# Posts Tagged robot One of the problem building a robot is the choice of motors. I’m speaking about a mobile robot with wheel. So, I’m not speaking about legs or others geometries.
A simple robot with 2 wheel that goes around in the house. So a robot moving on a flat surface, no hills. Without tracks, without rough terrain. No SUV!
In this situation the calculations are complex and out of the aim of this little tutorial for beginners.
First we can start from the value usually reported in any motor datasheet: the torque. The torque is, in the rotation, the equivalent of force in the linear motion. To push a box, bigger it is the force, bigger it is the acceleration. For a wheel, bigger it is the torque, bigger it is the wheel acceleration (rotational).

In the datasheets often it speaks about stall torque (start-up torque, stall torque) and, somethimes, about nominal torque (rated torque).

The start-up torque is the maximum torque that the motor can provide. But when the motor is in stall, the motor is stopped. So it isn’t very useful. It would be useful to have the rated torque, that is, (approximately) the maximum torque that ensures continous operation of the engine, without problems.

If the rated torque is not present in the datasheet, we can consider the first formula (approximated):

Rated torque=star-up torque / 2

Now, we can consider the robot motion formulas. There is a formula that links the motor torque with the robot weight and acceleration. So this formula provides us a very important information. That is, knowing the robot weight (in kg), knowing the acceleration desired, this formulas says wich is the torque that we have to consider in the motor choice.

Some information are required:
– robot mass (you can put the robot in a balance and read the weight in kg).
– the robot acceleration desired. For example, 0.5 m/s^2. This means that we start the robot motion, after 2 seconds it will have a speed of v=a*t=0.5*2=1 m/s, i.e. a meter for each second. Not so bad for a home robot.

The motion formula is:

C/r=m*a + Fattr

where: C is the rated torque of the motor, r is the wheel radius, m is the mass, a is the acceleration and Fattr is the attrition force (here mostly rolling) between the wheel and the floor.
The Fattr is complicated. We can do a semplification:

Fattr=m*a

Basically, when we have to calculate the torque, we can double the torque deriving from the m*a calcolation. Maybe, this could be a conservative calculation, but we can be serene in the motor choice.

So let’s recap:

C/r=2*m*a

We must consider that the robot is pushed by two engines, the right one and the left one, so we just need half torque. The formula becames:

C/r=m*a –> C=m*a*r

Let’s take an example. Suppose you have a little robot that weights 2 kg, with two wheels with 8 cm diameter (4 cm radius) and we want an acceleration of 0.5 m/s^2. You get:

C=2*0,5*4=4 N*cm.

So the engine should have a 4 N*m torque. The motors often have a torque indicated in kg*cm. So we have to divide by 9.81 (approximately 10).

So you get a motor with a rated torque of 0.4 kg*cm, and 0.8 kg*cm of start-up torque. Easy or not?

Now consider the speed. Suppose we want a robot whit 1 m/s of speed, that means 3.6 km/h.
If the wheel has a 4 cm radius, the distance traveled at each revolution is:
d=2*pi*r = 6.28 * 4 = 25.12 cm
So, to make 1 meter per second:
100/25.12 revolution per second = 3.98 revolution per second.
knowing that in a minute there are 60 seconds, you get the revolutions per minute (rpm), another data often written in a motor datasheet.

rpm = revolutions per second * 60 = 3.98 * 60 = 239 rpm

With the data of torque and the rpm we are able to choose the right motor.
All the formulas are simplified, however, it is enough for beginners and for DIY robot builders!

Tags: ,

The first robot presented is called “Geronimo” and it is a simple autonomous robot with an ultrasonic sensor for obstacles avoindance.
This robot can be built by a newbie of robotics. Components:

The robot is assembled starting from these components:

 arduino duemilanove robot chassis (link) ‘L’ support for servos   (link) servos Hitec HRS 1422CR with continuous rotation (link) Hitec wheels for servos (link) ball caster  (link) ultrasonic sensor DFRobot URM37 V 3.2 (link) servo for ultrasonic sensor (the cheapest in ebay) 400 contacts breadboard (link) batteries, jumpers, screw and other simple hardware

Functionalities:

The robot, very basic and simple, goes straight and verifies if there are obstacles. If it found some obstacle, it turns the ‘head’ and sees at the right and at the left in order to verify where the street is more free.

Then it goes where the street is more free. Nothing of special. This is a short video to see how the robot goes in a  path with obstacles:

Another video:

I liked very much the ultrasonic URM37. Libraries (link) that drive the sensor are available and they are easy to use. The sensor is advanced: in fact it can offer these functionalities:

