Loki Crosses the Pond — Part 2
Top view of Loki (new legs). Sonar and IR sensors.
connector. The red +V wire goes to the center connector;
the black -V wire goes to the shell. This connector allows
easy disconnect from the controller board. The battery
connector can be disconnected to allow connection of the
Now down to the software issues. I’m an old hand at
the C language, and I naturally grabbed my trusty HI-TECH
compiler for the job. (Note that any one of several different
languages would work.) Although I’m not using one, a
boot loader would be a good choice for a ‘bot like this.
As mentioned, I use an ICD2 for programming, and have
to plug in a modular cable for this. Obviously with a boot
loader and wireless connection, no cables would be
needed! But don’t dismiss this simple umbilical cord; it is an
easy way to get started. In fact, I initially ran my Loki with a
battery pack lying on my desk. Having the weight of the
battery pack off-loaded allowed me to use some old Futaba
S3004 R/C servos I had laying around until I could
determine what size servos I needed. The S3004 servos at
the knees are too weak to lift up the body of Loki. You
could also use the Hitec RCD servos listed here:
Front view of Loki (new legs).
Sonar and IR sensors.
(interrupt service routine).
The ISR is called at a regular
interval by a timer interrupt.
The ISR generates “system
ticks” that initiate various
background tasks. Also,
several peripherals are
supported by an ISR in the
background. The USART
and A/D converter are
examples of this, as are the
updates for the R/C servo
positions. The I2C FSM for
the ultrasonic rangefinder
relies on multiple calls from
the scheduler to avoid
“blocking” while waiting for I2C events. This RTOS is not
pre-emptive and only supports a fixed list of tasks; hence,
the baby moniker.
The current controller program (RTOS) is a bit eclectic
in that it has a monitor that accepts commands from a
console and also supervises an autonomous mode for
when the robot is on its own. I’ve mentioned the monitor
command to move the servos; there are also commands to
save/view/execute the servo positions stored in EEPROM,
and to read the sensors. The current autonomous mode
is in its infancy; it’s merely a simple obstacle avoidance
behavior for now. More is planned for it in the future.
Hitec HS-645MG 107 oz-in 4.8V, 133 oz-in 6.0V
Hitec HS-475HB 61 oz-in 4.8V, 76 oz-in 6.0V
Note: Futaba 3004 servos rotate the opposite direction
to Hitec HS-475HB servos! Be sure you account for this
if you change between the servo brands. I’m currently
making modifications to the code to accommodate both
The heart of the monitor is a simple hacked-together
parser to decode commands for Loki. Perhaps the most
important command is the R/C servo command which takes
position parameters for up to four servos (although I’ve
planned to allow up to eight servos) at a time. A servo
command is a simple string of ASCII characters (like
“#0P1200 #1P1500”) ending in a CR (carriage return) in a
format similar to that used by SSC (Serial Servo Controllers)
such as the Lynxmotion SSC32 servo controller. This is
convenient for me, as Shelob — my main hexapod — uses it.
Add to the command a parameter for the required time of
the move (“T1000”), and we have a means of commanding
1-4 servos to move in what’s called in CNC parlance a
“coordinated motion” (all axis motion starts and ends at the
same time). This is very convenient for moving the legs of
Loki, or any robot, for that matter.
Loki currently recognizes the following commands or
Loki’s controller program is basically a “baby RTOS”
(real time operating system), which means that there are
several tasks that run at the same time, managed by an ISR
54 SERVO 07.2008
• + -
Loki revision sign-on
Offset of servo position