PAGE 1 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
ONE DAY OF ROBOTICS
#1 MOTOR CONTROL
WITH COACH MICHAEL
[THIS BOOKLET FOR USE WITH A PRE-BUILT PRIMO ROBOT]
A rapid introduction to the world of robotics and mechatronics where you learn to write and
upload text-based programs to a pre-built robot to control its movements, and participate in
a robotics challenge to inspire you to consider a career in engineering
PAGE 2 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
NOTES
PAGE 3 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
ONE DAY OF ROBOTICS
CONTENTS
PART 1: Getting Connected
PART 2: Upload LED code
PART 3: Motor Control
PART 4: Moving PRIMO forward
PART 5: Turns and Pivots
PART 6: A Mini Challenge
PART 7: Coding Stages
APPENDIX 1: Calibration in Hardware
APPENDIX 2: Calibration in Software
PAGE 4 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
NOTES
PAGE 5 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
ONE DAY OF ROBOTICS
A CRASH CODING COURSE AND MINI COMPETITION
INTRODUCTION
How much robotics can be taught in a just a few hours? Quite a lot, really.
Using a mini competition as a focus – and having equipped the participants with quality notes that include
sample codeand a pre-built robot – the “One Day of Robotics” experience is guaranteed to inspire young
people by showing them they can quickly acquire competence in this exciting field. Part of the One Day of
Robotics experience includes career awareness.
OUTCOMES
By the end of the day the trainees will know how to operate a small desktop robot. They will learn how to write
and upload program code on a computer, and upload the programs to the PRIMO robot. They will learn how to
control the speed and direction of rotation of motors in order to control movements of the robot.
Participants will learn about how a robotics challenge works, and what the competition maze looks like. They
will earn how to navigate using a simple method called dead reckoning to solve the problem. The teams will be
briefed on how to create a strategy to tackle the challenge more effectively, and after a short practice session
the competition will start.
Teams will write their own program code to get through the maze. The team that completes the challenge
arriving first at the FINISH will be deemed winner, alternatively the team that gets furthest into the maze
towards the FINISH when the end of competition whistle blows will be deemed the winner. Second and third
places will be awarded [same rules].
Welcome +Safety
Introduction
Crash Coding Session
Quick Break
The Challenge
[practice session]
Mini Competition
www.robotscience.co.za
www.youtube.com/electronicsafrica
PAGE 6 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
NOTES
PAGE 7 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 1 CONNECT THE PRIMO ROBOT TO PC USING USB
Welcome to ONE DAY OF ROBOTICS where you learn to write a few lines of code to control the movements of a
small desktop robot with the minimum of code. By learning how to change the numeric values in the code, and
observing the effect of the changes on the movements of the robot every time you upload the new code, you
can control the distance the robot travels in a straight line and even make it execute some turns and drive into
a maze.
Using the “trial and error” method you can learn how to control the robot without too much difficulty. Pay
attention and understand the notes because after the “code and upload” session there’s a maze navigation
challenge.
If you read these notes very carefully – and take your time to properly understand the explanations of how the
code [and especially the numbers contained in the code] control the hardware – you should be able to
complete the mission.
BELOW LEFT: PRIMO ROBOT BELOW RIGHT: PRIMO “TOP DECK” ROBOT
The PRIMO robot is based on a microcontroller programming board called Arduino UNO. More than 10 million
Arduino UNO controllers have been bought by professional electronics engineers [and hobbyists] over the past
decade making Arduino the most widespread controller in the world. Arduino can be programmed with C++
type text code using a free software integrated development environment [IDE] and there’s even an easy
graphical [block] code option.
THIS IS WHAT THE ARDUINO PROGRAMMING IDE START SCREEN LOOKS LIKE:
PAGE 8 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
Upload the program code to the robot using the USB cable, if you are using a USB adapter cable type with the
small circuit board, to prevent damage make sure the parts side is facing up when you plug it into the robot:
Before uploading your Arduino program to the robot, in the Arduino code editor click on the <TOOLS> menu,
then <PORT> and make sure the active COM port is selected, and is showing a check mark like this screenshot:
If there’s more than one active COM port, and you’re not sure which one the Arduino is connected to, then do
a Windows search and open Device Manager and look at Ports (COM & LPT). If you’re not seeing the COM port
as per above right screenshot, or there’s an exclamation mark with a yellow triangle, speak to your instructor.
If you’re uncertain which the robot is connected to, first disconnect and then re-connect the robot and observe
which COM port vanishes and comes back. Thats the COM port you to select in the Arduino IDE.
When you upload code to the robot, if the screen turns orange at the bottom, that means there are mistakes.
Check your code very carefully for wrong characters and brackets and semicolons and keep trying until it
compiles without errors. Speak to your instructor if you can’t find the error.
PAGE 9 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 2 PROGRAM TO FLASH LED ON ARDUINO D13
The brain of your robot is a microcontroller chip ATMEL ATMEGA 328P-PU. The ATMEGA 328 is the heart of the
Arduino UNO system which is an open source prototyping controller that allows you to control a range of on-
board and off-board systems. There is an on-board LED on the Arduino UNO, the motors on the robot are an
off-board system.
OPEN SOURCE ARDUINO UNO [WITH ATMEL ATMEGA 328P-PU MICROCONTROLLER CHIP]
The PRIMO ROBOT you are working with may have an Arduino UNO plugged on top, in which case it is called
the PRIMO Top Deck robot, alternatively the Arduino UNO may be embedded directly on the PRIMO robots
own red circuit board.
ARDUINO PRIMO ROBOT SHOWING THE “TOP DECK” VERSION WITH UNO CONTROLLER ON TOP
The Arduino UNO has a huge community of users around the world, many of whom help beginners get started
with online forums, there are almost endless low cost accessories, and if you wanted to invent something its
quite likely someone somewhere in the world might be able to help and advise you.
If you look carefully at the PRIMO robot you will see it has ON-OFF switches for POWER and MOTORS. When
you connect the robot to the computer used to program it make sure the MOTORS switch is in the OFF
position. Don’t panic if your robot does not look identical to the picture below, you might have the Top Deck
version.
PAGE 10 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
In the image on the previous page there’s a green POWER LED on the left and a red MOTORS LED on the right.
The middle LED is orange and is connected to digital pin 13. There is a breadboard where you can put
electronic parts which we will learn more about in a future robotics session.
To upload your first program to the robot go to the <FILE> menu at the top of the Arduino IDE, scroll down to
the <EXAMPLES> option and then <BASICS> and finally select the program called <BLINK> which should look
like this:
EXAMPLE CODE to MAKE LED ON D13 FLASH ON AND OFF
//
// FLASH LED ON D13
//
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);---
}
void loop()
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Change the above code’sdelay” time (the numeric values you see are in milliseconds) and re-upload to the
Arduino PRIMO controller to see what happens. Remove the code from the loop and paste it into the setup
function to see what happens. Make sure the code is nested inside a set of curly brackets so you don’t get error
codes.
Watch some YouTube videos to learn more about the examples code in the Arduino IDE.
www.robotscience.co.za
www.youtube.com/mikerobotscience
www.youtube.com/electronicsafrica
PAGE 11 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 3 HOW DO CONTINUOUS ROTATION SERVOS WORK?
In mechatronics you will encounter many types of motors, and many other types of actuators, all of
which are used to create motion. The PRIMO desktop robot uses two continuous rotation servo
motors to give it the ability to move around very precisely controlled by program code like in the
image below:
The PRIMO robot doesn’t have a steering mechanism like in a regular car, but executes turns through
a system called ‘differential steering’ which is similar to the way a caterpillar army tank is controlled.
COPYRIGHT: SERVO MAGAZINE
When the wheel on one side of the PRIMO robot turns at a faster rate than the other side, then the
robot will pivot towards the side where the wheel is rotating slower. This system of control can
produce turns or pivots as per the image above. The servo motors on the PRIMO robot have three
wires, the black or brown wire is NEG or GND or 0 volts, the red wire is positive [+] or 5 volts or
power. The third wire is the control signal which is usually white or yellow. If one applies control
signals at specific frequencies to a servo, when connected to power the speed and direction of
rotation can be controlled quite precisely.
Continuous rotation servos on the robot accept HIGH pulses from 1000 microseconds to 2000
microseconds with an interval of 20,000 microseconds in between. High pulses of 1500
microseconds [1.5 milliseconds] will STOP a calibrated CR servo as per:
PAGE 12 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
Applying HIGH pulses of 1000 microseconds to the servo motors will make them turn full speed in
one direction, high pulses of 2000 microseconds will make a servo rotate at full speed in the other
direction according to standardised industry-wide hobby servo protocols.
COPYRIGHT: PARALLAX INC
You can also use whole number values between 1500-2000 and 1500-1000 for the high pulse
durations to set a range of speeds. In the above graphics we can see how applying 1300 microsecond
[1.3 ms] HIGH pulses makes the top servo rotate clockwise, applying 1700 microsecond [1.7 ms]
HIGH pulses makes the bottom CR servo rotate counter clockwise. The closer the value of the high
pulse duration to 1500 the slower the CR servo will run. If the servo ‘crawls’ when it receives high
pulses of 1500 then you need to calibrate the servo so that it stops completely. See the appendix.
CONTROLLING MOVEMENTS OF THE ROBOT
Because the servo motors are mounted on opposite sides of the PRIMO, in order to get the robot to
move forward both wheels need to turn the same way. The motors are mounted on opposite sides
of the robot, so to get both wheels to turn the same way one motor will in fact have to be counter-
rotating. If both motors receive the same HIGH pulse values the robot will pivot. Fold the illustration
above on the black line and you will see the wheels are actually rotating in the same direction on the
robot and it will therefore drive straight.
PAGE 13 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 4 PROGRAM PRIMO ROBOT TO MOVE FORWARD
In the previous section we understood the continuous rotation servo protocols, and how HIGH pulses control
the speed and direction of the wheels. The ball is at the back of the robot, and follows the driven wheels. If you
put the ball in front it tends to force the robot off course, which makes accurate and repeatable robot
movements hard to achieve.
If you notice slight creeping of the motors when applying 1500 microsecond stop pulses then your servo
motors may be out of calibration. How to re-calibrate the motors is covered in the Appendices.
The table show the values in the example program below, that you should upload to your robot and start
testing and experimenting to see for yourself the effect these numbers have on speed and direction.
ROTATION SERVO
rotates one way
stops the servo (if calibrated)
rotates the other way
TEST EXAMPLE CODE THAT SHOULD DRIVE THE ROBOT FORWARD FOR TWO SECONDS:
// text typed after two forward slashes are programmer’s comments
// the two forward slashes make the comments invisible to the compiler to prevent error codes
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left servo
Servo servoRight; // Declare right servo
void setup() // Built-in initialization code
{
servoLeft.attach(11); // Attach left signal to pin 11
servoRight.attach(10); // Attach right signal to pin 10
servoLeft.writeMicroseconds(1700); // DRIVE ROBOT – FWD LEFT
servoRight.writeMicroseconds(1300); // DRIVE ROBOT – FWD RIGHT
delay (2000); // continue for 2000 milliseconds [2 seconds]
servoLeft.writeMicroseconds(1500); // STOP motor
servoRight.writeMicroseconds(1500); // STOP motor
}
void loop()
{
// no code in the loop
}
Notice the HIGH pulse values in the code [writeMicroseconds(XXXXX)] that controls the servo motors speed
and direction. Try changing the values in the brackets (XXXXX) progressively from 1000 through 1500 to 2000
microseconds and observe the effect these changes have on the robot.
There’s a line of code at the top of the program you might have noticed [#include <Servo.h>] that serves the
purpose of setting up a process in the background to generate a continuous string of pulses that keeps the
motors running until another command changes or stops the pulses. After the lines of code that creates the
HIGH pulses for left and right motors, there’s another line of code [delay(XXXXX)] that allows the HIGH pulses
to continue for at least as long as the duration of the delay which in this instance is two 2 seconds.
PAGE 14 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
ARDUINO TWO WHEEL DIFFERENTIAL STEERING ROBOT WITH CONTINUOUS ROTATION SERVOS
If the robot reverses when you upload the drive forward program from the previous page into the PRIMO then
you need to swap the wires around, in other words the plug of the motor that is connected to D10 needs to
move to D11 and the plug of the motor that is connected to D10 needs to be connected to D11.
CONTINUOUS ROTATION SERVO MOTORS ARE CONNECTED TO D10 AND D11 OF THE ARDUINO
WARNING: Do not twist on the wheels of your robot as doing that can strip the gears.
OTHER TYPES OF SERVOS: 180 DEG POSITION HOBBY SERVOS
There are other types of servo motors. Position type servos that are used extensively in the model aircraft and
unmanned aerial vehicle [UAV] industry for control surfaces like ailerons and rudder. These types of servo
motors typically only move through 180 degrees and give precise control. Position servo motors can also be
controlled by an Arduino UNO but values are in degrees from 0 through 90 to 180 degrees where the code
might look like this:
positionServo.write(0);
positionServo.write(45);
positionServo.write(90);
positionServo.write(135);
positionServo.write(180);
PAGE 15 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 5 CONTROLLING PRIMO ROBOT: PIVOTS + TURNS
Once you have tested the code and understand how to move the robot forwards, its a good idea to learn how
to execute pivots + turns. If you can drive forward and turn left and right you will be able to navigate a course.
As mentioned before, to achieve accurate repeatable movements the ball should follow the driven wheels.
WARNING: Rapidly twisting the wheels of your robot will damage the gears.
PROGRAM 1: ROBOT DRIVES FORWARD, THEN TURNS:
// test drive the robot forwards, then turns
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servo
Servo servoRight; // Declare right servo
void setup() // Built-in initialization block
{
servoLeft.attach(11); // Attach left signal to pin 11
servoRight.attach(10); // Attach right signal to pin 10
servoLeft.writeMicroseconds(1700); // DRIVE ROBOT - FWD
servoRight.writeMicroseconds(1300);
delay (1000);
servoLeft.writeMicroseconds(1700); // DRIVING+TURNING THE ROBOT
servoRight.writeMicroseconds(1440);
delay (1000);
servoLeft.writeMicroseconds(1700); // DRIVE ROBOT - FWD
servoRight.writeMicroseconds(1300);
delay (1000);
servoLeft.writeMicroseconds(1700); // DRIVING+TURNING THE ROBOT
servoRight.writeMicroseconds(1440);
delay (1000);
servoLeft.detach();
servoRight.detach();
}
void loop()
{
}
PAGE 16 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
2: ROBOT DRIVES FORWARD, THEN EXECUTES A PIVOT MANOEUVRE:
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servo
Servo servoRight; // Declare right servo
void setup() // Built-in initialization block
{
servoLeft.attach(11); // Attach left signal to pin 11
servoRight.attach(10); // Attach right signal to pin 10
servoLeft.writeMicroseconds(1700); // DRIVE ROBOT - FWD
servoRight.writeMicroseconds(1300);
delay (1000);
servoLeft.writeMicroseconds(1700); // PIVOT THE ROBOT AFTER JUST OVER ONE SECOND
servoRight.writeMicroseconds(1700);
delay (1000);
servoLeft.writeMicroseconds(1700); // DRIVE ROBOT - FWD
servoRight.writeMicroseconds(1300);
delay (1000);
servoLeft.writeMicroseconds(1300); // PIVOT THE ROBOT AFTER JUST OVER ONE SECOND
servoRight.writeMicroseconds(1300);
delay (1000);
servoLeft.detach();
servoRight.detach();
}
void loop()
{
}
To control servo motors you can use degrees or microseconds in the Arduino code, but we recommend when
working with continuous rotation servos stick to microseconds values to get the best results.
This table should help you understand MICROSECONDS continuous rotation servo motor control:
writeMicroseconds(value)
ROTATION SERVO
value = (1300)
rotates one way
value = (1500)
stops the servo (if calibrated)
value = (1700)
rotates the other way
The reason why one motor needs to be run forwards and the other back is because they are mounted on
opposite sides of the robot, if you send both motors the same PULSOUT value the robot will pivot instead of
driving forward. Now it is your turn – see if you can make the robot drive a square and triangle.
www.robotscience.co.za
www.youtube.com/electronicsafrica
www.youtube.com/mikerobotscience
PAGE 17 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 6 ROBOTICS MAZE AND CHALLENGE RULES
1. The objective of the challenge is to evaluate the training and confirm newly acquired skills.
2. The challenge consists of a simple maze, into which the robots will drive autonomously.
3. The winner of the challenge is the robot that completes the maze first.
4. Alternately, the winner of the challenge will be the robot that drives deepest into the maze.
5. A team consists of a group of learners with one robot.
6. The competition will start at the designated time, which will be signalled by the whistle.
7. The competition will end at the designated time, when the whistle blows.
8. During practice teams will bring their robots to the competition table, and without delay place their
robot on the table and trigger the execution of the program once.
9. If a team wishes to re-test their robot [without going to their base to change and re-upload their
program] that team must go to the back of the line of teams waiting to test robots at the maze.
10. The objective of Rule 8 is to ensure all teams can access the maze without undue delay.
PAGE 18 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
11. During the competition the teams will bring their robots to the competition table, and without delay
place their robot on the table and trigger the execution of the program.
12. Each team will get one start, if things go wrong and that team decides not to go back to their base to
change their code that team must go to the back of the line of teams waiting at the maze.
NOTES:
PAGE 19 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: PART 7 ONE STRATEGY TO CONQUER THE CHALLENGE
Now you can move the robot forwards, and execute turns and pivots, its time to test your skills against the
maze challenge. There are many ways to conquer the maze, follow this method or try your own approach.
One method, that has proven effective for many teams that succeeded at this challenge, is to break your code
up into stages. Code the robot to drive forward just one fwd stage, and the first turn [Stage 2]. Upload the code
to the robot and take it to the maze and place it on the start markings. Place the robot in exactly the same
place every time you take it to the maze when testing your code. Start the robot. Observe the robot carefully.
When the robot stops after executing the first two stages it should be pointing to the next stage.
Add one more stage, then re-test the robot taking note of where it ends up. Calling out each stage of the
program code as the robot travels into the maze helps identify a stage that may require adjustment. Turns and
pivots are also stages...
Resist the temptation to add a whole bunch of stages in a hurry thinking that will save time and somehow you
will be able to unscramble the code. Yes, there is pressure because you’re competing against other robots, but
it is best to resist the temptation to simply dump a whole bunch of untested code into your robot. Rather add
one stage at a time, making sure each new stage is correct before adding the next. Below is an example of what
the starting code might look like, on the next page is an example of what the code might look like once more
stages have been added.
MAZE SOLUTION EXAMPLE CODE: STAGE 1…
#include <Servo.h>
Servo servoLeft;
Servo servoRight;
void setup()
{
servoLeft.attach(11);
servoRight.attach(10);
//---------[STAGE 0]-------------[2 SECOND DELAY TO GET YOU HAND CLEAR OF THE RESET BUTTON] -----------
delay (2000);
//----------[STAGE 1]------------[DRIVE FORWARD]-----------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1300);
delay (1111);
//----------[STAGE 2]------------[TURNING LEFT]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1440);
delay (1111);
//----------[FINAL STAGE]------------[STOP]-------------------------------------------------------------------------------------
servoLeft.detach();
servoRight.detach();
}
void loop()
{
}
PAGE 20 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
MAZE SOLUTION EXAMPLE CODE: STAGE 1, STAGE 2 [NOTE: THIS IS NOT A MAZE SOLUTION]
#include <Servo.h>
Servo servoLeft;
Servo servoRight;
void setup()
{
servoLeft.attach(11);
servoRight.attach(10);
//---------[STAGE 0]-------------[2 SECOND DELAY TO GET YOU HAND CLEAR OF THE RESET BUTTON] -----------
delay (2000);
//----------[STAGE 1]------------[DRIVE FORWARD]-----------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1300);
delay (1111);
//----------[STAGE 2]------------[TURNING LEFT]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1440);
delay (1111);
//----------[STAGE 3]------------[ DRIVE FORWARD]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1300);
delay (1111);
//----------[STAGE 4]------------[TURNING LEFT]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1440);
delay (1111);
//----------[STAGE 5]------------[ DRIVE FORWARD]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1300);
delay (1111);
//----------[STAGE 6]------------[TURNING RIGHT]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1440);
servoRight.writeMicroseconds(1700);
delay (1111);
//----------[STAGE 7]------------[ DRIVE FORWARD]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1300);
delay (1111);
//----------[STAGE 8]------------[TURNING LEFT]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1440);
delay (1111);
//----------[STAGE 9]------------[ DRIVE FORWARD]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1440);
delay (1111);
//----------[STAGE 10]------------[TURNING RIGHT]---------------------------------------------------------------------------------
servoLeft.writeMicroseconds(1400);
servoRight.writeMicroseconds(1700);
delay (1111);
//----------[FINAL STAGE 2]------------[STOP]-------------------------------------------------------------------------------------
servoLeft.detach();
servoRight.detach();
}
void loop()
{
}
You should now have the skills required to tackle solving the challenge – Best Luck!
PAGE 21 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
1 DAY OF ROBOTICS: APPENDIX 1: CONTINUOUS ROTATION SERVO CALIBRATION
Robot motors can be many shapes, sizes and types. We use continuous rotation hobby type servo motors
because they offer precise control at an affordable price, and they are easy to program using an industry-wide
standard set of protocols. Continuous rotation [CR] servos are slightly different to most hobby servos in that
they move beyond the 180 degree physical limit of normal ‘position’ type hobby servos.
Continuous rotation servos can drive wheels forward [and in reverse] precisely according to signals from the
controller. You can set the speed and direction of rotation, you can stop a continuous rotation servo after a
precise duration, you can also apply ‘braking force’ by stopping a CR servo. CR servos can be used to drive a
small robot through a competition maze, and perform many tasks far more precisely than simple DC motors.
Some CR servos do not need to be calibrated, and therefore don’t have an adjustment access hole. If you have
the type with a small hole, inside of which there’s a tiny variable resistor, then you will need to send the servo
1500 microsecond pulses while adjusting the servo with a wooden toothpick until it stops completely. Be very
careful not to use force, and use only a toothpick, or you could damage the servo.
ADJUST TRIMER POTENTIOMETER IN CONTINUOUS ROTATION SERVO WITH TOOTHPICK:
Continuous rotation servos are controlled by electronic pulses. The stop value [midpoint between forwards and
backwards rotation] is achieved by sending 1500 microseconds high pulses with 20 milliseconds low pauses
between each pulse. The Arduino software takes care of generating pulses in the background, all you need to
do is send the correct pulses with a few lines of code as shown on the next page.
If a PRIMO robot behaves unpredictably first check the (1) batteries then (2) check the continuous rotation
servos are properly calibrated. To calibrate a CR servo connect it to power and a controller and then insert a
fine toothpick into the adjustment variable resistor [accessed through the hole in the casing] taking great care
not to use excess force to prevent damage to the internal parts of the servo, which will render it useless. Insert
the toothpick gently into the variable resistor without force, so when you remove the toothpick it comes out
easily. If the toothpick gets stuck hard into the servo when you remove it the setting will be lost.
PAGE 22 | ROBOTICS 101: ONE DAY © 2 0 2 2 M I C H A E L E T T E R S H A N K
https://www.robotscience.co.za
With the program below running in the ARDUINO PRIMO ROBOT controller adjust the trim pot slowly until
[around the midpoint] the motor stops turning completely. The motor should not run at all, it should not creep
slowly, or vibrate or hum. Remove the toothpick carefully taking care not to disturb the setting. Repeat this
procedure until the servo stops completely with the toothpick out:
// save time – do not type out the comments behind the // fwd slashes
// left side of the robot is your left – imagine you’re a tiny person sitting on the robot and driving it forward [ball at back]
// the ball is always at the back of the robot, the drive wheels are at the front or it will not track straight…
// the left servo is connected on D11
// the right servo is connected on D10
#include <Servo.h> // include servo library
Servo leftServo; // create servo object to control left servo
Servo rightServo; // create servo object to control right servo
void setup() {
leftServo.attach(11); // attaches the leftServo to digital pin 11
rightServo.attach(10); // attaches the rightServo to digital pin 10
}
void loop() {
leftServo.writeMicroseconds(1500); // stop value to use while calibrating servo
rightServo.writeMicroseconds(1500); // stop value to use while calibrating servo
}
Once the servos are properly calibrated the table below should work perfectly in terms of sending control pulse
values in MICROSECONDS to the continuous rotation servo motors on the PRIMO robot:
writeMicroseconds(value)
ROTATION SERVO
value = (1000)
rotates one way
value = (1250)
rotates one way … half speed
value = (1500)
stops the servo (if properly calibrated)
value = (1750)
rotates the other way … half speed
value = (2000)
rotates the other way
In the above table you will see full speed the one way is 1000 microseconds and 2000 microseconds is full
speed the other. There are also steps in between, where you can vary the speed. This varies from brand to
brand like FiTech and Futaba servos, etc, so some experimentation can be required to get the best results.
WARNING: When you adjust a continuous rotation servo you can break the trimmer (variable resistor) that is
accessed through the hole in the body of the servo – use great care and adjust slowly to find the stop position.
Because there is a risk of damaging the servos by calibrating them manually with a fine screwdriver, we have
discovered that adjusting them with a toothpick is a much safer option.
WARNING: You can use a multimeter to check each battery on the Primo robot
where each cell should read above 4v per cell. Never leave batteries
unattended while charging. Read and sign the battery safety guideline.