Pages: [1]   Go Down
Author Topic: Wireless Joystick with Arduino control for 3pi Pololu robot  (Read 2503 times)
0 Members and 1 Guest are viewing this topic.
Venezuela
Offline Offline
Sr. Member
****
Karma: 12
Posts: 433
Ground.......ground........always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
-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:
...
int main()
{

pololu_3pi_init(2000);
clear();

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

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

 motorSpeed1=(pot1-128);
 motorSpeed2=(pot2-128);
 LeftWheel = (motorSpeed1+motorSpeed2);
 RightWheel = (motorSpeed1-motorSpeed2);
 set_motors(LeftWheel, RightWheel);
 }
}
...

Here the Fio sketch.

Code:
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:
  Serial.begin(115200);
}

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;  
   Serial.write(axis);
      
}

Regards!
« Last Edit: September 30, 2013, 04:03:45 pm by Palliser » Logged

Berlin
Offline Offline
Newbie
*
Karma: 0
Posts: 10
FRT - RoboCup Junior Team from Berlin, Germany
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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

Regards,
Tobias
Logged


Pages: [1]   Go Up
Jump to: