Drive Your Activity-Bot with an Android Phone (SPIN Code)
JonnyMac
Posts: 9,105
A few weeks ago I started playing with Bluetooth and was alerted to a neat program called Joystick BT Commander which you can get in the Google Play Store (it's free). I worked through the Arduino demo code and create a Spin demo that worked quite well.
The next step was to use JBTC as intended: to control a robot. The attached program does that.
Notes:
-- with only two servos required, I am not consuming a cog with a servo driver (I do use the counters, though)
-- the main loop runs full speed, processing BT bytes as they arrive (no waiting around for a packet)
-- asynchronous timers are used to trigger various events (e.g., loss of BT, update servos, update running RTC)
My Activity Bot has high-speed servos so I use a very small portion of the servo range to make speed manageable -- this can be adjusted with the S_MAX constant (which should not be greater than 500)
Turning:
-- the Y axis of the joystick is used as the throttle
-- the X axis of the joystick affects the servo speed on the side of the turn
If you pull the stick the right, the right servo will be slowed by a portion of that deflection (skid steering). I scale that a bit to make it less sensitive (easier to steer). You can adjust that sensitivity in the call to the map() method.
This version does not turn in place (tank steering). What I will probably add later is a mode that will use the buttons to cause the bot to stop and then go into a slow rotation in place.
I believe that the code is ready to play with -- meaning YOU get to experiment with it now; I've got other projects to work on.
The next step was to use JBTC as intended: to control a robot. The attached program does that.
Notes:
-- with only two servos required, I am not consuming a cog with a servo driver (I do use the counters, though)
-- the main loop runs full speed, processing BT bytes as they arrive (no waiting around for a packet)
-- asynchronous timers are used to trigger various events (e.g., loss of BT, update servos, update running RTC)
My Activity Bot has high-speed servos so I use a very small portion of the servo range to make speed manageable -- this can be adjusted with the S_MAX constant (which should not be greater than 500)
Turning:
-- the Y axis of the joystick is used as the throttle
-- the X axis of the joystick affects the servo speed on the side of the turn
If you pull the stick the right, the right servo will be slowed by a portion of that deflection (skid steering). I scale that a bit to make it less sensitive (easier to steer). You can adjust that sensitivity in the call to the map() method.
This version does not turn in place (tank steering). What I will probably add later is a mode that will use the buttons to cause the bot to stop and then go into a slow rotation in place.
I believe that the code is ready to play with -- meaning YOU get to experiment with it now; I've got other projects to work on.
Comments
[Update] Did another outdoor test with Parallax RN-42 and was able to control my Activity Bot from nearly 90 feet away -- well beyond the spec.
Yes. BT modules run at 3.3v (the Parallax module has a 3.3v regulator on it to work with BASIC Stamp boards). I have had no problems with the Parallax RN-42, the Roaving Networks RN-42 that fits into an XBee socket, nor the $8 HC-06 I bought from ebay.