Project 1: Moving IdeaBot

Introduction


Welcome, in this project you will learn how to :

  • Assemble IdeaBot Chassis.

  • Get introduced to servo motors and how to connect them to IdeaShield.

  • Calibrate continuous servo motors.

  • Driving mechanisms of IdeaBot.

  • Write functions and make things easier.

So put IdeaBot in front of you and start learning robotics now !


IdeaBot body fully assembled and ready to move, see assembly below to reach this state easily


Assembling The Body

A Step-By-Step Guide


First you need to assemble the mechanical body of IdeaBot, we did a very detailed assembly procedure just follow the pictures below or watch the video of assembly.





 

1: Locate the chassis.


2: Locate the 2 standard servos.


3: Push servos into their slots.


4: Locate the 8 M4x10 mm nuts and bolts.


5: Tighten the nuts and bolts, you will have to screw the bolts into the servo holes.


6: Locate the 2 wheels and the 2 M2x5 mm screws.



7: Push the wheels on to the servo heads and tighten the screws.


8: Locate 4 M20x3 mm pushers and nuts.


9: Push the pushers into their corresponding holes and tighten the nuts.


10: Locate the ball caster and the 4 M3x5 mm screws.


11: Hold the ball caster against the pushers and tighten the screws.


12: Locate one of the Velcro strips.


13: Stick the Velcro to the back of the robot.


14: Locate the Arduino and another strip of Velcro.


15: Stick the Velcro to the bottom of the Arduino.


16: Align the Velcro on the Arduino and the robot.


17: Press the 2 strips of Velcro together.


18: Locate the shield and align its pins with the corresponding headers on the Arduino.


19: Push the shield and the Arduino together.

20: Locate the right Velcro battery attachment, 2 M3x10 mm standoffs, and 2 M3x8 mm screws.


21: Tighten the screws and standoffs.


22: Align the right Velcro battery attachment with the robot chassis as shown.


23: Locate 2 M3 nuts.


24: Tighten the nuts and standoffs.


25: Locate the left Velcro battery attachment, 4 M3x10 mm standoffs, and 4 M3x8 mm screws.


26: Tighten the screws and standoffs.


27: Align the right Velcro battery attachment with the robot chassis as shown.


28: Locate 4 M3 nuts.


29: Tighten the nuts and standoffs.


30: Locate the battery pack and the power cable, and install the batteries.


31: Snap the power cable on the battery pack, and align it as shown.


32: Push the power cable through the hole on the right side of the chassis as shown above.


33: Feed the power cable through the hole, and push the battery pack between the Velcroed panels, try to keep the battery pack as close to the servos as possible as this will make it easier to install the gripper.


34: Plug the power cable into the Arduino as shown.



DC Servo Motor


A DC servo motor is one famous type of DC motors, it is widely used in robotics for many reasons one of them is the ease of use of the servo motor since the motor drivers are built in the motor.


Standard Servo Motor Picture.

The servo motor comes in two main categories:

  1. Continuous Servo motor, meaning that it rotates continuously around.
  2. Standard Servo motor, meaning that it has a limit in rotation like only 90,180 or 360 degrees.

The one included is of course the continuous servo to move freely like a car.

Internal Structure of Servo Motor.


now let us know what the colored wires of the servo means


Color coded wires of the servo and their functions.




These color coded wires of the servo represent the following:

  1. Red is the power wire input, normally +5 volts.
  2. Brown is the ground connection or negative (-ve) connection.
  3. PWM is the control signal input generated from the Arduino to control the speed and direction of the motor.
    (Note: we will explain PWM concept later on separately, all you need to know now that it is the speed and
    direction control signal of the servo motor.)


Connections and Calibration


Connecting the servo motor to StartUp shield is very easy.

After Assembling the body now all you need is to connect the wiring, calibrate the servos and start programing the movements.

StartUP shield have 4 servo motors connections which are D6,D9,D10 and D11 you are free to connect the two servos to any of these pins. But make sure to connect the brown wire side to ground and the orange color to the signal pin which is one of the D's.


The connection of servo to StartUP shield, you can connect the other servo in pin D10.




Once you have connected the servos as shown, they must be calibrated before they can be used.


What is Calibration and why ?


The continuous servo moves in two directions Counter Clock Wire and Clock Wise  and also can move in different speeds. To do that the Arduino has its own library for servo control through PWM, all you need to know now is the following code command

ServoName.write( Number Value Here );

 This code is using the <Servo.h> library from and we will discuss code in details next section. But for now our main concern is the ( Number Value Here ), this value can be from 0 to 180 only.

So in order to have a backward and forward movement there should be a mid point which is the number 90. So we need to make sure that the servo will be at a stop state when we set the command to 90, and 0 being full speed in one direction, 180 full speed in the other. Calibration is necessary to make sure the servos don't move when set to 90.


A graph that shows the Number Value and the states for each value.


The servos are calibrated using a small screw driver to rotate the potentiometer until it stops at that value which is 90. the video below shows how to calibrate the servos.



Note you need to download the code first below the video and start calibrating.!

Now upload the calibration code shown below. ( Copy and Paste it in Arduino IDE )

Notes:

  • Make sure you have connected the servos to pin D10 & D11 as they are used in that code.
  • Be gentle on the servo potentiometer screw while doing the calibration.
  • The following code will be explained in details in the next section


Copy & paste this code for calibration, and read the comments to understand the code !

#include <Servo.h>  // include the servo library to use the servo commands by arduino.

 // create servo object to control a servo, here we are defining the names of the servos which could be anything.
Servo a;      //Defining a servo name 'a' , you can call it also left or right to make it more clear.
Servo b;      // here the other servo is called 'b'

