Go Down

Topic: Wireless Joystick with Arduino control for 3pi Pololu robot (Read 3676 times) previous topic - next topic


Jan 27, 2013, 07:20 am Last Edit: Sep 30, 2013, 11:03 pm by Palliser Reason: 1
Here one of my robotics projects.

Video of the wireless control and 3pi in action!

XBee control for a 3pi Pololu robot using Arduino and a joystick.


XBee Joystick Control:
-Arduino Fio (Osepp Fio)
-XBee 802.15.4 module (Transmitter)
-2-axis joystick (Parallax 27800)
-Rechargeable baby battery (Dantona 3.6V/1500mAh Ni-MH)
-Miniature toggle switch
-Project Enclosure (4 x 2 x 1)

XBee 3pi Pololu Robot:
-3pi Pololu robot
-3pi wireless robot shield
-XBee 802.15.4 module (Receiver).
-4 AA batteries.

-Arduino IDE 1.0
-Atmel Studio 6
-Pololu USB AVR Programmer
-Xbee/USB board (XBee-USB Gravitech)

Code concept:

XBee Joystick Control:
Continuously, the Fio reads the X and Y analog voltages (0 to 3.3v) from the joystick's potentiometers connected to A0 and A1.
Each voltage represents the position of one of the axis of the joystick an a raw motor speed reference. When the joystick's knob is in its origin, the axis voltages are the same: 1.65v.
The Fio converts each axis voltage into a value between 0 to 256 (1 byte). Then, dividing them by 16, each value is scaled into 4 bits (1 nibble).
Finally, the Fio packages them into one byte and finally sends this data byte via XBee to the robot.

XBee 3pi Pololu Robot:
Continuously, the robot receives a data byte from the wireless control and breaks it back down into two nibbles.
The most significant nibble indicates the position of one of the axis of the joystick,
and the least significant nibble for the other axis. This gives 2 ^ 4 = 16 different speed readings that the code converts into motor voltages.

One joystick axis controls throttle (forward/reverse) and the other to controls steering (left/right).
I mixed the axis readings as follows:

LeftWheel = motorSpeed1 + motorSpeed2.
RightWheel = motorSpeed1 - motorSpeed2.

Where motorSpeed1 is throttle and motorSpeed2 is steereing.

Notice that if motorSpeed2 is zero, both motors are set to the same speed and if motorSpeed1 is zero, both motors are set to opposite speeds.

Both XBee radio modules have been matched up using X-CTU.

Electric Schematic

Code sample:
The C++ code of the robot was compiled using Atmel Studio 6 and programmed in the Atmega328 of the robot using the Pololu USB AVR Programmer.

Code: [Select]
int main()


// start receiving data at 115.2 kbaud
serial_receive_ring(buffer, 100);

command = read_next_byte();
temp = (command >> 4 );
pot1 = temp * 16;
pot2 = (command - (temp << 4)) * 16;

LeftWheel = (motorSpeed1+motorSpeed2);
RightWheel = (motorSpeed1-motorSpeed2);
set_motors(LeftWheel, RightWheel);

Here the Fio sketch.

Code: [Select]
const int analogInPin0 = A0;
const int analogInPin1 = A1;
int readByteX = 0;
int readByteY = 0;
byte mappedByteX = 0;
byte mappedByteY = 0;
byte bottom_nibble  = 0;
byte top_nibble  = 0;
byte axis = 0;
char buf[8];

void setup() {
 // initialize serial communications at 115200 bps:

void loop() {
  readByteX = analogRead(analogInPin0);            
  readByteY = analogRead(analogInPin1);            
  mappedByteX = map(readByteX, 0, 1023, 0, 255) / 16;
  mappedByteY = map(readByteY, 0, 1023, 0, 255) / 16;
  axis = ( mappedByteY << 4 ) | mappedByteX;  




could you post your complete code? I want to know how you recieve the

Website: http://first-robocup.org

Go Up