Monday, 9 March 2015

Tubby Bot, Simple Autonomous Robot

Ya just gotta love these Rolling Robots, well my grandchildren love them. I had been looking for a simple but entertaining rolling robot for a while and I came across a little robot called PopPet by Jaidyn Edwards, a young Australian now producing professionally made versions of this lovable robot and selling them from his poppettherobot.com site and they are as cheap as chips in the kit form. This inspired me to have a go at designing something similar but I wanted to be able to make it from the bits that I had in my workshop now, I didn't want to buy a single thing. Mind you I will be purchasing one of the PopPet kits from Jaidyn. Now I supply this information as is, it is for entertainment purposes only and if you use it you do so at your own risk. That out of the way lets begin.

So what did I have in my workshop, 3mm compressed particle board, empty CD cases, all but empty tub of CD's, servo motors but the micro versions, an Arduino Pro Mini clone, an ultrasonic sensor, battery holder for 4 AA's and enough bits and pieces to put a simple robot together. I didn't want to follow my normal path and use the chipboard as the chassis so I decided to use the CD Tub that had only one CD in it. I wanted to make the wheels and caster from scratch and use as simple a sketch as I could to get it working and avoiding objects. I only had two servos so the ultrasonic sensor had to be fixed, that is it couldn't sit on a servo motor to move it around. Remember that some  Arduinos operate on 5Volts (Some operate on 3.3Volts) and 4, 1.5Volt AA's is 6Volts so ONLY USE RECHARGEABLE BATTERIES. 4, 1.2Volts is 4.8Volts. (Actually it's 5.27 fully charged in my setup but that's fine) Make sure that the Arduino you use is the 5Volt version otherwise change the power supply to match the board you use.
This is my version of the robot.

First the tub, I had to plan a layout that fitted all the components inside it and how to mount everything.

                                     The Tub that was to be the Chassis


                                 The two Tower Pro 9g Standard Servos

The small size of the servos meant I had a lot of room inside the tub and everything will fit inside it, even the battery holder with room to spare.

                                Small cutouts to let the motors mount flat

Once I knew where I was going to mount the servo motors I was able to measure the space available for the wheels and I cut the wheels out using a hole saw, the added advantage of that was it drilled the centre hole for the servo horn at the same time.


                                  The wheels and servo horns that I used


                                      The servo horns were self locating

The lucky part was the servo horns were self locating, but once you marked the holes and drilled them you have to turn the horns back over so the mounting head is pointing away from the hole, see my images.

                                        Holes marked and drilled


                         Take note of the mounting position of the servo horn


As you can see the servo horns are now mounted the other way up after you drill the holes, now you have to trim the excess screw thread down level to the nut, make sure it is tight after you trim it down. See my images below.


                                      Screws trimmed down to the nut

Okay wheels are done, you need to do one more thing so they can rotate without fouling things, the location pin next to the motor shaft needs to be trimmed off and filed flat, see the images below.

                       See the little location pin just to the left of the drive shaft


                                                Trim it off and file it flat

Next we need to modify the small servo motors for continuous rotation, that's a bit painful in little motors like these but it can be done. Two screws in the bottom of the motor, some might have four, remove them and take the bottom plate off the motor, I carefully pulled the electronic PCB up to gain access to the wiring that goes to the trim pot, I had to get a firm grip on the pot terminals, not the wiring, the metal tabs on the pot itself, a good wiggle and I pulled until the pot came out. Simples....

                        Motor end cap off and PCB up and out of the way


                      Trim pot out of the motor and wiring location recorded

As I said take note of how the pot is wired, especially the pot wiper connection and then cut the wires right at the terminals of the pot, leave all the wiring in place. Now get the two 1% 2K5 Ohm resistors and twist the end of both together and trim the excess wire, make it as short as is humanly possible yet secure and to be able to bend back on itself. Slip a length of heat shrink over the wiper wire and solder the wire to that twisted pair. That is the centre of the voltage divider network, it will be half the voltage supplied to the network. Slide the heat shrink up and over the solder joint and twisted wires so it is insulated. See the images below.

             Wires twisted together to form the centre tap of the voltage divider

              The other wires soldered to the other two ends of the resistors

             The three wires connected and ready to be protected in heat shrink

