Go Down

Topic: [Bumped!] Wireless Joystick with Arduino control for 3pi Pololu robot (Read 3990 times) previous topic - next topic

Palliser

Here one of my robotics projects.

Video of the wireless control and 3pi in action!
http://youtu.be/f7RpSlC14eI

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

Resources:

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.



Programming:
-Arduino IDE 1.0 (see below)
-Atmel Studio 6 (see below)
-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. The Fio code was done using Arduino IDE.


New sketches for the robot and Fio will be posted soon! [Update: 12/10/14]

Regards!

frtrobotik

Hi,

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

Regards,
Tobias
Homepage: http://www.frtrobotik.de

Palliser

I used AVR Studio for programming the robot and Arduino IDE for the Fio. Given that the people from Pololu recently developed an Arduino Library for the 3pi Robot (and the Orangutans), I've ported the robot code to Arduino making this project fully developed in the Arduino environment. I will be posting soon both sketches (robot and Fio). Stay tuned!

p

Palliser

Here the Joystick (Arduino Fio) and Pololu 3pi robot (Orangutan SV-xx8) sketches.

Fio:

Code: [Select]
int x_axis, y_axis, motorSpeed1, motorSpeed2, data;

void setup() {
  Serial.begin(115200);
}

void loop() {
  x_axis = analogRead(A1)/2-255;
  y_axis = analogRead(A2)/2-255;
  if(x_axis>255) x_axis=255;
  if(y_axis>255) y_axis=255;
  motorSpeed1=(((x_axis+y_axis)/16)+15)/2;
  motorSpeed2=(((x_axis-y_axis)/16)+15)/2;
  data=motorSpeed1*16+motorSpeed2;
  Serial.write(data); 
}


Robot:

Code: [Select]
#include <OrangutanMotors.h>
int data, motor1, motor2;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
    while (Serial.available()) {
    data = Serial.read();
    motor1 = (data >> 4)*32 - 224;
    motor2 = (data - (((motor1+224)/32) << 4))*32 - 224;
    set_motors(motor1, motor2);
    }   
}


As you notice, the sketches are very simple. You surely will need to make your own adjustments
depending on your joystick values (offset, etc.)

Attached is the robot library (unzip and copy this folder in your ...\Arduino\libraries\ folder:

For the configuration of the robot and AVR programmer follow the step #3 in the following link:
http://www.pololu.com/docs/0J17

The Fio sketch is compiling/uploading OK with most of the Arduino IDEs.
The robot sketch is compiling/uploading OK with the Arduino IDE 1.0.5. I also tested it with 1.5.8; it compiles OK but is not uploading (issue with missing upload.tool and bootloader.tool keys). I will try to fix that.

With the above, the 3pi Pololu robot can be programmed within the Arduino environment. Regards,

p

Go Up