Shop OBEX P1 Docs P2 Docs Learn Events
Drive Your Activity-Bot with an Android Phone (SPIN Code) — Parallax Forums

Drive Your Activity-Bot with an Android Phone (SPIN Code)

JonnyMacJonnyMac Posts: 9,105
edited 2015-02-27 13:10 in Propeller 1
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.

attachment.php?attachmentid=113281&d=1424990765

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

  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-02-26 16:23
    For those interested I did an outdoor test with my Droid Turbo and a Roving Networks RN-42 (fits in PAB XBee socket) module -- got about 60 feet of control.

    [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.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2015-02-26 16:54
    Excellent work! Been following your BT work with this app as I downloaded it a while back but haven't messed with code, so a big thank you! I don't have an ActivityBot, but I bet this could easily adapt to my stingray.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-02-26 19:56
    Thanks a bunch for this. I had to tweak the StopValue a bit for my own needs but it works great. Now I can get to modifying it. I was able to get it to work with my RN-42. I do have an issue with my HC-06. Are you running yours on 3.3V? I followed your instructions from this post: http://forums.parallax.com/showthread.php/160112-HC-06-(Bluetooth)-Configuration-(RN-42-Code-Added)#1 However, when attempting to get an OK from the AT command at different Baud settings on 115000 I get AT back. The rest I get nothing.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-02-26 20:03
    Are you running yours on 3.3V?

    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.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-02-26 20:22
    I must have gotten a bum HC-06. Guess I will order a couple more. My RN-42 works fine but they are a little pricey to be using in multiple projects. Thanks again though for the Spin code.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-02-26 20:24
    Or it's an HC-05 which uses a different command set. Look that up and give it a try. You should be able to use my RN-42 terminal with the HC-05.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-02-26 20:31
    I can connect to it through my phone and it says HC-06. I will look it up just to be sure.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-02-27 13:10
    Is there a difference in the HC-06 Slave devices versus the HC-06 Master devices that are sold on eBay?
Sign In or Register to comment.