void setup()
{
  a.attach(9);  // Here we specify servo 'a' connected to which pin to the shield, we have connected it to 10. Make sure it is the right servo.
  b.attach(11);  // b is the left servo
}

void loop()
{
    a.write(90); // commanding servo a speed to go to 90 which should be stop position.
    b.write(90);
}



Make IdeaBot Move


Now that you have IdeaBot assembled and its servos calibrated you can write your first real program, and before that here is a picture that describes the movements of IdeaBot two wheels mechanism



Two Wheels Movement Mechanisms

So in it is obvious that if you want to move straight you should have both motors at the same speed and direction and for turning right or left one of them should have more speed than the other and by controlling speeds you can control the curve of turning.


Driving in a straight line



IdeaBot Moving in a straight line


The code to drive forward in a straight line is written below.

Note: the code is explained through the comments in the lines.

#include <Servo.h>  // include the servo library

 // create servo object to control a servo, here we are defining the names of the servos which could be anything.
Servo a;      //Defining a servo name 'a' , you can call it also left or right to make it more clear.
Servo b;      // here the other servo is called 'b'

void setup()
{
  a.attach(9);  // Here we specify servo 'a' to which pin it is connected to the shield, we have connected it to digital pin #10. Make sure it is the right servo.
  b.attach(11);  // b is the left servo
}

void loop()
{
    a.write(0);         //Commanding the right servo 'a' to move at maximum speed.
    b.write(180);    // Commanding the left servo 'b' to move at maximum speed in the opposite direction to move straight.
}

This code sets IdeaBot driving forward, and at maximum speed, notice that the left servo is set to 0 and the right servo to 180, this is because the 2 servo's face in opposite directions and for both to rotate in the same direction, one must rotate opposite from the other.


Driving Backwards in a straight line



Driving Backwards


The code to drive backward in a straight line is written below.

#include <Servo.h>  // include the servo library

 // create servo object to control a servo
Servo a;      // right wheel
Servo b;      // left wheel

void setup()
{
  a.attach(9);  // attaches the servo on pin 9 to the servo object
  b.attach(11);
}

void loop()
{
    a.write(180);
    b.write(0);
}

This code sets IdeaBot driving backward at maximum speed, the only difference between going forwards and backwards is that the servo speeds are switched.


Turning Left



Turning Left


The code to turn left about IdeaBots center written below.

#include <Servo.h>  // include the servo library

 // create servo object to control a servo
Servo a;      // left wheel
Servo b;      // right wheel

void setup()
{
  a.attach(9);  // attaches the servo on pin 9 to the servo object
  b.attach(11);
}

void loop()
{
    a.write(0); 
    b.write(0);

   // both servos moving in opposite directions
}

This code sets IdeaBot rotating about itself counterclockwise at maximum speed. To turn a certain angle, a slightly more complicated program is needed.


Turn IdeaBot a Fixed Angle



Turn a fixed angle left using delay.


The code to turn left for a fixed angle is written below.

#include <Servo.h>  // include the servo library

 // create servo object to control a servo
Servo a;      // right wheel
Servo b;      // left wheel

void setup()
{
  a.attach(9);  // attaches the servo on pin 9 to the servo object
  b.attach(11);
}

void loop()
{

    a.write(0);     // start IdeaBot turning
    b.write(0); 

    delay(450);    // let IdeaBot turn for .45 seconds     

    a.write(90);    // stop Ideabot
    b.write(90);

    delay(1000);   // wait 1 second before repeating
}

The code above will rotate IdeaBot counterclockwise for .45 seconds, to change the angle that IdeaBot turns the delay time can be increased or decreased accordingly. To rotate 90 degrees, a delay of about .45 second is needed. 

The code to rotate clockwise is exactly the same except that the numbers 0 and 180 should be switched so that IdeaBot will rotate the other way.

Note: there are many other methods to turn exactly a chosen fixed angle, like adding encoder sensors or changing the type of the motors to achieve time independent fixed angle turning.
we will discuss this at a later level of Ideabot tutorials.



Introduction to Functions


In general, functions can be used to make programs simpler. For example, instead of writing the code to turn or drive each time you want to turn or drive, you can write them once in a function and then call the function each time you want to turn or drive IdeaBot.


So how can you write your own function ?


The function type should be declared first, then the name of the function followed by two parentheses . After that you open curly brackets and write your code inside that function.   

void myfunction()
  {

      write the code here;

    }

Calling the function

void loop
{

    myfunction();      // here the function is called and the code inside it is executed.

}

void myfunction()  // here the function is declared after the main void loop.
{                       

// could be drive the servo forward code;

}

The word void technically means don't return any value when the function is executed. We will know more details about functions in the next tutorials.

A simple program to drive IdeaBot in a square is written below.

#include <Servo.h>

Servo a;  // create servo object to control a servo
Servo b;

void setup()
{
  a.attach(9);  // attaches the servo on pin 9 to the servo object
  b.attach(11);
}


void loop()
{

  drive();     // much simpler than writing code each time
  turn();
 
}


void drive()      // here is my function I created and called it drive
{
  a.write(0);    // turn on servos
  b.write(180);

  delay(800);  // drive for .8 seconds

  a.write(90);  // turn off servos
  b.write(90);
}


void turn()    // another function is created and called it turn
{
  a.write(0);    // turn on servos
  b.write(0);

  delay(450);  // turn for 1 seconds

  a.write(90);  // turn off servos
  b.write(90);
}



The results of the above code with functions implemented is the following square movement.


Square movement made easy using separate functions




Ready to Follow ?


Now you know how to move your robot. So are you ready to learn something more interesting !


  Project 2 : Line Following Robot







Have Fun and Learn Something !




We ship to the GCC and MENA regions.

Reliable and fast shipping to your door, quality assured.

More about shipping

Find us on
Instagram

Just type @idea_link

Visit our profile