Finally, the last article of a robotic vehicle series. When everything is build, the robot can be programmed. Whole solution consists of four projects. One project for the vehicle, one for the remote controller and one shared library with communication protocol. The fourth project is accelerometer library, which was ripped off from Ball in Maze game by Device Solutions. All projects will be described later int the article.

Micro Framework Vehicle - evil lab 640x480 Figure 1: Evil lab - work in progress

How does it work?

As it’s seen on the video, the remote controller takes inputs from buttons or accelerometer and then sends the appropriate commands to vehicle. The communication is done via XBee transparent mode, which means permanent point-to-point connection. It is very similar to bluetooth serial port profile. Program in the vehicle keeps the last command active until the new command arrives. As a protection against loose-control when connection is lost, the vehicle will automatically stop when no command or PING is received in 1.5sec interval. The PING is a command that resets the safety-timer in the vehicle.

All commands accepts two parameters representing the speed. First parameter is the microseconds time when PWM is set to high. The second parameter gives amount of microseconds when PWM is low. If no speed parameter is passed, the last set will be used. The communication protocol is very simple, every text line that ends with \r character is interpreted as a command. All commands are upper case string and numbers are also passed as a string. Parameters are divided by spaces. Full list of commands follows:

FORWARD [high_time] [low_time]		Move forward at given speed
BACKWARD [high_time] [low_time]		Move backward at given speed
LEFT [high_time] [low_time]		Turn left at given speed
RIGHT [high_time] [low_time]		Turn right at given speed
STOP					Stop the motors
SPEED high_time low_time		Set the vehicle speed
PING					Reset safety-timer

Visual Studio 2005 Solution 357x237 Figure 2: Robotic vehicle solution in Visual Studio


Project for Digi Connect ME, which sits in the vehicle, consists of four classes. The TankApplication class is the main application loop that reads the commands and interprets them. The safety-timer is also executed and handled in this class. The CommandReceiver class is responsible for parsing the commands from serial stream. Motor operations are stored in very simple Motors class. Most interesting class is the PWMThread. This class is responsible for speed control. It’s a background thread that flipps the GPIO3, which is connected to enable input of L293D. The flipping frequency is set by the PWM parameters of the command.

Class diagram for Vehicle firmware 580x240 Figure 3: DigiTankFirmware class diagram


The remote controller project for Tahoe is more complex in terms of user interface controls, while technically is much easier. Most of the classes are UI orinented classes for speed and direction visualization as well as WPF button providers. Main logic is held in ControllerWindow where button events are processed and translated to appropriate commands. The CommandSender class is responsible for converting command structures into the serial stream. Accelerometer is represented by AccelerometerInputProvider, which regularly reads the status of accelerometer and raises OnMoveChanged event when move was recognized.

Class diagram for Tahoe controller 560x300 Figure 4: DigiTankFirmware class diagram


The shared library that is referenced by vehicle and remote controller is very simple. It consists of SerialPortEx class for more comfortable work with serial port. The other class and structure are just constants definition.

Micro Framework Vehicle - evil lab 640x480 Figure 4: Development board is a must!


Uhmmm.. hmmm.. well.. as I said before this library is ripped off from Ball in Maze game. It’s because the accelerometer functionality was added during one hour right on the TechEd. I would like to thank Colin Miller for sacrificing his accelerometer to my robot. If you want to know more about accelerometer and it’s interfacing, you should download Ball in Maze demo project.

X-CTU configuration 465x200 Figure 5: Configuring Xbee in X-CTU

Getting XBee to work

The XBee module situated in the tank is configured as a coordinator, while remote controller is configured as a router/end device. Both modules are working in AT command mode. Please refer to the Xbee technical manual for more informations. Settings can be done by the tool called X-CTU, which comes with the Xbee modules. The coordinator must be named TANK and communication speed set to 115200 baud/s, otherwise you will need to change it in the source code. The settings can be done by the following commands in X-CTU.

+++      		' get into the command mode
OK<CR>      		' module response
ATNI TANK<CR><LF>	' set module name
OK<CR>			' module response
ATBD7<CR><LF>		' set baud rate
OK<CR>      		' module response
ATWR<CR><LF>    	' store settings
OK<CR>      		' module response


Complete source code is available for download: [235 Kb].