CSULB EE400D
TECHNICAL
DOCUMENTATION
ARDUINO/ARXTERRA PROGRAMMING
PART I - COMMANDS
GETTING STARTED
ARXROBOT FIRMWARE DEFINE ROBOT FEATURES
You can download the arxrobot_firmware from the Arxterra GitHub releases page:
https://github.com/arxterra/arxrobot-firmware/releases.
Based on the Arxterra robot you are building, set definitions to TRUE or FALSE
mini-Rosco rover configured with bluetooth communictions with an ultrasonic pinger.
GETTING STARTED
ARXROBOT FIRMWARE DEFINE ROBOT PINOUTS
Once you have configured your code. Open the pinouts_robot.h tab and make sure
your rovers pinouts are correct.
COMMAND ENCODING
BYTE ARRAY FORMATTED INTO A PACKET
Packet ID 0xA5 indicates the start of a command packet
Packet Length is the number of bytes following minus the LRC byte.
Command ID is an 8-bit code identifying the instruction to be executed.
Command ID byte is followed by some number of bytes.
Longitudinal Redundancy Check (LRC) is generated over the entire packet.
COMMAND ENCODING
EXAMPLE - MOVE (0X01) FORWARD HALF SPEED TEST
i =
N =
A5 05 01 01 80 01 80 A1
MOV forward half speed
sendPacket
data[0] A5 = Command Packet ID
data[1] 05 = Packet Length N w/o parity byte
data[2] 01 = Move ID
data[3] 01 = Left Motor Forward
data[4] 80 = Half Speed (128/255)
data[5] 01 = Right Motor Forward
data[6] 80 = Half Speed (128/255)
data[7] A1 = Longitudinal Redundancy Check (LRC)
COMMAND ENCODING
COMMAND DEFINITIONS IS INCLUDED IN THE PINOUTS_ROBOT.H FILE
arxrobot-firmware alpha version 0.8.2
COMMAND ENCODING
CUSTOM COMMANDS
Arxterra control panel allows you to create
your own custom commands
Control panel designed to support a Hexapod robot
Control Panel User interface (UI) widgets include:
radio buttons, sliders, drop down menus, and more.
Use command IDs 0x40 to 0x5F
Learn how to create your own custom UI widget,
Jeff Gomes Video Series
Tommy Sanchez Creating Custom Commands With the Arxterra Application
IMPLEMENTING COMMANDS
HOW THE ARXROBOT FIRMWARE DETECTS, READS, AND HANDLES
COMMANDS
All Arduino programs contain a setup() and a loop() method. Commands are detected
in the loop() method.
Once detected, commands are decoded in the commandDecoder() function.
You can find the command decoder code under the command tab within the Arduino
IDE (Integrated Development Environment).
IMPLEMENTING COMMANDS
COMMAND DECODER FINITE STATE MACHINE (FSM)
IMPLEMENTING COMMANDS
COMMAND EXCEPTION CODES
01
Start byte 0xA5 expected
02
Packet length out of range 1 - 20
03
LRC checksum error
04
Undefined command decoder FSM state
05
Array out of range i >= 23
IMPLEMENTING COMMANDS
HOW THE ARXROBOT FIRMWARE DETECTS, READS, AND HANDLES
COMMANDS
If the command is successfully decoded then the commandHandler function is called
from state 3 of the FSM.
The data parameter points to the received byte-array.
The N parameter is the length of the packet as previously
defined
IMPLEMENTING COMMANDS
COMMAND DECODER
To understand these two parameters, review move (0x01) command example.
i =
N =
Data = A5 05 01 01 80 01 80 A1
MOV forward half speed
The command handler function assigns the third byte to the unsigned byte variable cmd.
uint8_t cmd = data[2];
Next a series of if-else-if statements direct action to be taken by the Arduino
if (cmd == MOVE) {
...
}
else if (cmd == CAMERA_MOVE){
...
}
else if (cmd == CAMERA_RESET){ ...
IMPLEMENTING COMMANDS
HOW TO WRITE ARDUINO CODE FOR YOUR ROBOTS UNIQUE COMMAND(S)
Develop and test your code in a separate Arduino ino file(s).
Once you know it works, then add to arxrobot_firmware
Two approaches to modifying the code for your robot.
1.
The simplest is to throw away the code within the else if block and adding your own.
2.
The second is to add your code in such a way that the original functionality of the code is
not lost.
IMPLEMENTING COMMANDS
METHOD 2: MAINTAINING CODE COMPATIBILITY
Step 1
Add a new C++ preprocessor directive for your robot. Declare it TRUE and the
remaining robots FALSE.
#define BiPed TRUE
#define PaperBot FALSE
#define Rosco FALSE
Step 2
Scroll down to the command block you are implementing
Append a #elif preprocessor conditional directive (before #endif).
Add a function call to your command
IMPLEMENTING COMMANDS
METHOD 2: MAINTAINING CODE COMPATIBILITY CONTINUED
Step 3
Save and close the Arduino IDE.
Add the ino file(s) containing the functions that are unique to your robot.
Reopen the Arduino IDE. The new ino file(s) will now appear as tab(s).
Rename the setup() method from your development software and call
from the setup() method in arxrobot_firmware. For example setup_BiPed()
Rename the loop() method from your development software and call from
the loop() method in arxrobot_firmware. For example update_BiPed()
Compile your code and verify that there are no errors.
IMPLEMENTING COMMANDS
METHOD 2: MAINTAINING CODE COMPATIBILITY - EXAMPLE
if (cmd == MOVE) {
#if Rosco == TRUE // Adafruit L293D motorshield
move_L293D(data);
#elif Pathfinder
// Pololu VNH5019 motorshield
move_VNH5019(data);
#elif PaperBot
// Sparkfun TB6612FNG
move_TB6612FNG(data);
#elif BiPed
walk_BiPed(data);
#endif
IMPLEMENTING COMMANDS
UNPACKING/FORMATTING COMMAND ARGUMENTS
All command data is in the form of a byte array, formatted as an Arxterra command
packet.
Your unique commands may want data formatted as a type other than an 8-bit byte.
In this example, four (4) bytes are converted into a 32-bit unsigned long data type
and saved in variable ping_interval.
COMMANDS
ADDITIONAL READING
Here is the companion document to this presentation. http://web.csulb.edu/~
hill/ee400d/Lectures/Technical%20Training/Arduino%20Programming.pdf