Introduction
Did you ever think that you could draw through coding ..! Well this is what you will do in this tutorial using IdeaBot's drawing attachment. We have designed the body to be compact, small and capable of doing a lot of tasks and projects easily.
Who says that science and art doesn't meet, we will learn how to convert coding and math to drawings and art.
Don't forget to draw on a surface that can be erased like the white board, a white acrylic sheet or any smooth erasable surface..!
Enjoy coding and drawing :)
Assembly
Before IdeaBot can become a calligrapher, you must first assemble the scriber attachment. For instructions watch the assembly video or follow the detailed instructions below.
1: Locate the scriber hole at the back of the robot.
2: Locate 4 M3x20 mm standoffs and 4 M3 mm nuts.
3: Tighten the standoffs and nuts.
4: Locate the marker holder.
5: Align the marker holder with the standoffs, and locate 4 M3x8 bolts.
6: Tighten the bolts into the standoffs.
HowtoDraw Rules
Driving in a straight line was covered in Project 1, and the exact same method of driving will be used here. However to draw intricate shapes it is necessary to study turning in a bit more detail which we will discuss in this tutorial.
Before digging deep into the rotational movements, the marker hole is centered in the middle between the two motors and also it is crossing the shaft line of the motors. meaning that if the robot rotates on itself the marker will not move.
There are some basic rules of drawing:
1 if you want to draw a straight line, move two wheels in the same speed and direction.
2 if you want to draw geometries with angles, always use case 1 method mentioned below.
3 if you want to draw arcs, circles or spirals, use case 2 and case 3 methods mentioned below.
The robot will go in a circle if each wheel has a different speed. And a straight line, if both wheels has the same speed.
Circular Motion
There are 3 cases for circular motion:
Case 1: One wheel forward the other backwards
In this case, the rotation point (also called the center of zero velocity because it does not move) is between the two wheels. If the 2 wheels rotate at exactly the same speed but in opposite directions, the rotation point will be exactly at the center of the robot, where the marker tip is located. This will result in a circle of zero radius, a point. This was the type of turn explained in Project 1. If the rotational speed of 1 wheel is slowed down, the rotation point will start to move towards that tire and the marker will draw a small circular arc.
Rotating on its shaft, the marker will not move and it will be a point only.
the following code does the same as the GIF picture above:
#include <Servo.h>

Case 2: One wheel rotates forward, the other backwards but at a slower speed
When one wheel is rotating forwards and the other backwards, but the rotational speed is different the robot will draw a circle of radius less than half the robots width, as the wheel rotating backwards is slowed down, the radius of the circle will increase, when that wheel stops the radius of the circle will be equal to half the robots width.
Rotating about a point inside the robot but not the center, draws a small circle.
The code below will give the same movement as the gif above:
#include <Servo.h>

Case 3: One wheel fixed, other rotates
If one wheel is slowed down until it stops, that wheel will become the point of rotation and the robot will draw a circle with a radius equal to half the robots width.
Moving with one tire only, the other tire is the center of rotation
The following code does the same as the GIF picture above:
#include <Servo.h>

Case 4: Both wheels rotate forward, one slower than the other
If both wheels rotate forward, but one is slower than the other, the robot will will rotate about a point outside of the robot, and the radius will be bigger than half the robots width. As the slower wheel is speed up, the radius of rotation will increase.
Rotating around a point outside idea bot chassis, radius increases if speed increases.
If the slower wheel is sped up until both wheels have exactly the same speed, the robot will drive in a straight line. This can be considered turning in a circle of infinite radius.
The following code does the same as the GIF picture above:
#include <Servo.h>

Moving Specific Distance !
At this point you might be wondering how to turn a specific angle or drive a specific distance. Since IdeaBot's servos do not have any feedback loop meaning that you cannot know the current position, the only way to do this is by time.
Programming the robot to turn and then waiting a specified time will enable you to turn IdeaBot a set angle, and programming IdeaBot to drive and then waiting a set time will enable you drive IdeaBot a set distance.
The times needed for delay must be found by calibrating and a bit of trial and error. this is shown in more detail in the Lets Draw Section below.
NOTE: A more accurate method would be to use an encoder to count the number of turns each tire makes and from that... accurate distances and angles can be calculated.
Lets Draw!
Now let us get use of the functions approach and draw something ! Start with something easy like a square or a rectangle ...
So now how can we draw a rectangle, well it is easy to think about it. We make the robot move straight then take a 90 degrees turn then move straight then turn and so on until the square/rectangle is drawn.
In order to do that it is better to create a function with a distance input then convert it to time to drive the motors
Here we declared a function called drive, and the input is integer called d which stands for a distance in cm.void drive(int d) {
int t = d*36.6; // conversion from distance to time
}
Then the conversion equation is t = d *36.6; that converts the distance in cm to the time needed to reach that distance... the question is how and why 36.6 coefficient ?
The answer is so simple .. trial and error.! What we did here is we made the robot move 1 cm only and we estimated the time of 1 cm which turns out to be 36.6 milliseconds approximately.
But keep in mind that this number is continuously changing since the battery level drops with time and motor speed is totally dependent on battery level.
To make the function more flexible, we considered moving in both direction so you can write drive(20) or drive(20) which makes the robot capable of moving in both directions. you will see in the code below the details of doing that.
Now to turn fixed angles use the same approach, create a function called turn(int theta) where the input is angle value in degrees
void turn(int theta)
{
int t = 36.6 * 10 * theta/180*3.1415;}
The same conversion here is used based on trial and error approximation we found that 36.6 * 10 is the turn coefficient, you can change it to reach the right values.
The term theta/180*3.1415 is the conversion from degrees to radians to have units consistency.
Drawing a square
Drawing a square using drive & turn functions
NOTE: Keep in mind that the function is totally time dependent so it needs some trial and error efforts to convert time to distance and the battery level affect that directly.
#include <Servo.h> drive(20); turn(90); drive(10); turn(90);
if(t >= 0) // if distance is positive move forward direction

Drawing spiral shape
Drawing a spiral shape is much easier in coding, the main concept is that the robot should move in a circle but one tire must increase its speed gradually from zero to slower speed compared to the other tire to stay circularspiral movement.
So the secret is increasing the speed of the idle motor slowly as if we are shifting from case 2 to case 3...
Spiral movement, gradual speed increase of left motor.
To do that easily we will introduce a smart simple way in coding called increment operator basically it adds a value of 1 or any specified value to an integer or any other storage types.
it is written in the following way:
int x;
x++;
x++ means exactly the following x = x + 1 ,,, look at the code of spiral below to understand the use of it.
The following code does the spiral move in the GIF above:
#include <Servo.h> // put your main code here, to run repeatedly:

Keep in mind that the code above and all codes in our tutorials are very simple and you can do much more complex codes to do complex tasks, so you can draw a better looking spiral. actually we drew a very compact spiral with many circles inside it by making both motors move at first in opposite directions with different speeds.
You can always innovate and draw your own shapes, it all depends on your imagination in coding and art.
Challenge
Try to program IdeaBot to write IdeaBot as shown in the introduction video. Send your codes and a video of them in action and we may post them on our website. If you run into difficulty email us and we will send you the code used in the video.
Hint : make for each letter a separate function and use the drive turn functions, don't forget to charge your battery or replace with new ones and finally change the coefficients to meet your settings, good luck :)