– distance measurement between 4 cm and 3 meters

– temperature measurement

– sensor servo driving and control

This is the sensor: At the beginning it seemed very interesting the functionality of servo driving offered out-of-the-box by the sensor,  however making some test I couldn’t to drive well the servo, that it went from a part to another part at maximum speed. So, I used directly Arduino to drive also the sensor servo. I think that spending more time, it is sure possible to make something better.

• Chassis and ‘L’ supports. Perfect, nothing to say
• Servos Hitec: not very well. Unfortunely they don’t have a pot to regulate the stall (I mean to stop them), so I have tried with some tests. Finally I discovered the stall value. Another issue consist in turning the servos to a precise angle. The only method that I could use is many, many tentatives. I know that is a common problem for continuous rotation servos.
• Batteries and Arduino: I used two batteries, because the Arduino hasn’t enough current to feed the servos.  When I divided the power, I hadn’t problems.

Some photo of robot process building:    This is the Arduino Code used for robot programming:
```#include "URMSerial.h"
#include <Servo.h>
Servo sservo;
Servo dservo;
Servo uservo;
int ang=0;
int angolomax=0;
int distmax=0;
int value=100;
int ind=0;
int rotazione=0;

// Definizione delle misure - Measures definition
#define DISTANCE 1
#define TEMPERATURE 2
#define ERROR 3

//angolo di riposo dei servi delle ruote - wheels stop angle
#define RIPOSOS 94
#define RIPOSOD 93

// inizializza l'oggetto della libreria urm del sensore ultrasuoni - initialize urm library ```
```URMSerial urm;

void setup()
{
Serial.begin(9600);  // baud rate at 9600
urm.begin(9,10,9600); // RX Pin, TX Pin, Baud Rate
sservo.attach(6);   // left servo to pin 10
dservo.attach(5);    // Right servo to pin 9
uservo.attach(3);    // Ultrasonic servo to pin 3
uservo.write(90);    // put ultrasonic servo straight
delay(100);
}

void loop()
{
//   sservo.write(RIPOSOS); // stop the robot
//   dservo.write(RIPOSOD); // stop the robot
sservo.write(RIPOSOS + 90); // go straight
dservo.write(RIPOSOD - 90); // go straight
// Richiedi la distanza al sensore ad ultrasuoni - ask ultrasonic sensor for distance
urm.requestMeasurement(DISTANCE);
delay(50); // attendi allineamento dei servi - wait for servos alignement
{
switch(urm.getMeasurement(value)) // Verifica che il valore letto sia una distanza
{
case DISTANCE: // Ulteriore verifica che sia una distanza - verify that read is a distance
if (value < 20 & value > 0)  // se il valore e' < 20 cm stiamo per sbattere - if < 20 cm turn
{
angolomax=0; // imposta l'angolo di migliore uscita a zero - set best exit angle to zero
distmax=0; // imposta la distanza di uscita migliore a zero - set best distance exit to zero
sservo.write(RIPOSOS);  // ferma il servo in posizione di riposo - stop servo
dservo.write(RIPOSOD);  // ferma il servo in posizione di riposo - stop servo
delay(100);

for (ang=0; ang<180; ang +=5) // obstacles control
{
uservo.write(ang); // set ultrasonic sensor on ang value
delay(20);
{
switch(urm.getMeasurement(value))
{
case DISTANCE:
if (value > distmax) // verify if distance is > max
{
angolomax=ang;  // set new max angle
distmax=value;  // set new distance max
} //end if (value > distmax)
break;
} // end switch
} //end for (ang=0; ang<180; ang +=5)

uservo.write(90); //set the URM servo straight
delay(135);
// write angle read in the serial port
Serial.print("Angolo max \t");
Serial.println(angolomax);

//set servos to max distance

if (angolomax > 180)
angolomax=180;
if (angolomax < 0)
angolomax=0;

rotazione=abs(angolomax-90);

// write value to serial port
Serial.print("Angolo inviato ai servi \t");
Serial.println(RIPOSOS+angolomax-90);
Serial.print("Valore di rotazione \t");
Serial.println(rotazione / 9);
// go servos to max angle and max distance
for (ind=1; ind < rotazione / 4; ind+=1)
{
sservo.write(RIPOSOS+angolomax-90);
dservo.write(RIPOSOD+angolomax-90);
delay (40);
} // end for (ind=1; ind < rotazione / 9; ind+=1)
} //  end if (value < 20 & value > 0)
break;
} // end switch