The other two wires are connected to the other two ends of the resistors, one on each and it doesn't really matter which wire goes to what as it is a voltage divider network made up of equal size resistors, now slide the heat shrink up and heat it so it shrinks and insulates the wires and resistors and put it all inside another bit of heat shrink but keep it as small as possible because it has to go inside the motor case and its a tight fit.
Now the gear box, you now need to remove the top of the motor to reveal the gearbox, take your time and take note of the layout as you go. Locate the gear that has the limit pin or block, see the photo below.

                                  The gear with the limit pin or block

The limit pin or block as above must be removed but be very careful not to damage the gear itself and now the metal shaft that locked into the trim pot, cut the section with the two flats off just below the flats so it no longer protrudes into the electronics section. Now put the motor back together, start at the gear box and work backwards, make sure everything is secure and can't cause short circuits and the like. replace the screws and your done. Lets get back to the tub.

                                  The tub base showing the wheel cutouts

You can now measure and mark out the holes for the wheels to extend through, see image above, take your time and measure twice and cut once and trial fit as you go and make fine adjustments as required. Remember that the wheels need to be aligned carefully for correct operation.

                                Motors on wheels ready for final assembly

As all of this was going on I took the top of the tub outside and roughed up the outer surface with fine sand paper and gave it a coat of paint, undercoat first and then the colours that I had chosen, really it was what paint I had to hand, lots of yellow and a bit of red. I had also measured up and drilled the holes for the ultrasonic sensor and on off switch so I didn't have to do it after I had painted it all and have the paint come off. Once again make a template for the sensor, makes it a lot easier.

                                       Motors mounted with Hot Glue

Okay, why hot glue you ask, because it's what I had, not only that if you sand the areas that the glue has to stick to it makes a far better bond and I have been using hot glue for many years and it has worked perfectly for me every time, get the preparation right and it will stick beautifully. How you mount it is up to you.


                    Note the Hot Glue applied to the cutouts from underneath

                                           My home made caster?

You can see in the image above that I made my own caster wheel, I am going to replace it, it works but not a well as I had hoped, it's on the bot in the video but I didn't show you the full video, I took the part where the bot over balances out, the caster swings around and in one spot it lets the bot over balance and loose traction, it just needs to be smaller, the centre of the pivot and centre of the wheel need to be closer together, I'm looking at making a ball caster for it.

                                  Wood wheels and caster in place

I did use wood glue on the caster wheel but I also used some hot glue to make it a bit more kid proof, the youngest grandson likes to pick it up and throw it, it did survive him, well 80% survive, the battery holder came away so I had to re-mount it but it was easily fixed and I made it stronger the second time around.
Back to the build, the wiring next.


                                       Busbar and motor connectors

The image above shows you the Busbar and Motor Connectors, making these means I can re-use the components and makes the hookup much easier and safer. The switch is wired in on the negative/0V line, I do it this way every time. Note the use of heat shrink over every soldered joint and also on the motor connectors to make it much more secure, develop good habits and your builds will last longer and have far less break downs. The Arduino Pro Mini has male pins so I was able to use the female terminals from Jaycar and some heat shrink tubing to insulate them. See image below.


                     Female Terminals used to connect to the Arduino Male pins

The top of the tub should be painted and dry, mount the ultrasonic sensor into the top and secure it with a bit of hot glue, at the same time solder the 0V/negative lead from the battery holder to the switch, don't forget the heat shrink, and mount the switch.


                                  Switch and ultrasonic sensor mounted

Make all the connection wires making sure that they are long enough to be able take the top off for servicing and changing batteries. I mounted the Arduino Pro Mini clone on the shaft on the base, it fitted over this shaft nicely with all the wires connected. I used a small amount of hot glue just to hold it while I put the cable tie around it for extra support, remember the grandson that sends it flying, it has to be strong. The wiring is made safe with a cable tie or two as well.

                   Arduino cable tied and excess motor wiring also cable tied


                         Busbar hot glued to the base and wiring made safe


                                   Battery holder mounted with hot glue

The components fitted inside the tub very well, remember to make the battery holder mount as strong as possible, I had to re-do mine, bit of extra sanding and extra layer of hot glue, strong as now. The connections to the Arduino will depend on the Sketch you use but now is a good time to test everything on the bench. WARNING, only use RECHARGABLE BATTERIES.


                                   All the wiring done and made safe


                           Final test fit of the top and some art work applied

