Robosapien
InfraRed operation from a Raspberry Pi using LIRC.
An
old v1 robosapien robot came into my possession which I thought could be good
to use as an interesting demonstration of sequential programming in KS2 using
either Python or Scratch on a Raspberry Pi. The problem was that I had
no remote control with the robot, no idea about the ir codes or protocol and was therefore dependent on searching the web for the required information.
There
are a number of projects on the web that “hack” the robosapien. Most dispense
with the IR control and add an arduino or similar and directly input data to
the robot removing the need to use the IR protocol. See http://playground.arduino.cc//Main/RoboSapienIR
as an example.
There
is some data available for the IR codes and set-up for the Robotsapien but
there also appears to be some disagreement about the exact protocol both in
relation to headers and trailing data and the exact timing for pulses and
spaces.
Setting
up LIRC on the Pi
The LIRC configuration and IR codes for the Robosapien
proved to be a little more difficult as there is no consistent agreement on the
web about what the setup should be. I used two sources as a starting point:
and
They each agree in part but differ over the basic
structure of the start and stop encoding and the setting of the Most
Significant Bit. There is much discussion on the web about what is correct. I
went back to basics and researched the protocol /encoding on sites such as:
and determined that the protocol in use was probably PDM
and space driven based on a 1/1200 cycle time and a carrier frequency of 39200.
A 0 data bit having a space of 1/1200th or 833us and a 1 having a
space of 4/1200th or 3333us. The header required a pulse of 6666us
followed by a 3333us space and a ptrail pulse of 833us is required to determine
the length of the space of the last bit.
I then built a very simple LIRC config file on the Pi consisting
of the headers in the first of the config files with the addition of the ptrail
pulse along with the RIGHT_ARM_UP and RIGHT_ARM_DOWN codes in order to start to
play with it. At this stage testing of IR transmission was very crude and
consisted of a smartphone camera to ensure that the IR LED was operating when
basic commands were sent using LIRC’s irsend command. The camera showed that
the LED was firing at the right times but little else.
I then added the full set of codes and experimented with
Robosapien switched on. The initial results with were mixed and very
inconsistent. Some codes worked some of the time, whilst some didn’t work at
all. This testing proved to be very unhelpful as there appeared to be no apparent
pattern to the mode of failure but it did at least show that Robosapien was working.
However, a couple of weeks later, I was fortunate enough
to receive an Xmas present from my son which enabled a much more scientific debugging
approach to be taken...
The following charts are all produced using a Saleae
Logic analyser which enabled a much closer look at the structure and timings of
the IR signals being sent to the Robotsapien.
Analysis 1 shows a space encoded signal for Hex 1C which is
the STOP command. The header shows that the space signal timing is 3.33ms which
is exactly as specified in the headers of the config file.
|
Analysis 1. |
The 833us spaces signify a 0 and the 3333us signify a 1.
The next image, analysis 2, shows measurement of the
pulse width of the initial header pulse (logic low) which is required to be at
least 6.666ms. Whilst it was defined as that in the LIRC config file, the
output as shown below is only 5.634ms.
|
Analysis 2 |
Analysis 3 shows the end to end measurement of a pulse that is
specified to be 833us but is in fact only 700us in duration. The expanded pulse
on this chart also shows the 50% duty cycle giving the width and period
duration of each cycle. Some variation in the period can be seen at this level
which is measured by variations in the %duty cycle.
|
Analysis 3 |
Amendments to the config file so that the header pulse width
is set to 8000 and the ptrail, one and zero pulses are set to 1000 has produced
a waveform that consistently communicates with the Robotsapien.