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.
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
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.
Figure 3: DigiTankFirmware class diagram
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.
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.
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: MicroFrameworkTank.zip [235 Kb].