In this post, I will familiarize the reader with how to talk to the Arduino microcontroller that controls the entire RP2W robot.
Currently, our RP2W robot is controlled by a subpar Visual-Basic-based GUI application running from a Windows netbook. We will replace that netbook with a PandaBoard running Ubuntu (see https://emotionrobots.com/2015/03/07/running-ubuntu-on-pandaboard/). The PandaBoard will send to and receive signals from the Arduino embedded inside our RP2W robot, which in turn controls the wheels and camera joints of the robot.
The signals that we send indicate the settings for the robot’s wheel and camera movements at one instant of time. We must continuously send the signal, otherwise the Arduino will stop. The signals are formatted into a packet consisting of 11 bytes, or values ranging from 0 to 255. C++ does not contain a bytes data type, but rather an unsigned char that ranges from 0 to 255. I found the details of the packet in the comments of the Arduino firmware file, written in Arduino Sketch based on C/C++:
// Incoming Packet: PC to Robot // - 0 0x53 "S" Start Byte // - 1 Right Motor Speed // - 2 Left Motor Speed // - 3 Camera Tilt High Byte // - 4 Camera Tilt Low Byte // - 5 Camera Pan High Byte // - 6 Camera Pan Low Byte // - 7 Digital 1 // - 0 Relay 1 // - 1 Relay 2 // - 2 Relay 3 // - 3 Relay 4 // - 4 (Not implemented) // - 5 (Not implemented) // - 6 Right Motor PWM Direction // - 7 Left Motor PWM Direction // - 8 Digital 2 // - 0 Clear Encoder Count // - 1 (Not implemented) // - 2 Override Front Sonar // - 3 Override Rear Sonar // - 4 Override Bumper // - 5 (Not implemented) // - 6 (Not implemented) // - 7 (Not implemented)
Bytes 9 and 10 are checksumHigh
and checksumLow
, which together form a 16-bit value that must equal the sum of bytes 0…8 in order to verify the integrity of the data packet. The actual data structure of the receiving packet looks like this:
typedef struct { byte startFlag; byte rightMotorSpeed; byte leftMotorSpeed; byte cameraTiltHigh; byte cameraTiltLow; byte cameraPanHigh; byte cameraPanLow; byte digital1; byte digital2; byte checksumHigh; byte checksumLow; } packetToRobot;