Introduction: How to Draw Pictures and Create Fonts Using the Doodle Bot Sample Code

If you are reading this before 31st of July, 2013 then there is a contest with prizes running. See here for details.

Doodle Bot is a simple robotic platform that is ideal for hobbyist and students learning the basics of robot locomotion. The robot has 2 geared motors for locomotion and 1 servo to raise or lower the pen.  The robots only sensors are two simple wheel encoders that can be used to measure distance and / or speed. Doodle Bot's brain is a small, low cost, Arduino compatible controller with USB interface, servo headers and motor drivers all built in.

This tutorial will show you how to use the supplied sample code to create custom text, symbols and draw relatively complex artwork using only 4 commands.

Step 1: Sample Code Commands

The sample code allows the user to easily write messages in English however the robot can do a lot more than write messages. If you look in the tab [Alphabet] you will see that each letter of the alphabet is drawn using 4 simple command functions:

· Go(x)            
· Turn(angle)  
· Up()               
· Down()         


Go(x):x is an integer that specifies the number of steps the robot should take. As the wheel encoders change state 8 times (4 high and 4 low) per wheel revolution each step is equal to 1/8 of the wheel circumference. This is equal to approximately 15.7mm.

The variable charsize is used as a multiplier and by default has a value of 1. If you change it for example so that charsize=3 then the message / image will be 3 times bigger and each step will be approximately 47.1mm.

Turn(angle): angle is an integer that specifies the turning angle. All positive values cause the robot to turn clockwise. A negative value will cause the robot to turn anti-clockwise. This command is more complicated to use because there are two different ways the robot can turn.

Turning method 1: The first method stops one motor and drives the other motor forward or backward. This method provides the greatest number of possible angles but because the robot pivots about 1 wheel it is more difficult to align the pen with its previous position.

Turning method 2: The second method drives one motor forward and one motor backward. This method provides half as many angles but because the robot pivots about the centre of the wheels it is easier to align the pen with its previous position.

The sample code uses the first method for angle values from –31 to +31. This makes all possible angles available. These angles are shown in blue.

Positive or negative values from 32 to 40 cause the robot to turn using the second method as shown in red.

If you look at the sample code you will see that you can also enter values 45, 90,135,180, 225, 270, 315 and 360. The code automatically converts these values to their equivalent value using the second method of turning.

The sample code automatically compensates for the pen not being mounted directly between the wheels and remembers if the pen was up or down at the time a turn was being made.

Up(): This command raises the pen.

Down(): This command lowers the pen.

The sample code does include a Stop() function however this command is not needed for drawing and is only used within the Turn(angle) and Go(x) commands to ensure encoder accuracy.

There is also an End() function that puts the robot into a continuous loop where it does nothing until the reset button is pressed. This can be used at the end of the text or picture to stop the robot from repeating the loop() function.

Step 2: Create New Fonts and Symbols

To create new characters, fonts or symbols for Doodle Bot to draw you must first draw them on a grid. This will give you a map to work with and help you ensure all characters are the same size. As you can see in the first picture, all the numbers and letters included in the sample code were first drawn in a grid.

The instructions for each character assume that the robot is starting in the bottom left corner of the grid facing to the right. When you create a new character you must make sure you include instructions that leave the robot in this position ready to write the next character.

If you look here at the code for the letter “A” and compare it to the character map above you will see that after drawing the letter the robot raises the pen, goes to the bottom of the character and then goes right 6 steps.

It only had to go right 4 steps to finish in the lower right corner of the character but it went an additional 2 steps to create a gap between the letter A it had just drawn and the next character to be drawn.

You can make your grid any size you want. For example, if you want to create a font with more detail in each letter or write a language using more complex characters such as an Asian language then you might use a 15 x 15 grid for each character.

Step 3: Drawing Pictures With Doodle Bot

This can be done the same way as we draw numbers and letters. First we need to create our map using 3 basic steps.

Step 1: Find a suitable picture. Remember the more complex the picture the bigger your grid must be and the more difficult it will be to teach the robot to draw it.

Step 2: Using your favourite art program (or tracing paper, pencil and ruler if you printed the image) place a grid on top of the image. Trace over the image to generate the lines you want the robot to draw.

