Project By: Vale T
Level: Beginner
Hours to Complete: 1-2
Skills Required: Propeller C programming, building circuits on a breadboard, simple mechanical assembly
Have you ever wanted to drive your ActivityBot like you would an RC car? This project will let you control your ActivityBot remotely using a joystick mounted on an Activity Board.
This is a fun project that one can accomplish within an hour or two.
For this project, the following should already be completed:
Remember that you should already have pre-assembled and calibrated your ActivityBot [3], and also wired the Joystick circuit [2] on your Activity Board before starting this project. In this step, you will be installing and wiring the XBee connections that make it possible to drive your ActivityBot wirelessly using your Activity Board Joystick Controller.
It is actually pretty simple to attach your XBee modules to the Activity Board and ActivityBot. For each, all you need to do is push the XBee module’s pins into the slots available on the board (upper left section).
One thing that you should be careful of is that you install the XBee the right direction. If the angled edge of the XBee module is facing inward to the board, you have attached the XBee backwards. Remove the module, turn it around, and re-install it.
The end result of your Xbee installation should look like the image below.
After you have attached the XBees you will need to attach 2 jumper cables to connect the DI and DO (Data in and Data out) pins to your I/O pins. In my program I specified these I/O pins to be 8 and 9. On my board, shown below, you can see that I have attached DO to pin 9 and DI to pin 8.
Once you've attached the jumper cables on one board, repeat this process for the other board. Your final product should look like something the picture below.
At this point the hard part should be over. You should now have a XBee-wired ActivityBot robot and your XBee-wired Activity Board Joystick Controller.
Now, all you have to do is program them.
In this step you will be programming your ActivityBot robot and Activity Board Joystick Controller.
Below is the code for the ActivityBot robot:
Note: If you are using the ActivityBot 360° Robot (#32600), the following code will not work because it uses a different drive library. Change #include "abdrive.h" to #include "abdrive360.h" before uploading the code to your robot.
/* Code for ActivityBot - Joystick-Controlled ActivityBot Project Author: Vale T */ #include "simpletools.h" // Include libraries #include "fdserial.h" #include "abdrive.h" fdserial *xbee; int main() // Main function { xbee = fdserial_open( 9, 8, 0, 9600 ); // Begin the serial connection ( this is why we // needed the jumper cables connected to pins 8 and 9 ) char data; // Create the variable that will be used to hold // the incoming data while ( 1 ) // Repeat this forever or until loss of power { data = fdserial_rxChar( xbee ); // Set data to the data received from the XBee board if ( data == 'f' ) // If the data incoming is telling the robot to move forward { drive_speed( 64, 64 ); // Move forward at 1/2 speed } else if ( data == 'b' ) // If the data incoming is telling the robot to move backward { drive_speed( -64, -64 ); // Move backward at 1/2 speed } else if ( data == 'l' ) // If the data incoming is telling the root to turn left { drive_speed( 0, 64 ); // Turn left in a spin turn at 1/2 speed } else if ( data == 'r' ) // If the data incoming is telling the robot to turn right { drive_speed( 64, 0 ); // Turn right in a spin turn at 1/2 speed } else if ( data == 's' ) // If the data incoming is telling the robot to stop { drive_speed( 0, 0 ); // Stop } } }
Below is the code to upload to the Activity Board Joystick Controller:
/* Code for Activity Board Joystick Controller - Joystick-Controlled ActivityBot Project Author: Vale T */ #include "simpletools.h" // Include simple tools #include "fdserial.h" #include "adcDCpropab.h" fdserial *xbee; //Initialize the full-duplex serial connection over XBee int main() { xbee = fdserial_open( 9, 8, 0, 9600 ); // Open the serial connection adc_init( 21, 20, 19, 18 ); // Initialize the analogue connections for the joystick float lrV, udV; // Create 2 float values for incoming joystick values while ( 1 ) { udV = adc_volts( 2 ); // Get values from the joystick lrV = adc_volts( 3 ); if ( udV < 1.00 ) // If joystick going backward, send backward value { dprint( xbee, "b" ); } else if ( udV > 4.00 ) // If joystick going forward, send forward value { dprint( xbee, "f" ); } else if ( udV < 4.00 && udV > 1.00 && lrV < 4.00 && lrV > 1.00 ) // If joystick is in center, // send stop value { dprint( xbee, "s" ); } else if ( lrV < 1.00 ) // If joystick is going left, send left value { dprint( xbee, "l" ); } else if ( lrV > 4.00 ) // If joysitck is going right, send right value { dprint( xbee, "r" ); } pause( 50 ); // Only need to check joystick values 20 times a second } }
At this point you should be finished building and programming. You can power your Activity Board Joystick Controller with the USB programming cable; however, if you want to make it portable, you will need to use the 4 or 5-AA Battery Holder listed in the "What's Required" section on the first page of this project. Fill the holder with AA batteries, plug the barrel jack into the port on the Activity Board, and you're ready to go anywhere with it!
Links
[1] https://learn.parallax.com/activitybot
[2] https://learn.parallax.com/propeller-c-simple-devices/joystick
[3] https://learn.parallax.com/activitybot/calibrate-your-activitybot