Open Source Robot Controls

I’ve been playing around with some ideas for an Arduino/Netduino robot control system the past few months. I knew that I wanted to be able to control my robots from an Android phone, PC, or any other WiFi enabled device. I also knew that I wanted the system to be small and simplistic, but also powerful and extensible. The reason I went with an Arduino (Ethernet Pro) or a Netduino Plus for the controller was the low cost, ease of programming, and the embedded ethernet port. I coupled the onboard ethernet with a wireless router so that I could connect and transmit data to the robot wirelessly. Here are the results of our first robot build with this system. The robot was affectionately named Mantis.

Mantis Robot

 

 

 

 

 

 

 

 

While developing this control system, I wrote an open source app for Android devices called IPGamepad. It is now in the market for free and available on Google Code. On the Google Code page you can also find the Arduino, Netduino, and Python code for use on your own robot control system. Episode #7 of The Tech Junkies gives a good overview of how the system is put together, how the code works, and a closer look at the Mantis robot:

As for all of the parts we used in the video, here’s all of the basics you’ll need to get your control system off the ground:

1. Ethernet Pro or Netduino Plus ($55-60)

2. Screw Shield ($15)

2. Wireless Router ($30-50)

3. 40A Speed Controllers ($90 ea) (can substitute lower current controllers for smaller motors)

4. Spike Relay ($35) (optional – useful for switching headlights or other 12v accessories)

4. 5V Power Regulator ($15)

5. Ethernet Cable, PWM Cables, Power Cable (~$20)

6. Battery Terminals ($5)

7. Main Power Breaker ($30)

8. Fuse Block ($15)

9. 12V Battery ($100-$200)

Robot Control System

It’s a bit rough, but here is the basic layout of the wiring for a basic robot setup using this system:

Open Robot Control System Wiring

I’m definitely looking for help to continue the project and add several more features to the Android app and controls side of the system. Feel free to pitch in or contact me through the Google Code page. As I pointed out earlier, all of the code to make all of this work is up on that page.

If you’ve got any crazy robot ideas or just need some help implementing the system, go ahead and add a comment to this post. I’ll try to monitor the page and get back to you as soon as possible. I’ll be out at Maker Faire Detroit next weekend (30th and 31st) demoing Mantis and a few other robots driven by this system. I hope to see you there!