We need to talk about the Sketch or Code that I used, I have been trying to learn the language of micro controllers for months and I have been collecting the code as I have been going. I stand on the shoulders of the many Great Women and Men that have gone before me and use this material that I collect and modify it for my projects. This is the beauty of Open Source and the community that supports it, just amazing so credit belongs to them not me, I simply change a few numbers around to make it all work in my project. That said, I can't remember where I got this code from and the author didn't put her/his name to it and I never remove the authors information, NEVER. It is Open Source and we are free to use it so here it is;

Simple_Servo_Obstacle_Avoidance _Robot_2015
#include <Servo.h>     //Inclue Servo Library
#include <NewPing.h>   //Include NewPing Library

Servo leftServo;       //Create Left Servo object
Servo rightServo;      //Create Right Servo object

#define TRIGGER_PIN  6   //Trigger pin of Ultrasonic sensor connected to pin 6
#define ECHO_PIN     7   //Echo pin of Ultrasonic sensor connected to pin 7
#define MAX_DISTANCE 100 //The maximum distance we want the sensor to look for is 1m

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);  //Create Ultrasonic sensor object

unsigned int time;            //Variable to store how long it takes for the ultrasonic wave to come back
int distance;                 //Variable to store the distance calculated from the sensor
int triggerDistance = 30;     //The distance we want the robot to look for a new path
int fDistance;                //Variable to store the distance in front of the robot
int lDistance;                //Variable to store the distance on the left side of the robot
int rDistance;                //Variable to store the distance on the right side of the robot

void setup()
{
  leftServo.attach(9);        //Left servo connected to pin 9
  leftServo.write(90);        //Write the neutral position to that servo
  rightServo.attach(8);       //Right servo connected to pin 8
  rightServo.write(90);       //Write the neutral position to that servo
}

void loop()
{
  scan();                                //Get the distance retrieved
  fDistance = distance;                  //Set that distance to the front distance
  if(fDistance < triggerDistance){       //If there is something closer than 30cm in front of us
    moveBackward();                      //Move Backward for a second
    delay(1000);
    moveRight();                         //Turn Right for half a second
    delay(500);
    moveStop();                          //Stop
    scan();                              //Take a reading
    rDistance = distance;                //Store that to the distance on the right side
    moveLeft();
    delay(1000);                         //Turn left for a second
    moveStop();                          //Stop
    scan();                              //Take a reading
    lDistance = distance;                //Store that to the distance on the left side
    if(lDistance < rDistance){           //If the distance on the left is smaller than that of the right
      moveRight();                       //Move right for a second
      delay(1000);
      moveForward();                     //Then move forward
    }
    else{
      moveForward();                     //If the left side is larger than the right side move forward
    }
  }
  else{
    moveForward();                       //If there is nothing infront of the robot move forward
  }
}

void scan(){
  time = sonar.ping();                  //Send out a ping and store the time it took for it to come back in the time variable
  distance = time / US_ROUNDTRIP_CM;    //Convert that time into a distance
  if(distance == 0){                    //If no ping was received
    distance = 100;                     //Set the distance to max
  }
  delay(10);
}

void moveBackward(){
  rightServo.write(180);
  leftServo.write(0);
}

void moveForward(){
  rightServo.write(0);
  leftServo.write(180);
}

void moveRight(){
  rightServo.write(0);
  leftServo.write(0); 
}

void moveLeft(){
  rightServo.write(180);
  leftServo.write(180);
}

void moveStop(){
  rightServo.write(90);
  leftServo.write(95);
}




Remember if you use this sketch you may need to change some of it to work with your robot, It worked perfectly as is in mine. As I mentioned I not sure who the author is but my best guess is Jaidyn Edwards from poppettherobot.com as I think his work is amazing and I follow him on the Internet, his training videos are excellent.


                               This is a short video of Tubby Bot working

Well I hope you enjoyed this and you are now inspired to have a go at making your version of this little robot, my grandchildren have a ball with them and that alone makes it all worth while, remember I'm no expert at this and If I can do it so can you, all you have to do is have a go at it, enjoy. Cheers, TJ.











































































                                   

No comments:

Post a Comment