Solder Spot

A Hobbyist's Journal

Building Zumo – Encoder Redux and Bluetooth

Encoder Do-Over

So it turns out that all the effort to get the servo and sensor off to another processor, the Trinket, was not needed.

I had forgotten that the encoder signals can be processed using pin interrupts, which is the recommended way to do things. When I was first implementing the encoders, on a different bot, availing of the pin interrupts was not possible so was forced to used a timer interrupt to sample the encoders instead.

For the Zumo build the pin interrupts are available and I’ve reimplemented the encoders accordingly. The result is that the pin interrupts work perfectly and do not cause problems for the rest of the system, unlike the high frequency timer interrupt which was eating up all the CPU cycles. So problem solved with much less effort than adding the second processor.

Still, having the option to off-load the servo and sensor may come in handy if there is a need to free up pins on the Arduino. It was also great to have an excuse to play with the Trinket.

Feeling much better about using the Arduino for the rest of this project.

You can view all the code on GitHub.

Untethered At Last

Purchased an inexpensive Bluetooth transceiver module from Amazon. Just got it today.

1200_1402_IMG_3286

1200_1402_IMG_3288

Doesn’t get any simpler than this device. Just plug in 5V, GND, Tx to pin 0 and Rx to pin 1, fire it up and pair it to your computer (type in 1234 if asked for a code).

For now I just stuck it on the rear of the bot.

1200_1402_IMG_3283

Eventually I’ll figure a better location for it.

And the timing is perfect. I’m in the process tuning the PID controller. Before this would mean having to tether the bot to my laptop and follow it around to collect data. Now the laptop stays on the desk and collects data untethered. It’s surprising how nice this is. Definitely my favorite piece of kit so far.

Also thinking about creating an app that acts as a remote UI, over the serial link, so that realtime data can be collected and displayed, and even provide simple inputs/settings to the bot. Maybe such an app exists already. I’d much rather that than mess around with an LCD display.

About these ads

15 comments on “Building Zumo – Encoder Redux and Bluetooth

  1. Pingback: Building Zumo – Part III | Solder Spot

  2. telle Blet
    February 17, 2014

    Is it also possible to use your code without the encoder? So it drives through a room depending only on the sonar?

    • solderspot
      February 17, 2014

      Yes. Set the variable PIDenabled to false and USE_PATHS to 0.

  3. telle Blet
    February 25, 2014

    I used your code and it works! It’s alive;-) Only one thing i am trying to figure out is that it moves slightly to left. I learned a lot of how it works. Up to the next step. Thank you so much for sharing!

    • solderspot
      February 25, 2014

      That is great to hear. Glad it was useful to you. Have fun getting it to go straight.

  4. telle Blet
    February 25, 2014

    So strange when i upload a standard zumomotor example sketch it moves straight but now it moves slightly to the left.

    I adjust int LMotorGain = 110 so it should move to the right a bit more. But it does not
    Can you give me a hint?

  5. solderspot
    February 25, 2014

    Are you using encoders and/or the PID controller?

    Setting LMotorGain should definitely have an effect. Set MOTOR_INFO to 1 so you can verify what values are getting sent to the motors.

  6. telle Blet
    February 27, 2014

    I dont have encoders so i dont have a pid controller, is that correct?
    Is the servo or the sonar catching some power of the left motor or interupting it?

  7. solderspot
    February 27, 2014

    I would suggest removing all the encoder and PID code as you do not need it. Also get rid of the path code.

    I wonder if the servo/sensor are affecting the motors. I’ve not done any tests myself but you can try simply unplugging them and see if that has an affect.

    I’ll try testing tonight as well. I’m curious about what is happening. I have quite serious drift to the left.

  8. solderspot
    February 27, 2014

    With no servo or sensor and the simplest sketch I still get the same drift left. In my case it seems to be either a motor imbalance or some kind of wheel alignment issue. I’m guessing the second as I am getting drift even when the encoder ticks are the same for both wheels.

  9. solderspot
    March 18, 2014

    My problem was wheel alignment. The Zumo bot has a lot of slack in the idler wheels.

  10. Abdul Halim
    April 16, 2014

    Enjoyed your coding. My Zumo works without the PID & Encoder.
    Do you think your code with some changes to pins setup will work with Pololu 3Pi?

    • solderspot
      April 16, 2014

      I don’t see why you would not be able to get it running on the 3Pi but I don’t have any experience with that platform. The devil is always in the details.

  11. Abdul Halim
    April 16, 2014

    My wish is to see your tutorial on controlling Arduino with Xbee. There isnt much comprehensive example that shows Xbee with Arduino or with Zumo & 3Pi?

    • solderspot
      April 16, 2014

      At some point I will experiment with XBees but it might be a while.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on February 12, 2014 by in arduino, builds, equipment, robotics and tagged , , , .
Follow

Get every new post delivered to your Inbox.