64 Comments on “Open Source Robot Controls”

  1. dm3281 says:

    Hi, this is really cool. Where did you get the chassis and wheels, etc?

    I’m new to this sort of thing and dont know much about electronics. Where is a good place to start when trying to build something like you have?

    There is no way I’d know what pieces I’d need or whether it would support the power consumption for breakers, fuse box, regulators, etc. Very interested in knowing how you went from idea, concept and prototype.

  2. dm3281 says:

    ALso, where did you get the headlights and how are they wired? I’m guessing 12V Accessory ground/power?

  3. eric says:

    Hey dm3281,

    The chassis was just square tube steel we cut up and welded together. We used solid steel tube for the axles and picked up some cheap wheels from northerntool.com.

    Take a look at the build of materials I listed above…that should be just about every electrical component you need. We were able to buy about 90% of everything from robotmarketplace.com or sparkfun.com.

    We ended up using a lot of parts that are typically used for FIRST competition robots, so we had a ballpark idea of the power requirements. What size robot are you thinking of?

    The headlights were just cheap car headlights we picked up at Autozone. They’re wired directly into our 12V spike relay which is controlled from a digital pin on the Netduino.

  4. dm3281 says:

    How long does your battery last when operating this thing? since it’s non recharging, I’d imagine buying new batteries gets expensive?

  5. eric says:

    Actually we’re just using Optima Car Batteries which can handle plenty of discharge/recharge cycles. We can pretty easily drive for an hour before having to recharge the battery.

  6. […] and the crew over at The Tech Junkies, just put the finishing touches on a pretty powerful robot that they call […]

  7. Scott says:

    I wish I could have seen several more minutes of actual driving footage – that would have been fun to watch!

  8. Marcel says:

    This is nice work.

    Grtz from Holland

  9. Jos says:

    What kind of motor’s do you use? And yes a little bit more footage of driving would be fun!

  10. eric says:

    Hi Jos,

    We’re using four of these CIM motors: http://www.andymark.com/product-p/am-0255.htm For the price you can’t beat them! We’ll try to get a bit more footage while we’re at Maker Faire this weekend. In the meantime, there’s also the YouTube video on the front page of ttjcrew.com.

  11. Bill says:

    Eric
    Very cool project and professional build. I download all software, thank you.
    I loaded the arduino code on a EtherTen and it prints “robot control system initialized” Don’t have an android YET. I know nothing about python, but I put python 3.2.1 on windows XP And I do get a shell I think its working. I’m not clear on pygame and your code? Any advice will be greatly appreciated. Also how many single acting spike relays have you plugged into one arduino at the same time?
    Bill

    • Eric Barch says:

      Hey Bill,

      Do you have a USB gamepad that you can use with the python app? As far as getting it up and running, did you install the 32 bit or 64 bit python? I know pygame has some issues with 64 bit. If you’ve got 32 bit installed, you can download pygame for Python 3.2 here: http://pygame.org/ftp/pygame-1.9.2a0.win32-py3.2.msi You may also need pywin: http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.1.win32-py3.2.exe/download Once you’ve got all that installed, you should just be able to double click the .py file off of the Google Code page. Let me know if it works!

      I’ve only got a single spike connected to mine, but you can connect as many as you want provided you have that many free digital I/O pins.

      Eric

      • Bill says:

        Hey Eric,

        Logitech F310 USB Wired Game pad with drivers installed.
        6.5 year old DELL Laptop with XP sp3.
        Kyocera KR2 Router at 192.168.1.1.
        EtherTen Arduino at 192.168.1.22.
        ////////////////////////////////////////////////////////////////////
        Python Shell
        Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32
        Type “copyright”, “credits” or “license()” for more information.
        >>>
        ////////////////////////////////////////////////////////////////////
        Pygame AND Pywin From your Links.
        python_robot_control_v01_2.py From Google Code.
        When I double click the .py file, I see a black screen for a second or less then it disappears ?
        All the software loaded ? OK, NO Ererss.
        I can ping the arduino ok, and the arduino can talk to google with deferent code.
        Control Panel > Game Controllers > Logitech Dual Action Properties Test Page is working OK.
        I’m monitoring network activity with windows task manager with all columns selected.
        Many Reboots on every thing.
        I keep thinking I’m missing something.
        I appreciate your time, and I hope I’m not wasting it.

        I found another of your projects that’s a much better fit for what I’m trying to do,
        A driver side PS2 controller, Arduino and Ethernet Shield control system for 221.
        The question is your android phone App. Setup for the software on their site ? And also Is it possible to change your Android App. Using Google’s AppInventor ?

        Thanks
        Bill

      • Eric Barch says:

        No worries…sounds like the app may be encountering an error and just exiting. What if you open up the Python terminal first and then drag the .py file to the window and run it that way? Does it stay up and allow you to see an error message? I haven’t used that particular version of Python on Windows, so it could be an issue with that version.

        Right now the android app code isn’t setup to control that exact control system, but the data packet is almost setup the same way. With a little bit of tweaking you could easily get both running together. I’m hoping to publish the code and wiring diagram for the PS2 controller arduino-side soon.

        I’ve never used Google’s AppInventor so it’s tough to say…if you do find anything out about it or give it a shot, let me know so I can tell our readers about that!

        Eric

      • Bill says:

        Eric
        First: nice video at Maker fair.
        I tried your suggestion, and it did the same thing and opened briefly.
        After guessing and stumbling around in the dark, I got your file opened in the python shell and called up the debugger after guessing and fooling around for awhile I managed to get two errors that I managed to repeat two times and it was the same both times, this means to me I’m consistently good at making mistakes the same way or I may have stumbled and fumbled and produce something usable?
        I made screen captures of both of them. Because I don’t think I could sufficiently described the results.
        You have my e-mail, if you’d like to do something else or try something else give the word, I’m game.
        Bill

      • Eric Barch says:

        That should definitely be helpful…just upload the screenshots to http://imgur.com/ and post the links here and I’ll take a look.

        Eric

  12. Todd says:

    Great project Eric. What gearbox did you use for the 4 CIM motors (looks like 2 motors per box)? Also – what sprocket gearing did you use on the wheels and the drive shaft? Love it!

    • Eric Barch says:

      Hey Todd!

      Thanks for the feedback. We ended up using ToughBoxes from AndyMark: http://www.andymark.com/product-p/am-0145.htm You’d be correct on the 2 CIMs/gearbox. We took out one of the stages in the gearbox so it’s a single reduction. This took a little bit of modification/drilling, but it ended up working well. The sprocket on the end of the ToughBox shaft is a 10 tooth garage door opener sprocket. We used 46 tooth bike sprockets for each wheel and connected it all with bike chain.

  13. Rob says:

    Nice job Eric. Could you tell me how you ended up using two motors per side? If you have a sketch of the ToughBox mods would you mind posting it? Have you toyed with the idea of a video feed?

    • Eric Barch says:

      Thanks, Rob…it’s much appreciated. The ToughBoxes are designed to accept two CIM motors without any modifications. We simply drilled a hole in the other side so that we could remove a stage in the gearbox and flip the gears around 180 degrees. If you purchase the ToughBoxes with the gearing you need, you won’t need to modify anything to couple the two CIMs.

      We’ve actually got an IP based camera that we’ve tested onboard the robot. It connects to one of the ports on the router and our eventual plan is to do video processing on a remote PC and then transmit control data back to the robot.

  14. Rob says:

    Thanks for the prompt reply Eric. Let me rephrase my question about the motors. Did you find that a single motor per side was inadequate to drive this type of chassis? Do you know what gear ratio you ended up with in the ToughBox?

    I’ll be watching for your video “upgrade”.

    • Eric Barch says:

      No problem…a single motor on each side should’ve been just fine, but for the price of the motors, we decided to use 4. I believe it’s just the standard gear ratio of the toughbox (12.75:1) that we ended up using.

  15. Gary says:

    Will you be developing IPgamepad to work with Iphone?

    • Eric Barch says:

      Hi Gary,

      Unfortunately I have neither any iOS hardware or an Apple developer license at this time. If it appears as though there is enough demand I will definitely consider it, though. I’m actually in the middle of a new project based off of IPgamepad (open source) that will be released in the coming months. It should be much more capable than IPgamepad and have some neat things like packet checksumming so that all control data is validated. It’ll also be a 2-way communication protocol so you can get feedback from your robot. Hopefully that will make it to iOS at some point.

      Eric

  16. Einarr says:

    hey there guys im a rc fan that had a little bit of electronic experance but very little in the programming feild have come accross the ipgamepad and would like some help it has the basic features i would like for my robotics project but i would like to expand on the idea and also have on screen switches for lights and other acc is there any chance you will be adding new fetures to the program or can you point me in the right direction to modify or extend on your idea email me back at the provided address

    • Einarr says:

      also is there any chance of scaling the whole thing down using smaller lower voltage/amp rated componentry

    • Eric Barch says:

      Hi Einarr,

      At the current moment in time I’m not able to add those features, but I would love to make a much more feature filled version in the future. In terms of modifying the app, it probably won’t be all that bad. The code is pretty simple and it would just be a matter of placing new components on the GUI and then sending this additional data over in the packet byte array. You can take a look and see how I added the headlight switch to get an idea.

      As far as making this run on smaller scale robots, of course. As long as you can control it from an Arduino, this system should work well for you!

      Eric

  17. John says:

    Hello

    Great project!
    Question: Is the wiring diagram above for the Netduino the same as the Arduino?

    Thanks … John

    • Eric Barch says:

      Hey John,

      All should be identical…just keep in mind you’ll need to write in the code in the Arduino example to toggle the relay (if you’re adding one). Besides that, PWM 5 and 6 are the defaults.

      Eric

  18. Bill says:

    Hey Eric

    I got your older “PS2 Arduino wifi code” working with your
    “Open Source Robot Controls” Robot Side.
    My First Arduino Project.
    There’s still some bugs. Next I want Data feedback from the robot side = Speed, RPM, Gas Gauge, GPS. From a Lawn Mower “part 2 coming soon” Take a look at part 1: http://youtu.be/id6rz9pvz7s
    Thanks so much for the help.
    Keep up the GOOD work/fun

    Bill

    • ericbarch says:

      Hey Bill,

      This is awesome stuff! Glad to see it’s been working out well for you. I look forward to part 2 =) If you want to check out some code I’ve written since then that allows feedback data to be sent, here’s another project I’ve been working on:

      http://www.team221.com/robotopen/product.php?id=105
      https://github.com/221robotics/RobotOpen-Arduino-Library
      https://github.com/221robotics/RobotOpen-Java-DriverStation
      https://github.com/221robotics/RobotOpen-Android-DriverStation

      Eric

      • Bill says:

        Eric
        Now this is awesome stuff!
        You’ve been BUSSSSSY and then some.
        I look forward to trying it out, it will take me awhile to watch and read it all, But I did a quick 15min. skim over: On the robot side all the data is running over wifi and udp? Thru the arduino first? Then to the robot control shield? And the feed back is from the [robot control shield] and the [arduino] both?
        It looks like “I think android code” has video?? Is the video running thru udp to???
        Is the android code ready for prime time? – I’m not sure what to do with the code?
        Can’t find it on the market.
        Keep up the GOOD fun/work
        Bill

      • ericbarch says:

        Hey Bill,

        Yup, everything is UDP/WiFi just like IPGamepad. It passes through the Arduino and the atmega on the shield is for generating PWM signals. The feedback comes from the Arduino as the shield is just used for interfacing with the FIRST Digital Sidecar and PWM generation.

        The video is all separate of the Arduino. Just using a standard IP based camera. The Android code isn’t quite ready so it’s not on the market. The current version in Git is just for tablets – it does support an Xbox 360 controller though.

        Hoping to have more soon…thanks for checking it out =)

        Eric

  19. pittom says:

    can u make the ipgamepad with ip camera picture on the background and joy sticks on top of it

  20. Egoblitz says:

    Is there an update for Arduino IDE 1.0, they changed something in the UDP library and I can’t figure out how to get this to work. I’ve been banging my head for 3 days now.

  21. Egoblitz says:

    Well, I finaly got it working with Arduino IDE 1.0. Here’s what I came up with https://gist.github.com/3470380

    The python and andriod code is the same, only tested with python.

  22. Egoblitz says:

    Lemme try that again.


    /************************************
    * Arduino Based Robot Control System v0.2 RJ
    * by Eric Barch (ttjcrew.com)
    * edits to work with Arduino IDE 1.0 and tweaks by rivetjaw.blogspot.com
    ************************************/
    #include <SPI.h>
    #include <Ethernet.h>
    #include <EthernetUdp.h>
    #include <Servo.h>
    //Set the MAC address, static IP, gateway, and subnet of the network
    byte mac[] = {
    0x00, 0x1D, 0x60, 0xAF, 0x03, 0x35 };
    byte ip[] = {
    192, 168, 1, 22 };
    //UDP Stuff
    const int PORT = 4444; //Port of incoming UDP data
    const int PACKET_SIZE = 4; //Size of the joystick data packet
    byte joystick_data[PACKET_SIZE]; //Byte array for incoming data – [0] = leftY, [1] = leftX, [2] = rightY, [3] = rightX
    //Robot specific stuff
    boolean lastState = false; //Keeps track of when we go between enabled/disabled or vice versa
    unsigned long lastUpdate = 0; //Keeps track of the last time (ms) we received data
    //Define robot outputs
    int pwm01 = 5; //Digital Pin 5
    int pwm02 = 6; //Digital Pin 6
    //Speed Controller/Servo Objects
    Servo leftDrive;
    Servo rightDrive;
    EthernetUDP Udp;
    void setup() {
    Serial.begin(9600); //Setup serial comms for debugging
    // Start Ethernet and UDP
    Ethernet.begin(mac,ip);
    Udp.begin(PORT);
    Serial.println("Robot control system initialized.");
    }
    void loop()
    {
    xferdata();
    joystick_data[PACKET_SIZE] = Udp.parsePacket();
    //Only allow robot to be enabled if we've received data in the last 100ms and robot is set to enabled
    if (((millis() – lastUpdate) <= 100) && (millis() > 500)) //Robot is disabled for first 500ms of runtime
    enabled();
    else
    disabled();
    }
    /* This function's sole purpose is to receive data and shove it into the joystick_data byte array */
    void xferdata()
    {
    if (Udp.available()) {
    Udp.read(joystick_data,PACKET_SIZE);
    lastUpdate = millis();
    }
    }
    void enabled()
    {
    //If we were last disabled, we need to attach the PWM outputs
    if (lastState == false) {
    leftDrive.attach(pwm01);
    rightDrive.attach(pwm02);
    }
    //Output the left/right drive PWMs based on joystick input (0-180)
    leftDrive.write(map((long)joystick_data[0], 0, 255, 0, 180));
    rightDrive.write(map((long)joystick_data[2], 0, 255, 0, 180));
    //We are enabled
    lastState = true;
    }
    void disabled()
    {
    Robot is disabled, detach PWM outputs
    leftDrive.detach();
    rightDrive.detach();
    //We are disabled
    lastState = false;
    }

  23. Will says:

    Hello Eric, your project is amazing! I was wondering how the router is setup to receive data from python. Does the router need to be hacked or does it work straight out of the box with the original firmware installed on the linksys router? Any advice would be great!
    Thanks

    • ericbarch says:

      Hi Will!

      The router is completely stock – no modifications. The Arduino (or Netduino in this case) is what accepts and parses the data being transmitted from the phone. The phone has its own IP address and so does the Arduino/Netduino. From there it’s just being sent as UDP packets that contain the joystick values.

      • Will says:

        Sorry, I’m still having a hard time understanding the setup. Is the router on the Robot consider a “Wireless Bridge” to your home access point network? Or are you creating a totally different network all by itself for the robot? In that case, I’m guessing there’s new internet connection on the robot router??

  24. Will says:

    I meant to say “NO internet connection on the robot router” OPPS!

    • ericbarch says:

      Yup, completely separate network. That’s correct – there is no Internet connection when you are connected to the robot. You could certainly use a Wireless Bridge and connect to your home WiFi…but where’s the fun in driving a robot restricted to your house? =)

      • Will says:

        Can you get video feedback from an IP camera on the robot router network without any internet?? I never knew that was possible or not!! If so how difficult would it be to implement computer vision from the video feedback??
        Thank you so much for your replies, i’ve learned a lot from your tutorials!

        A group of us built a robot last year to compete in a NASA competition. That robot had a netbook communicating through serial to the Arduino. The programming language I used was Processing. I used a simple Client/server library to communicate with the robot and the control base computer. The problem with that setup is that the program must be running at all times in order for it to work. I REALLY like your idea of using a router instead of a netbook which makes things whole lot simpler.

      • ericbarch says:

        Indeed you can! A lot of IP based network cameras just have a web interface that you could log into (e.g. http://192.168.1.x) and view the video live. Axis specifically makes some really solid hardware/software that usually hits close to 30 fps over WiFi.

        Very cool project! Yup, simplicity is a beautiful thing!

  25. Will says:

    Hello Eric,
    Would it be OK if I reference your project for my thesis?

  26. Rob says:

    finally some code using upd ports! Love your work! Just getting back into this hobby.. was using oopic controllers before… Check out Ubiquiti’s Long Range Access Points/ Routers.. they are cheap and can be put into bridge mode very easily…

  27. Charles says:

    Hi Eric,
    I was wondering if it was possible to control the robot with the Arrow keys of my pc using the python application.
    thank you in advance.

  28. Andrew says:

    Could I use a tp-link nano router or does it have to be full sized router to set up a bot-to-laptop connection?

    • ericbarch says:

      Of course! There’s nothing special about the WiFi router. I’ve been playing around with TP-Link’s nano routers and they work great.

      • Andrew says:

        I was wondering if you could give me some extra guidance. I have a tplink wr702n router but im not sure what mode to put it in or how to set it up. Any help would be great.

  29. Dave Pina says:

    Let me start by saying YOU ROCK!!!!!!
    I implemented your ipgamepad robot control system and it works like a dream. Right now i have the left control running forward & reverse and the right control running the steering(tank style) on the ipgamepad app. Is there any way to configure the left control on the app to run forward and reverse on the y axis, and run the steering(tank style) on the x axis, leaving the right control unused. This would allow me to control forward, reverse, left and right with just one finger.

    Any help you can provide would be great!!

    Thank you
    Dave Pina

  30. Dave Pina says:

    Hi Eric,
    Back in June I mentioned how I used your app to control a golf cart on the golf course, so far so good it works Great!!!! The whole system functions, how ever I was wondering if there was any way to configure the left control on the app to run forward and reverse on the y axis, and run the steering(tank style) on the x axis, leaving the right control unused. This would allow me to control forward, reverse, left and right with just one finger. Is this possible?….and does it require a lot of rework?

    Thank you!
    Dave

  31. Dave Pina says:

    Hi Eric,
    Just wanted to touch base and ask you if you had a chance to review my previous post. I was wondering if there was any way to configure the left control on the app to run forward and reverse on the y axis, and run the steering(tank style) on the x axis, leaving the right control unused. This would allow me to control forward, reverse, left and right with just one finger. Is this possible?….and does it require a lot of rework?

    Thank you!
    Dave

  32. […] Source : https://ttjcrew.com/2011/07/22/open-source-robot-controls/ […]