Step 3: Remove the original image and check how your drawing should look. At this point you may want to make some changes before you start writing the code.

Step 4: Multi-colour Images

Although the robot can only draw one colour at a time it is possible to break your drawing down into different colours and manually change the pen between each segment.

The simplest way to implement this is to break your code into different segments for each colour and have a time delay of 30 seconds between each segment of code. This gives you plenty of time to pick up the robot, change pens and put the robot back in the correct position before the robot starts drawing again.

In this example I would draw the black outline first as it then offers many starting points for the other colours to begin drawing from.

Step 5: Converting Your Map to Code

Once you have your map, you must convert it to code for the Doodle Bot to follow. If you are doing a fairly complex image such as the example picture of R2D2 then it is easy to loose track of the robots position and orientation as you write the code. It may be easier to print the map and use a small printed arrow to keep track of the position and angle of the robot as you write each command.

Choose a starting point: In the sample code, the bottom left corner was always assumed to be the starting point for any character but if you are drawing a picture then you can choose any point in the image. If the robot is working on a confined area such as a large piece of paper or a whiteboard then it may be easier to start in the centre so that you have as much room as possible in all direction.

In my example I will start with the black outline at the top. The green line shows the path I want the robot to follow. To get the robot to follow this path my code would be:

Down(); Go(1); Turn(45); Go(1); Turn(90); Go(1); Turn(90); Go(1); Turn(90); Go(1); Turn(45); Go(1);

At this point it should be noted that each square in the grid is one step wide and one step high. So if Doodle Bot was to draw the 45° lines accurately it would really need to travel a distance of approximately 1.4 steps (the hypotenuse of a triangle where each of the other sides =1). As the robot cannot travel 1.4 steps, the diamond shaped eye at the top of the robots head will be a bit smaller than shown on the map.

In this case the inaccurate distances of the 4 sides cancel out and Doodle Bot finishes this section of the code in the correct place. When it comes time to draw the rest of the head, which has several lines at various angles, then some adjustments will need to be made to compensate.

Step 6: Choosing the Nearest Angle

Although Doodle Bot cannot turn to any angle, we can choose the nearest angle. In many cases this will work well. Below is a table showing the different angles and distances you will get on your grid and the nearest angle and distance the robot can turn at and travel.
 
Ratio Angle Distance Nearest Nearest Turn
      Angle Distance Value
N:1 ≈90 ≈N 90 N 36
6:1 80.5 6.1 78.8 6 7
5:1 78.7 5.1 78.8 5 7
4:1 75.9 4.1 78.8 4 7
3:1 71.5 3.2 67.5 3 35
2:1 63.4 2.2 56.3 2 5
3:2 56.3 3.6 56.3 4 5
1:1 45.0 1.4 45.0 1 34
2:3 33.7 3.6 33.8 4 3
1:2 26.6 2.2 33.8 2 3
1:3 18.4 3.2 22.5 3 33
1:4 14.0 4.1 11.3 4 1
1:5 11.3 5.1 11.3 5 1
1:6 9.4 6.1 11.3 6 1
1:N ≈0 ≈N 0 N 0
 
The ratio is the vertical distance divided by the horizontal distance and the angle is calculated using the ATAN function. If you are using a scientific calculator then this is usually achieved by pressing [inv] or [2nd] followed by the [Tan] button.
 
The distance is the hypotenuse of the triangle. The turn values shown use the second method where possible for best accuracy.
This tutorial has only shown one method of drawing pictures. By writing your own code, many other options are possible.

Good luck and enjoy!

Comments

author
Alejandro de Montecristo made it! (author)2014-12-10

hi i whant use the code whith the robot controller micro magician V2 but the code samples not load and have problems whith arduino V1 or superior but the robot magician V2 not connect whith arduno 22 or 23 which load the code, please you can help me please

Captura de pantalla 2014-12-10 a la(s) 15.22.45.jpg

About This Instructable

5,496views

18favorites

License:

Bio: I have been building electronic circuits and programming since I was twelve. I am an Australian but now I'm living in China where I ... More »
More by OddBot:Tic-Tac-Toe RobotHow to draw pictures and create fonts using the Doodle Bot sample codeBuilding a Doodle Bot kit from DAGU
Add instructable to: