At-Bot E120703 Small
At-Bot E120703 Small
At-Bot E120703 Small
AT-BOT
The 4-wheel autonomous robot
programmed with C/C++ language
Activity book
Details and illustrations used in this handbook are thoroughly and carefully to provide
the most accurate and comprehensive information under the conditions and time we
have before publishing. Innovative Experiment Co.,Ltd. shall not be responsible for
any damages whatsoever resulting from the information of this book as constant
revisions and updates will be published after this edition.
Table of contents
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
AT-BOT movement........................................................79
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 1
AT-BOT : The 4-wheel autonomous robot
AT-BOT (All-Terrain mobile robot) is an autonomous robot performed by DC motors
with the set of 4 DC motor gearboxes come with spiked wheels in order to aid passing
through rough surface more efficiently. Also, it can move up on the slope in the level of 0
to 25 degree and if it is necessary to stop immediately to change the direction of motion,
it can do. The possibility is that AT-BOT is capable of supporting any mission in either a
smooth competition court with lines appeared for determining directions of motion or
rough court with barriers or participating with the World RoboCup Junior-Rescue.
Digial Converter, 128-KByte Flash memory , 4-KByte EEPROM, 4-KByte RAM. Operated with
16MHz clock from external crystal
Define all ports compatible with Wiring I/O standard hardware (www
port 14 and 15), A/D port (7 : port 40/ADC0 to port 46/ADC6), Two-wire interface or TWI (2
: port 0/SDA and port 1/SCL) and UART serial port communication (2 : port 2/RX1 and port
3/TX1). Both TWI and UART ports can config to digital input/output port for more I/O
applications.
Analog input (ADC0 to ADC6) supports 0 to +5Vdc input. The converter
One variable resistor is connected with the Analog input ADC7 of main
the Wiring I/O controller board for simple digital input experiment.
One LED with a current limited resistor. It is connected with port 48
One piezo speaker at port 4
16x2 characters LCD for monitoring
On-board digital compass; HMC6352 from Honeywell. It is interfaced by I2C
bus or TWI
UART port for interfacing serial module device such as camera module (ZX-
CCD, CMUCAM1, CMUCAM2, mCAM), servo controller board (Parallax servo controller,
ZX-SERVO16U), Real-time clock (ZX-17 : serial real-time clock moduel)
6-ch DC motor driver with indicators. Support 4.5V to 9V DC motor. Maximum
motor types.
Motor driver power indicator; nomally turned on. It will off when motor is short-circuit.
42 ADC2
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
43 ADC3
START
c o n t r o l l er R b o a r d
USB DATA
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
SW1
49
SW2
50
48
ADC7
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
KNOB
RESET
7.2-9V BATT.
14
PC6
15 PC7
MOTOR
- Last left yellow LED displays that the input supply voltage is 6.75V. When the
battery voltage is lower than 6.75V, this LED will start to blink.
- Next yellow LED displays the input supply voltage at 7.0V.
- First green LED displays the input supply voltage at 7.25V.
- Second green LED displays the input supply voltage 7.5V.
- Last right green LED displays that the input supply voltage is higher than at 7.75V.
Download and interface with computer via USB port by using USB to UART
+6Vdc for all motor driver circuits. By using voltage regulator; the motor driver circuit can
drives DC motor with constant speed when battery voltage is full and reduce to 60%. It
features constant speed without effect by battery voltage until it is lower 60% of full.
(A)
(B)
(C)
LED1
+V
R2
10k
R1
510
S1
Switch
R3
220
DATA
GND
Figure 1-4 : The touch sensor or Switch input board picture and
schematic diagram
Output port
LED
LED1
+V
OUT
SFH310
GND
10k
220
Infrared Receiver
2.8
2.4
2.0
GP2D120
1.6
1.2
Vout GND
Vcc
0.8
0.4
Supply
0
38.39.6 ms
12
16
20
24
28
32
Distance (cm)
Measurement
Vout
1st measure
2nd measure
Not stable
1st output
n measure
2nd output
n output
5 ms
Object
L F
A X
F
Transmit LED
GP2D120
Therefore, L equals
Photo array
FA
X
2mm. pitch
GND
S
+5V
2mm. pitch
GND
S/Data
+5V
Chapter 2
AT-BOT Development tools
Robo-Creator robot kit supports the operation controller program which can be
developed from Assembly, BASIC or C programming languages. For here, we will use
C/C++ programming language with the open-source software called Wiring, which is
the name of a development project of a small control system in order to apply the
software and hardware together.
We focus on concrete utilization as well as the connection of devices with
electronic system so that the system can work according to the statement written
correctly, collectively, Physical computing or the computer system which concentrates
on physical signal connection, connecting external sensor devices or controlling display
of LEDs, light, and sound, etc.
The official website of Wiring here is www.wiring.org.co. At this website, there is
data of both hardware and software allowed to download with free of charge. Also, it
is the open-source project to give an opportunity to developers who will be able to join
the project and expand the project freely.
The founder of Wiring is Hernando Barragan (Architecture and Design School,
Universidad de Los Andes, Comlumbia). Wiring started at the Interaction Design Institute
Ivrea in Italy and it is currently developed at the Universidad de Los Andes, Architecture
and Design School in Colombia.
through USB port in Wiring IDE software. There is a connection point to recieve signals
from both analog and digital external sensors that allows the board to acquire information
from the surrounding environment (temperature, light, distance to an object etc.).
Moreover, there is another point to send signals out to control external devices, such
as LEDs, loudspeakers, servo motors, and liquid crystal display or LCD, etc.
Robo-Creator robot kit provides the hardware of controller board compatible
with Wiring hardware and the system of Wiring IDE so you will be able to develop the
program comfortably.
(2) Next, click to agree in each step of the setup as installation of other applications
of Windows until completion.
(3) Installing the Wiring 1.0 software by using the CD rom is bundled with RoboCreator robotic kit is the setup of both Wiring 1.0 software and USB driver to connect
with ATX controller board in the same time.
(4) Test to start the program by select START > All Programs > Wiring. Then for a few
moment, the window of Wiring IDE will be present.
After That you can use the Wiring IDE in the program development for AT-BOT
robots.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
> o R u n n i n g. . . o a r d
2
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
SW1
49
SERVO PORT
9
SW2
50
48
BATTERY LEVEL
10 11 12 13
S
Turn on power
ADC7
RESET
7.2-9V BATT.
14
PC6
15 PC7
MOTOR
Figure 2-1 : The steps of preparation for checking USB serial port
positions of AT-BOT robot
(5) Check the hardware listing at Port. You should see USB Serial port . Check the
position. Normally it is COM3 or higher (for example; COM10). You must use this COM
port with the Wiring IDE software.
(3) Select menu Tools > Serial Port to choose the USB serial port of AT-BOT. It is
COM4 (for example).
Must do this step for every new connection of the AT-BOT with Wiring IDE
Now the AT-BOT is ready for interfacing and code development with the Wiring
IDE.
Chapter 3
Wiring IDE introduction
This chapter presents preliminary information of Wiring, which is the software tool
for developing the operation of AT-BOT robots or one of the activities to build robots in
Robo-Creator kit. For the details of program structure of C/C++ language Wiring supports,
you can read in the Wiring IDE help.
3.1.1.1 File
New (Ctrl+N) : Create new files. This is called sketch in Wiring and given name
following the recent date in the format sketch_YYMMDDa, such as sketch_080407a or
click the button
Open (Ctrl+O) : Open the exist sketch file or click on the button
Save as(Ctrl+Shift+O) : Save the open sketch file in the new name and the old
file will not disappear.
Upload to Wiring hardware (Ctrl+U) : Exports the program to the Wiring I/O Board
(inthis document is the ATX controller board). After the files are exported, the directory
containing the exported files is opened. There is more information about uploading
below. It works in the same way as click the button on
3.1.1.2 Edit
The menu contains commands used to edit the sketch file that develops on the
Wiring IDE.
Undo (Ctrl+Z) : cancel the previous action of a command or the lastest typing.
You can cancel Undo command by click Edit > Redo.
Redo (Ctrl+Y) : To return to make a statement made before the Undo command
is available only when done Undo already.
Cut (Ctrl+X) : Delete and copy the selected text to store at the clipboard, which
functions as the temporary memory unit to preserve information.
Paste (Ctrl+V) : Place the data in the clipboard on the desired position or replace
the selected text.
Select All (Ctrl+A) : Select all letters or text in the open file in the text editor at that
time.
Find (Ctrl+F) : Search for any text in the open file in the text editor. In addition, it is
also able to find and replace another text.
Find Next (Ctrl+G) : Find text or words we use to search for the next one within
the open file in the text editor.
3.1.1.3 Sketch
Sketch menu is a command menu relating to compile a sketch file.
3.1.1.4 Tools
Tools menu is a command menu relating to selection of tools helped to develop
a program. Important commands you should know are as follows.
3.1.1.5 Help
Getting Started : Open the window about the using Wiring of the Wiring website.
Examples : Open a sketch file of an example program.
Reference : Open Reference window of the Wiring website. It consists of
language, programming environment, libraries, and language comparison. You have
to connect with the internet if you would like to see the information.
Find in Reference (Ctrl+Shift+F) : Choose text in your program code. Here you will
drag black bar and click on it. The program will take the text you have chosen to find in
reference and if it cannot find anything, there will be a warning message in the window
of the program.
Wiring Hardware : Browse the information of Wiring I/O hardware via internet.
Troubleshooting : Open the window about solutions in performance of the Wiring
of the Wiring website.
Visit wiring.org.co (Ctrl+5) : Open the web browser to visit the homepage of
Wiring at http://wiring.org.co.
About Wiring : Show the copyright on the Wiring software
3.1.2 Toolbar
There are six buttons of basic functions and initial operation as follows.
Run or Compile : This button is used to compile the program code.
New : This button is used to create a sketch file.
Open : Open the exist sketch file
Save : Save the open sketch file in the old name. If would like to
change filename, use Save As command instead.
This program is used to test a basic hardware of AT-BOT robot. At the LCD display
shows message Hell Robot ! and blink the LED at port 48 of the ATX controller board with
one second rate.
(4) Go to the File menu to choose the Save as command to save the file in the
name of Test. Now, there is test.pde file happening in the folder called test.
(5) Verify the sketch by click onthe Run button of choose from menu Sketch >
Compile/Verify
If all are correct, the message area will display Done compiling message.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
> o B o o t l o ad e r o a r d
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
SW1
49
SERVO PORT
8
SW2
50
48
LED at port 48 is on
for programming mode
BATTERY LEVEL
10 11 12 13
+
7.2-9V BATT.
Turn-on power
ADC7
KNOB
RESET
14
PC6
15
PC7
MOTOR
until uploading complete. The message Done uploading. RESET to start the new program.
is shown in the status bar of Wiring IDE.
This mostly occurs if the serial port is invalid or not selected the board to
work in the program mode. Correction can be read in the topic of Troubleshooting of
uploading error.
(9) Press on the START button on the ATX control board to start the operation of
the program.
At the display of ATX board; it shows message Hello Robot! and the LED at
the port 48 lights up.
(2) Wiring IDE program will resume in a normal status and supply power to the
board again. Select the correct COM port and then set the ATX board to the
programming mode in order to upload the program again.
Cause :
Wiring software cannot connect with ATX control board or AT-BOT robot because
selecting a COM port is not correct.
Solution :
You need to choose an another COM port used for the connection again and
correctly by doing at the Tools > Serial port.
Chapter 4
ATX Library file
Developing C/C++ programming language with Wiring for AT-BOT robots is managed
under the support of atx.h library file in order to reduce steps and complexity in programming
to control parts of the hardware because it is required to give the priority for the program
development controlling AT-BOT robots to programming to support competitions.
The structure of atx.h library file shown as the diagram and details of all sub files are
consisted of as follows.
Operation
%c or %C
Display 1 character
%d or %D
%l or %L
%f or %F
#c
#n
Example 4-1
lcd(Hello LCD);
Result :
H e l l o o L C D rb o a r d r
W i r i n g I / Ob R o b o t d
Example 4-2
lcd(abcdefghijklmnopqrstuvwxyz);
// Display string. If over 16 charactes, the next character will
// show on the second line automatically.
Result :
abcdefghijklmnop
q r s t u v w x yz R o b o t d
Example 4-3
lcd(Value: %d unit ,518); // Display message with number date (518)
Result :
Value:g518kunitp
q r s t u v w x yz R o b o t d
Example 4-4
lcd(Value: %d ,analog(4));
// Display analog value from analog port 4 (PA4)
Result :
Value:gxxxkunitp
q r s t u v w x yz R o b o t d
Example 4-5
char c_test=j;
lcd(abcd%cxyz,c_test);
// Display character j with any message
Result :
abcdjxyzxxkunitp
q r s t u v w x yz R o b o t d
Example 4-6
lcd(Value: %f ,125.450);
// Display message with floating number 3 digit
Result :
Value:g125.450tp
q r s t u v w x yz R o b o t d
Example 4-7
lcd(count1: %d #ncount2: %d,12,48);
// Display message with 2 control code and special key #n
// for moving all message after #n to line 2 or bottom line of
// LCD screen
Result
count1:112.450tp
c o u n t 2 : x 48 R o b o t d
// Dealy 20 miliisecond
// Delay 1 second
4.3.1 in
Read data from the specific digital port
Syntax
char in(x)
Parameter
x - Choose digital port number. it is 0 to 50
Return value
0 or 1
Example 4-9
char x;
x = in(49);
Example 4-10
char x;
x = in(50);
4.3.2 out
Write or send the data to the specific digital port
Syntax
Example 4-11
out(43,1);
out(45,0);
4.3.3 sw1_press
This function loops to check the SW1 pressing. It returns value after switch is released.
Syntax
void sw1_press()
Example 4-12
................
sw1_press();
................
4.3.4 sw2_press
This function loops to check the SW2 pressing. It returns value after switch is released.
Syntax
void
sw2_press()
Example 4-13
..................
Sw2_press(); // Wait until the SW2 is pressed and released
.................
4.3.5 sw1
This function check the SW1 pressing in any time.
Syntax
char
sw1()
Return value
0 - SW1 is pressed
1 - SW1 is not pressed
Example 4-14
char x;
x = sw1();
4.3.6 sw2
This function check the SW2 pressing in any time.
Syntax
char
sw2()
Return value
0 - SW2 is pressed
1 - SW2 is not pressed
Example 4-15
char x;
x = sw2();
4.4.1 analog
This gets digital data from the analog to digital converter module of any analog
port; ADC0 to ADC7.
Syntax
4.4.2 knob
This function gets data from ADC7 port. This port isconnected with variable resistor
on-board. It is called KNOB.
Syntax
Example 4-16
int val=0;
val
= analog(2);
Example 4-17
int val=0;
val
= knob();
4.5.1 motor
It is DC motor driving function.
Syntax
Example 4-18
motor(1,60);
motor(1,-60);
direction.
Example 4-19
motor(2,100);
4.5.2 motor_stop
This function is driving off a motor or stop.
Syntax
Example 4-20
motor_stop(1);
motor_stop(4);
Example 4-21
motor_stop(ALL);
Syntax
void servo(unsigned char _ch, int _pos)
Parameter
_ch - Servo motor output (8 to 13)
_pos - Set the sevo motor shaft poistion (0 to 180 and -1)
If set to -1, disable selected servo motor output
4.7.1 beep
It is beep sound generating function. The beep frequency is 500Hz and 100
millisecond duration time.
Syntax
void beep()
4.7.2 sound
This is programmable sound generating function.
Syntax
Example 4-22
beep();
sound(1200,500);
4.8.2 uart
This is serial data sending function via UART0 port. The default baudrate is 115,200
bit per second.
Syntax
Operation
%c or %C
Display 1 character
%d or %D
%l or %L
%f or %F
\r
\n
4.8.3 uart_set_baud
This is baud rate setting function for UART0.
Syntax
Example 4-23
uart_set_baud(4800);
4.8.3 uart_available
This is receiveing data testing function of UART0.
Syntax
Example 4-24
char x =uart_available();
// Check the recieving data of UART0.
// If x value is more than 0; it means UART0 get any data.
// Read it by using uart_getkey function in the order next immediately.
4.8.4 uart_getkey
This is data reading function from receivers buffer of UART0
Syntax
char uart_getkey(void)
Return value
- 0 : no data received
- data : received character in ASCII code
Example 4-25
#include <robot.h>
// Get function
void setup()
{
}
void loop()
// Main loop
{
if(uart_available())
// Check incoming data
{
if(uart_getkey()==a)
// Is key a pressed ?
{
lcd(Key a Active!); // Display message when get a
sleep(1000);
// Delay 1 second
}
else
{
lcd(#c);
// Clead display
}
}
}
Note : Default baud ratre of UART library is 115,200 bit per second. Data format
is 8-bit and no parity.
4.8.5 uart1
This is serial data sending function via UART1 port. The default baud rate is 9,600 bit
per second.
Syntax
4.8.6 uart1_set_baud
This is baud rate setting function for UART1.
Syntax
Example 4-26
uart1_set_baud(19200); // Set baud rate as 19,200 bit per second
4.8.7 uart1_available
This is receiving data testing function of UART0.
Syntax
Example 4-27
char x =uart1_available();
4.8.8 uart1_getkey
This is data reading function from receivers buffer of UART1.
Syntax
char uart1_getkey(void)
Return value
- 0 : no data received
- data : received character in ASCII code
4.9.1 compass_read
This reads the angle of the HMC6352 digital compass.
Syntax
int compass_read()
Return value
Angle value 0 to 359 defree
4.9.2 compass_set_heading
This is reference angle setting function. With this function, the current angle that
read from digital compass is set to 0 degree reference.
Syntax
void compass_set_heading()
4.9.3 compass_read_heading
This is reference angle reading function. Use this function after set the new reference
angle from compass_set_heading function.
Syntax
int compass_read_heading()
Return value
1 to 180 : positive angle (clock wise direction) of digital compass.
-1 to -180 : negative angle (Counter-Clockwise direction) of digital compass.
Chapter 5
The ATX controller board
hardware experiment
This chapter presents examples of the hardware experiment with the ATX controller
board of the Robo-Creator robotic kit. There are 7 experiments as follows.
Experiment 1 Shows message on the display of the ATX board
Experiment 2 Using SW1 and SW2 switch
Experiment 3 Reading analog from KNOB button of the ATX board
Experiment 4 Sound activity
Experiment 5 DC motors control
Experiment 6 Servo motor control
Experiment 7 Serial data communication with computers
(4) Connect the ATX controller board with a USB port. Turn on power and wait until
the connection between the computer and ATX board is completed. This can be noticed
from the blue LED at the position of USB power on.
(5) Set the ATX board to program mode by pressing START switch and hold it for 3
seconds.
At the ATX board display, it shows messages
Robo-Creator
> Bootloader
and the red LED at the port 48 is powered on.
(6) Upload the code by click at the
Wiring hardware.
(7) Wait until the uploading is successful. Then press the START switch again. Finally,
the ATX controller circuit board will be running the latest uploaded program immediately.
Program L1-1
Experiment 1
Shows message on the display of the ATX board
Experiment 1.1 Simple message displaying on the ATX board
This experiment demonstrates the simle programming for showing the message at
the display of the ATX board.
Procedure
L1.1.1 Create the new sketch file. Type the Listing L1-1 and save as lcd_01.pde file
L1.1.2 Compile and upload the sketch to the ATX board.
L1.1.3 Run the program.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
At the LCD display of the ATX controller board show message Hello Robot! as follows.
> o B o o t l o ad e r o a r d
2
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RESET
14
PC6
15 PC7
MOTOR
#include <atx.h>
// Include the main library
void setup()
{
lcd("Hello Robot!"); // Display mesage on the ATX display
}
void loop()
{}
Code explanation
This code runs within the setup function. There is one command. Display the message;
Hello Robot! on the screen. After that the program will jump to run in the loop function. No
any command in this function. The operation is stop finally.
Procedure
L1.2.1 Create the new sketch file. Type the Listing L1-2 and save as lcd_02.pde file
L1.2.2 Compile and upload the sketch to the ATX board.
L1.2.3 Run the program.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
At the LCD display of the ATX controller board show message as follows :
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
10 11 12 13
S
BATTERY LEVEL
+
7.2-9V BATT.
RESET
#include <atx.h>
void setup()
{}
void loop()
{
lcd(Line1#nLine2);
}
14
PC6
15 PC7
MOTOR
Code explanation
The program starts running in the setup function then it repeats working in the loop function
to display message on both lines of the LCD. The result comes from the operation of control
code #n. The overall results have been shown the display of 2-line text.
Procedure
L1.3.1 Create the new sketch file. Type the Listing L1-3 and save as lcd_03.pde file
L1.3.2 Compile and upload the sketch to the ATX board.
L1.3.3 Run the program.
At the LCD display of the ATX controller board show message as follows :
Count: xxx
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
10 11 12 13
S
BATTERY LEVEL
+
7.2-9V BATT.
RESET
14
PC6
15 PC7
MOTOR
#include <atx.h>
// Include the main library
int i = 0;
// Declare the counting variable
void setup()
{}
void loop()
{
lcd("Count: %d ",i); // Display the counter on the ATX board display
sleep(1000);
// Delay 1 second
i++;
// Increase counter
}
Code explanation
The program starts running in the setup function and then it repeats working in the loop
function. It shows the counting value that increased every 1 second. The variable i stores the
count values.
Experiment 2
Using SW1 and SW2 switch
Experiment 2.1 Using SW1 to start the counter
This expeirment demonstrates how to use the SW1 on the ATX controller board to
start the counter. The counting values also should be display on the ATX board display.
Procedure
L2.1.1 Create the new sketch file. Type the Listing L2-1 and save as switch_01.pde file
L2.12 Compile and upload the sketch to the ATX board.
#include <atx.h>
int i=0;
void setup()
{
lcd("SW1 Press!");
sw1_press();
lcd("#c");
}
void loop()
{
lcd("Count: %d ",i);
sleep(1000);
i++;
}
Code description
The program starts running in the setup function to wait for the pressing of SW1 and
there is an alert by the text of SW1 Press! at the display after the switch is pressed. The
program will repeat working in the loop function to display the count value that is increased
in every 1 second. The i variable is used to stores the count values.
Listing L2-1 : switch_01.pde, the sketch file for checking the SW1
of the ATX board pressing to start the counter
SW1 Press!
L2.1.4 Press the SW1 on the ATX board and release.
Counting is start. The counter value is displayed on the ATX board display as follows.
Count: xxx
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RES ET
14 PC6
15 PC7
MOTOR
Procedure
L2.2.1 Create the new sketch file. Type the Listing L2-2 and save as switch_02.pde file
L2.2.2 Compile and upload the sketch to the ATX board.
L2.2.3 Run the program.
At the LCD display of the ATX controller board show message as follows :
Count: xxx
therefore xxx is the counting value. Start from 10.
#include <atx.h>
int i=10;
void setup()
{}
void loop()
{
lcd("Count: %d ",i); // Display the counting value
if(sw1()==0)
// SW1 is pressed ?
{
i++;
// If SW1 is pressed, increase counter.
sleep(200);
// Delay for switch debouncing
}
if(sw2()==0)
// SW2 is pressed ?
{
i-- ;
// If SW2 is pressed, decrease counter
sleep(200);
// Delay for switch debouncing
}
}
Code description
The program begins operating in the setup function. Then it repeats in the loop function.
It loop to check up pressing the switch of SW1 and SW2 all the time and display the count
values of the variable I at the LCD module as well.
Conditions of verification in the loop as following these:
1. If the SW1 is pressed ( sw1 ( ) function returns the value as 0)
The program responds by increase value of the variable i
2. If the SW2 is pressed (sw2 ( ) function returns the value as 0 )
The program responds by decrease value of the variable i.
Listing L2-2 : switch_02.pde, the sketch file for checking both SW1
and SW2 of the ATX board pressing anytime
L2.2.4 Press the SW1 switch on the ATX board. Observe the operation of the ATX board
display.
Each time you press the SW1, the count value is added up one value
L2.2.5 Press the SW2 switch on the ATX board. Observe the operation of the ATX board
display.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
Each time you press the SW2, the count value is deduct one value.
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RES ET
14
PC6
15 PC7
MOTOR
Press SW2 to
decrease value
Experiment 3
Reading analog from KNOB button of the ATX board
Experiment 3.1 Knob value reading
This experiment demonstrates how to read the analog value from KNOB button of
the ATX controller board. It is basic example of analog sensor reading. The result is 0 to
1023.
Procedure
L3.1.1 Create the new sketch file. Type the Listing L3-1 and save as knob_01.pde file
L3.1.2 Compile and upload the sketch to the ATX board.
L3.1.3 Run the program.
At the LCD display of the ATX controller board show message as follows :
KNOB: xxx
therefore xxx as KNOB position value from 0 to 1023
- Adjust to last left position. Value is 0.
- Adjust to last right position. Value is 1023.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RES ET
14
PC6
15 PC7
MOTOR
#include <atx.h>
void setup()
{}
void loop()
{
lcd("KNOB: %d
sleep(100);
}
",knob());
Code explanation
The program begins operating in the setup function. Then it repeats in the loop function
to display the readable values from KNOB at the LCD module.
Knob value is read by using knob function of the atx.h library. It is analog to digital
converter function.
Listing L3-1 : knob_01.pde, the sketch file for reading the KNOB
button of the ATX board value.
Procedure
L3.2.1 Create the new sketch file. Type the Listing L3-2 and save as knob_02.pde file
L3.2.2 Compile and upload the sketch to the ATX board.
L3.2.3 Run the program.
At the LCD display of the ATX controller board show message as follows :
Count: xxx
Count Up
in the Count up mode or
Count: xxx
Count Down
in the Count down mode
therefore xxx is thge counting value. Start from 100.
#include <atx.h>
int i=100;
int k;
void setup()
{}
void loop()
{
lcd("Count: %d
k = knob();
if(k>512)
",i);
//
//
//
//
Display counter
Read the KNOB value to store to the k variable
Check the KNOBs value is through
the middle to right or not ?
{
i++;
lcd("#nCount Up
");
}
else
{
i--;
lcd("#nCount Down
}
sleep(1000);
");
//
//
//
//
// Delay 1 second
Code explanation
The program begins operating in the setup function. Then it repeats in the loop function
to verification of adjustment position of KNOB continually. At the same time, the count value of
the variable i and the counting mode at the LCD module as well. There are conditions for the
verification as follows:
1. If the KNOB value is greater than 512
The program will respond to adding up the count value of the variable i to one value
and show the Count up mode message on the display.
2. If the KNOB value is less than 512 (working in the section of else).
The program will respond to deducting the count values of the variable i to one value
and show the Count down mode message on the display.
Listing L3-2 : knob_02.pde, the sketch file for using the KNOB button
of the ATX board to Mode selector
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
The program wil count up and down depending on the value of KNOB, which is
result from the rotation of spindle of the variable resistor at the position of KNOB of ATX
board.
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
10 11 12 13
S
BATTERY LEVEL
+
7.2-9V BATT.
RES ET
14
PC6
15 PC7
MOTOR
L3.2.4 Adjust the KNOB shaft to go through the middle to the left (or may adjust to the left)
This will be found that the counter is in Count down mode. The count value will be
deducted 1 value in each second.
L 3.2.5 Adjust the KNOB shaft to go through the middle to the right (or maybe adjust to the
far right)
The counter is in Count up mode. The count value will be added up 1 value in
each second.
Experiment 4
Sound activity
Exeperiment 4.1 The signal selector
This experiment demonstrates about using the SW1 and SW2 on the ATX controller
board to generate the different sound frequency. If SW1 is pressed, ATX board drives
500Hz signal with 0.1 second duration. If the SW2 is pressed, it generate 2000Hz (2kHz)
signal with 0.5 second instead.
Procedure
L4.1.1 Create the new sketch file. Type the Listing L4-1 and save as sound_01.pde file
L4.1.2 Compile and upload the sketch to the ATX board.
L4.1.3 Run the program. Press the SW1 on the ATX controller board.
Everytime to press the switch SW1, you will hear the sound with the frequency of
500 Hz for 0.1 second from the piezo speaker on the ATX board.
L 4.1.4 Press the switch SW2
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
Everytime to press the SW2, you will hear the sound of frequency 2000Hz for 0.5
second.
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RES ET
14 PC6
15 PC7
MOTOR
Press SW2 to
generate 2000Hz
signal
#include <atx.h>
void setup()
{
}
void loop()
{
if(sw1()==0)
{
beep();
sleep(100);
}
if(sw2()==0)
{
sound(2000,500);
sleep(100);
}
}
Code explanation
The program operates in the loop function to check the pressing of the SW1 and SW2
switches and there are conditions as follows.
1. If the SW1 is pressed (sw1( ) function returns the value as 0)
The program will respond to generate the 500Hz signal for 0.1 second.
1. If the SW2 is pressed (sw2( ) function returns the value as 0)
The program will respond to generate the 2000Hz signal for 0.5 second.
Listing L4-1 : sound_01.pde, the sketch file for using the SW1 and
SW2 on the ATX board to set the condition for signal generating
Procedure
L4.2.1 Create the new sketch file. Type the Listing L4-2 and save as sound_02.pde file
L4.2.2 Compile and upload the sketch to the ATX board.
L4.2.3 Run the program.
At the LCD display of the ATX controller board show message as follows :
Freq: xxx Hz
therefore xxx is the generated signal frequency
L4.2.4 Asjust the KNOB button slowly from left to right direction. See the display operation
and listen the sound signal from ATX board.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
The frequency of the sound displaying at the LCD module will increase from 0 to
2046Hz (as 2 times of the value read from KNOB). The sound you have listen will be
dramatically sharpened following the adjustment of frequency increasing.
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RES ET
14
PC6
15 PC7
MOTOR
#include <atx.h>
int k;
int f;
void setup()
{
}
void loop()
{
k = knob();
f = 2*k;
lcd("Freq: %d Hz
",f);
sound(f,200);
sleep(1000);
// Delay 1 second
Code explanation
The program starts working in the setup function and repeats to work in the loop function
to repeat reading from the KNOB button. Then, the value you have got multiply by 2 to use for
the frequency value desired so the value will be in the range of 0 to 2046Hz and the frequency
value will be shown at the LCD module.
For the sound generation at the Piezo speaker, the program will space in each second
briefly.
Listing L4-2 : sound_02.pde, the sketch file for using the KNOB button
on the ATX board to adjust the sound signal frequency
Experiment 5
DC motors control
Experiment 5.1 Direction control for DC motor driver
This experiment demonstrates about direction control for DC motor driver output 0
and 1 of the ATX board. The motor driver will be drive DC motor forward and backward
every 3 seconds continually.
Hardware connection
Connect the DC motor #1 with Motor-0 output of the ATX board.
Connect the DC motor #2 with Motor-1 output of the ATX board.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
DC motor #2
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RESET
14
PC6
15
PC7
MOTOR
DC motor #1
Procedure
L5.1.1 Create the new sketch file. Type the Listing L5-1 and save as motor_01.pde file
L5.1.2 Compile and upload the sketch to the ATX board.
L5.1.3 Run the program.
DC motor at output 0 and 1 start and reverse direction every 3 seconds.
#include <atx.h>
void setup()
{
}
void loop()
{
motor(0,70);
motor(1,70);
sleep(3000);
motor(0,-70);
motor(1,-70);
sleep(3000);
Code explanation
The program repeats to work in the loop function to drive the DC motor of the channel 0
and 1 simultaneously with 70% power equally both. And every 3 seconds reversing direction of
rotation will be operated continuously.
Hardware connection
Connect the DC motor #1 with Motor-0 output of the ATX board.
Connect the DC motor #2 with Motor-1 output of the ATX board.
Procedure
L5.2.1 Create the new sketch file. Type the Listing L5-2 and save as motor_02.pde file
L5.2.2 Compile and upload the sketch to the ATX board.
L5.2.3 Run the program.
DC motors at output 0 and 1 start and stop 3 seconds alternately and continually.
#include <atx.h>
void setup()
{
}
void loop()
{
motor(0,90);
motor(1,90);
sleep(3000);
// Delay 3 seconds
motor_stop(0);
// Stop motor-0
motor_stop(1);
// Stop motor-1
sleep(3000);
// Delay 3 seconds
Code explanation
The program repeats to work in the loop function to drive the DC motor at channel 0 and
1 simultaneously with the 90% power driving equally both. After 3 seconds, all motors will stop
for 3 seconds also and start to rotate again. This will work together seamlessly.
Experiment 6
Servo motor control
Experiment 6.1 Control position of the servo motor
This experiment demonstrates about programming to control the servo motor shaft
position. The servo motor is driven to move the shaft to 60 degrees position and stop to
lock at this position for 5 minutes. Next, change to the position to 120 degrees and stop to
lock at this position for 5 minutes as well. Then, the shaft will be moved to the position of 60
degrees again so that the positions will be switched back and forth like this constantly.
Hardware connection
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
Connect a standard servo motot to servo motor output port 12 of the ATX board
Servo motor
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
STANDARD
SERVO MOTOR
7.2-9V BATT.
RESET
14
PC6
15
PC7
MOTOR
Procedure
L6.1.1 Create the new sketch file. Type the Listing L6-1 and save as servo_01.pde file
L6.1.2 Compile and upload the sketch to the ATX board.
L6.1.3 Run the program.
The servo motor shaft will move between 60 and 120 degrees position every 5
seconds
#include <atx.h>
void setup()
{}
void loop()
{
servo(12,60);
sleep(5000);
// Delay 5 seconds
servo(12,120);
sleep(5000);
// Delay 5 seconds
Code explanation
The program repeats to work in the loop function to drive a servo motor to move its shaft
between the position of 60 and 120 degrees in every 5 seconds.
Listing L6-1 : servo_01.pde, the sketch file for driving a servo motor
to control the movement position
Hardware connection
Connect a standard servo motot to servo motor output port 12 of the ATX board
Procedure
L6.2.1 Create the new sketch file. Type the Listing L6-2 and save as servo_02.pde file
L6.2.2 Compile and upload the sketch to the ATX board.
L6.2.3 Run the program.
At the LCD display of the ATX controller board show message as follows :
Servo: xxx
therefore xxx is servo motor shaft position. Start at 90
#include <atx.h>
int p=90;
void setup()
{}
void loop()
{
servo(12,p);
lcd("Servo: %d
if(sw1()==0)
{
p++;
if(p>180)
{
p=0;
}
sleep(100);
}
if(sw2()==0)
{
p-- ;
if(p<0)
{
p=0;
}
sleep(100);
",p);
//
//
//
//
}
}
Code explanation
The program repeats to work in the loop function to drive a servo motor to move its shaft
to the position stored in the variable p along with displaying a position value at the LCD module.
Furthermore, there are conditions of verification within the loop as follows:
1. If the SW1 switch is pressed (sw1( ) function returns the value as o)
The program responds by adding the p variable value to 1 value and check that
exceed 180 or not. If it is exceeded, set the position to start with the new 0. Next, time delay will
proceed to not cause the addition of values too fast.
2. If the SW2 switch is pressed (sw2( ) function returns the value as 0)
The program responds by reducing the p variable value to 1 value and verifies that
the value is below 0 or not. If it is, set the position to start with the new 0 and then time delay.
Listing L6-2 : servo_02.pde, the sketch file for driving a servo motor
to control the movement position by SW1 and SW2 switch on the
ATX board
Experiment 7
Serial data communication with computers
Experiment 7.1 Transmit the serial data to computer
This experiment demonstrates about computer interfacing of the ATX controller
board. Begins with transmitting the serial data to USB port via the USB to serial converter
circuit on the ATX board. The data will be display on the Serial Monitor of Wiring IDE.
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RESET
14
PC6
15 PC7
MOTOR
Procedure
L7.1.1 Create the new sketch file. Type the Listing L7-1 and save as uart_01.pde file
L7.1.2 Compile and upload the sketch to the ATX board. Still connect the USB cable with
USB port of computer.
#include <atx.h>
void setup()
{}
void loop()
{
uart("Hello Robot!\r\n");
sleep(2000);
// Delay 2 seconds
Code explanation
The program reapeats working in the loop function to transmit some text Hello Robot! to
display on the Serial Monitor of the computer every 2 seconds continuously.
Listing L7-1 : uart_01.pde, the sketch file for transmitting the serial
data to computer of the ATX controller board
L7.1.3 Run the program. Click on the
The Serial Monitor window appears and dsiplay message Hello Robot! every 2
seconds.
Procedure
L7.2.1 Create the new sketch file. Type the Listing L7-2 and save as uart_02.pde file
L7.2.2 Compile and upload the sketch to the ATX board. Still connect the USB cable with
USB port of computer.
L7.2.3 Run the program. Click on the
L7.2.4 Adjust the KNOB button and see the operation at the Serial Monitor of Wiring IDE.
The Serial Monitor displays message KNOB: xxx every 0.1 second. Therefore xxx
value us 0 to 1023.
#include <atx.h>
void setup()
{}
void loop()
{
uart("KNOB: %d
sleep(100);
Code explanation
The program repeats to work in the loop function to transmit the KNOB value to KNOB to
display on the Serial Monitor of the computer every 0.1 seconds continuously.
Listing L7-2 : uart_02.pde, the sketch file for transmitting the KNOB
button of the ATX board to computer
Procedure
L7.3.1 Create the new sketch file. Type the Listing L7-3 and save as uart_03.pde file
L7.3.2 Compile and upload the sketch to the ATX board. Still connect the USB cable with
USB port of computer.
L7.3.3 Run the program. Click on the
L7.3.4 Type character of number 1 at the transmit box. Choose the serial data parameter
box to No line ending. After that, click on the Send button of the Serial Monitor.
#include <atx.h>
char c;
void setup()
{}
void loop()
{
if(uart_available())
{
c = uart_getkey();
if(c=='1')
{
beep();
}
if(c=='2')
{
sound(2000,500);
}
}
}
Code explanation
The program repeats to work in the loop function to receive the serial data from computer.
After the receiving occur, it will be stored data to the c variable and check the value as follows :
1. If the data is the number 1 (from pressing the key 1)
The program will respond by generating the 500Hz signal for 0.1 second.
2. If the data is the number 2 (from pressing the key 2)
The program will respond by generating the 2000 Hz signal for 0.5 second.
3. If it is another data
No response
Listing L7-3 : uart_03.pde, the sketch file for receiving the serial data
from computer of the ATX board
Chapter 6
AT-BOT movement
After try out with some experiment to verify the operation of the hardware in the
chapter 5. Next, it will be the part of understanding to the mechanical structure of AT-BOT
robots and how to move AT-BOT robots. The movement of AT-BOT robots is different from
familiar two wheeled mobile robots because an AT-BOT has 4 sets of DC motor gearbox
and spike wheels. Therefore, programming to drive robots also needs to be considered
the functions of all 4 motors. In this chapter, the content will be presented with examples
of programming under C/C++language of Wiring to manage AT-BOT to move in the basic
patterns, either moving straight, backward and turning or turning around in various ways.
ON
42 ADC2
41 ADC1
40 ADC0
ADC7
SW1
46 ADC6
10 11 12 13
SW2
48
MOTOR
44 ADC4
50
PC7
BATTERY LEVEL
45 ADC5
49
PC6
START
43 ADC3
SERVO PORT
14
15
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
8
+
USB DATA
E2
RESET
7.2-9V BATT.
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW2
45 ADC5
49
48
MOTOR
44 ADC4
50
PC7
15
BATTERY LEVEL
PC6
SW1
c o n tr o l l er Rb o a r d
ADC7
10 11 12 13
44 ADC4
KNOB
45 ADC5
SERVO PORT
46 ADC6
40 ADC0
48
MOTOR
USB DATA
41 ADC1
50
PC7
7.2-9V BATT.
42 ADC2
SW2
15
BATTERY LEVEL
START
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
43 ADC3
49
PC6
14
SW1
c o n tr o l l er Rb o a r d
ADC7
10 11 12 13
SERVO PORT
9
S
E2
RESET
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
ON
ON
E2
RESET
7.2-9V BATT.
START
ON
ON
E2
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
45 ADC5
ADC7
14
SW1
46 ADC6
10 11 12 13
SERVO PORT
9
40 ADC0
49
PC6
SW2
48
MOTOR
BATTERY LEVEL
SW2
15 PC7
48
MOTOR
BATTERY LEVEL
50
44 ADC4
15 PC7
45 ADC5
49
PC6
50
44 ADC4
41 ADC1
KNOB
c o n t ro l l er R b o ar d
42 ADC2
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
43 ADC3
+
14
SW1
c o n t ro l l er R b o ar d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
ADC7
10 11 12 13
SERVO PORT
KNOB
5
4
3
2
ON
ON
USB DATA
E2
RESET
USB DATA
E2
RESET
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
45 ADC5
ADC7
10 11 12 13
SERVO PORT
40 ADC0
ADC7
14
SW1
46 ADC6
10 11 12 13
14
SW1
49
PC6
SW2
SW2
15 PC7
48
MOTOR
48
MOTOR
BATTERY LEVEL
50
44 ADC4
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
50
44 ADC4
41 ADC1
KNOB
c o n t ro l l er R bo a r d
42 ADC2
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
43 ADC3
SERVO PORT
KNOB
c o n t ro l l er R bo a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
USB DATA
RESET
USB DATA
E2
RESET
START
START
Turning
point
7.2-9V BATT.
7.2-9V BATT.
START
START
1
0
5
4
3
2
1
0
7.2-9V BATT.
7.2-9V BATT.
There are two formats of the movement, including turning with two wheels and
turning around.
This movement uses 2 sets of motors and wheels in driving an AT-BOT to turn left by
controlling the right front wheel and the right back wheel to rotate forward. Meanwhile,
the left front wheel and the left back wheel are stopped, so the robot will be able to turn
left and the rotation point is between the left front wheel and the left back wheel as the
diagram below.
43 ADC3
42 ADC2
41 ADC1
40 ADC0
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
Turning
point
46 ADC6
SW1
14
44 ADC4
ADC7
SERVO PORT
c o n t ro l l er Rb o a r d
KNOB
10 11 12 13
45 ADC5
46 ADC6
40 ADC0
48
USB DATA
41 ADC1
50
MOTOR
7.2-9V BATT.
42 ADC2
SW2
15 PC7
BATTERY LEVEL
START
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
43 ADC3
49
PC6
14
SW1
c o n t ro l l er Rb o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
10 11 12 13
ADC7
SERVO PORT
9
S
E2
RESET
USB DATA
KNOB
ON
ON
E2
RESET
7.2-9V BATT.
START
43 ADC3
42 ADC2
41 ADC1
40 ADC0
SW2
44 ADC4
50
48
MOTOR
BATTERY LEVEL
45 ADC5
49
Turning
point
46 ADC6
SW1
PC6
ADC7
14
15 PC7
c o n t r o ll er R b o ar d
KNOB
44 ADC4
9 10 11 12 13
45 ADC5
SERVO PORT
46 ADC6
40 ADC0
48
USB DATA
41 ADC1
50
MOTOR
7.2-9V BATT.
42 ADC2
SW2
15 PC7
BATTERY LEVEL
START
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
43 ADC3
49
PC6
14
SW1
c o n t r o ll er R b o ar d
ADC7
SERVO PORT
9 10 11 12 13
S
E2
RESET
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
ON
ON
E2
RESET
7.2-9V BATT.
START
43 ADC3
42 ADC2
41 ADC1
40 ADC0
SW2
44 ADC4
50
48
MOTOR
BATTERY LEVEL
45 ADC5
49
Turning
point
46 ADC6
SW1
PC6
ADC7
SERVO PORT
14
15 PC7
c o n t ro l l er Rb o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
44 ADC4
10 11 12 13
45 ADC5
46 ADC6
48
40 ADC0
50
MOTOR
USB DATA
41 ADC1
SW2
15 PC7
BATTERY LEVEL
7.2-9V BATT.
42 ADC2
49
PC6
START
E2
43 ADC3
14
SW1
ADC7
10 11 12 13
c o n t ro l l er Rb o a r d
KNOB
SERVO PORT
RESET
USB DATA
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
ON
ON
E2
RESET
7.2-9V BATT.
START
Experiment 8
Wheel driving setting
This experiment must be done first for programming to control AT-BOT to move around
by presenting the adjustment step of the motor driving to test the basic movement.
AT-BOT are defined all motor connections as follows:
The left front wheel is connected with the Motor-0 output.
The left back wheel is connected with the Motor-1 output
The right back wheel is connected with the Motor-2 output
The right front wheel is connected with the Motor-3 output
In order that this test is in the same way, need to determine the direction of the
wheel rotation in each position. In here, a motor of any wheel is driven with a positive
value power (+). From the motor function, the motor will turn to the direction that forces a
robot to move forward. For example, when you drive the motor from the Motor-1 output
with a positive power, the motor shaft will rotate to the direction that makes a robot move
forward. If it rotates in the reverse direction, change the polarity connecting of the motor
cables at the Motor-1 output to opposite polarity. And then examine remaining 3 motors
and wheels with the same method.
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
15
48
MOTOR
44 ADC4
50
PC7
BATTERY LEVEL
45 ADC5
49
PC6
ADC7
SERVO PORT
9 10 11 12 13
c o n t r o l l er R b o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
#include <atx.h>
// Include the main library
Code explanation
The motor of the channel 0, 1, 2, and 3
are driven with +50% power. Observe the
voltage polarity that supplies to the motor from
void setup()
{}
void loop()
{
motor(0,50);
motor(1,50);
motor(2,50);
motor(3,50);
}
Listing L8-1 : motor_test.pde, the sketch file for checking the motor
connection of the AT-BOT
Procedure
L8.1 Remove all motor cable.
L8.2 Create the new sketch file. Type the Listing L8-1 and save as motor_test.pde file
L8.3 Compile and upload the sketch to the ATX board.
L8.4 Connect the left front motor cable to motor-0 output
If polarity is correct, robots wheel will rotate to the direction that drive the robot
forward. If not, swap the connection of motor cable
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
ADC7
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
KNOB
10 11 12 13
SERVO PORT
c o n t ro l l er R bo a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
USB DATA
E2
RESET
7.2-9V BATT.
START
L8.5 Connect the left back motor cable to motor-1 output of the AT-BOT
If polarity is correct, robots wheel will rotate to the direction that drive the robot
forward. If not, swap the connection of motor cable
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
50
48
MOTOR
44 ADC4
BATTERY LEVEL
15 PC7
45 ADC5
49
PC6
ADC7
10 11 12 13
SERVO PORT
c o n t ro l l er R bo a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
L8.6 Connect the right back motor cable to motor-2 output of AT-BOT
If polarity is correct, robots wheel will rotate to the direction that drive the robot
forward. If not, swap the connection of motor cable
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
ADC7
10 11 12 13
SERVO PORT
c o n t ro l l er R bo a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
L8.7 Connect the right back motor cable to motor-3 output of AT-BOT
If polarity is correct, robots wheel will rotate to the direction that drive the robot
forward. If not, swap the connection of motor cable
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
ADC7
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
KNOB
10 11 12 13
SERVO PORT
c o n t ro l l er R bo a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
USB DATA
E2
RESET
7.2-9V BATT.
START
Since all motor connections are correct and get the correct result.
User must use these motor connection and polarity mainly on
programming for all experiments in this activity book.
Experiment 9
Creating the AT-BOT movement function
These experiments will present examples of program development to control the
AT-BOTs movement by using the movement control function. Includes forward, backwards,
turn left, turn right and stop.
Code explanation
When the program starts, there is a title message at the ATX board display and then wait
for the pressing of SW1. After SW1 is pressed, the program will repeat to work in the loop
function to drive motors in order to make the robot move forward constantly.
Addition Program developers can define motor driving power as appropriate. Generally, it is
defined that values of the motor driving power in all wheels should be the same. In case that
each motor operates differently, a developer needs to test by adjusting a value of driving power
of each motor to be not the same in order to find out the best value that makes a robot move
best as possible.
Procedure
L9.1.1 Create the new sketch file. Type the Listing L9-1 and save as robot_move_forward.pde
file.
L9.1.2 Compile and upload the sketch to the AT-BOT.
L9.1.3 Run the program.
AT-BOT display shows the title message ; SW1 Press.
AT-BOT moves forward after the SW1 is pressed.
Procedure
L9.2.1 Create the new sketch. Type the Listing L9-2 and save as robot_move_backward.pde
file.
L9.2.2 Compile and upload the sketch to the AT-BOT.
L9.2.3 Run the program.
AT-BOT display shows the title message ; SW1 Press.
AT-BOT moves backward after the SW1 is pressed.
Procedure
L9.3.1 Create the new sketch file. Type the Listing L9-3 and save as robot_turn_left.pde file.
L9.3.2 Compile and upload the sketch to the AT-BOT.
L9.3.3 Run the program.
AT-BOT display shows the title message ; SW1 Press.
AT-BOT turns left after the SW1 is pressed.
Procedure
L9.4.1 Create the new sketch file. Type the Listing L9-4 and save as robot_turn_right.pde file.
L9.4.2 Compile and upload the sketch to the AT-BOT.
L9.4.3 Run the program.
AT-BOT display shows the title message ; SW1 Press.
AT-BOT turns right after the SW1 is pressed.
Procedure
L9.5.1 Create the new sketch file. Type the Listing L9-5 and save as robo_pause.pde file.
L9.5.2 Compile and upload the sketch to the AT-BOT.
L9.5.3 Run the program.
AT-BOT display shows the title message ; SW1 Press.
AT-BOT moves forward with 2 seconds and stop for 3 seconds alternate continually
after the SW1 is pressed.
Listing L9-5 : robo_pause.pde, the sketch file for controlling the ATBOT to move with time setting
Chapter 7
Object avoidance by contact
Subsequent learning after driving robots is to read values from sensors in order to
define the conditions in the movement and the most basic sensor that functions in here is
switch. In this chapter, it will mention about application of a switch input board cooperated
with AT-BOT so as to detect touching with obstacles and hence a robot will be able to
recognize moving to meet obstacles. After this it will process to define movement to be
capable of passing through the obstacles.
An important material used in this learning is a switch input board. There is a circuit
and a working diagram shown as in the figure 7-1. When there is a pressing of switch, it
means touching or bumping with obstacles. The logic output signal will change from the
logic 1 to 0 until release the switch or there is no bumping and then the output signal
will change back to be 1 again.
With this sensor characteristic, it is used to determine the conditions of the movement
for AT-BOT by attaching the switches at the front of a robot body. Once a robot runs to
touch or crash with any obstruction, the switch will be pressed and the controller will
recognize a change of the output connected with the switch. Therefore, this process will
control the robot to move backward and followed by changing a direction of movement.
Only this, the robot will be able to move passed the obstacless.
Output
LED1
LED status
+V
R2
10k
R1
510
LED Switch
status
S1
Switch
R3
220
DATA
Output
GND
Experiment 10
Reading the Switch input board
This experiment is a test for function of a switch input board on AT-BOT by which the
ATX board will read the status of pressing the switch from the switch input board connected
with ADC0 port (or the port 40) to show at the LCD module of the ATX board.
connect to ADC0
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
15
48
MOTOR
44 ADC4
50
PC7
BATTERY LEVEL
45 ADC5
49
PC6
ADC7
10 11 12 13
SERVO PORT
c o n t ro l l er R bo a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
#include <atx.h>
void setup()
{}
void loop()
{
lcd("Switch1: %d ",in(40));
}
Procedure
L10.1 Create the new sketch file. Type the Listing L10-1 and save as switch1_test.pde file.
L10.2 Compile and upload the sketch to the AT-BOT.
L10.3 Run the program.
AT-BOT display shows the title message :
Switch: x
therefore x is the reading data of the Swich input board
L10.4 Press and hold the switch and then check the result of the operation.
The status value of the switch (x) will change to 0 and when you release the switch,
the result will return to the value of 1 again.
STA
T
41 ADC1
4
DC
A
44
40 ADC0
C5
AD
5 A DC 2
442
46 ADC6
C6
11
E R 10O PORT
SSERV
9
8 89 10 11 12 13
+
14
ON
USB D ATA
E2
14
PC6
S W1RESET
49
50
48
TWI
UA RT1
0 SCL 1 SD A 2 R X1 3 TX1
SW2
15
PC7
MOTOR
BATTERY LEVEL
ADC2
ADC64 1 45
A DCA1DC 540 44ADC0
ADC4
42 46
10 11 12 13
SERVO PORT
ADC3
0
4 043A DC
U SB D ATA
E2
15
PC7
MOTOR
46 A DC 6
10 11 12 13
SERVO PORT
BATTERY LEVEL
46 A DC 6
14
SW1
PC6
49
40 ADC0
+
14
S W1
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
ADC 7
10 11 12 13
4 1 A DC 1
10 11 12 13
14
SW1
SW2
ADC7
15 P C7
48
14
SW1
MOTOR
48
MOTOR
BATTERY LEVEL
50
4 4 ADC4
15 P C7
BATTERY LEVEL
SW2
50
4 4 ADC4
9 10 11 12 13
SERV O PORT
KNOB
45 ADC5
PC6
49
45 ADC5
PC6
49
45 ADC5
44 A DC 4
MOTOR
PC7
15
BA TTER Y LEVEL
PC6
48
44 A DC 4
S W2
15
PC7
MOTOR
BA TTER Y LEVEL
50
45 ADC5
PC6
49
5
4
3
2
1
43 ADC3
RX
UA 1 3
46 ADC6
2
DC
A
40 ADC0
2
4
L
SC
I SD
TW 1
T
E SE
R
41 ADC1
C3
AD
AD
>
46
>
d
>
> t o rr e > > > > > > > >
C0
C r e> a
a
AD
40
o
>
1
c >o n Rtbr o l l e r R b o a
DC
48 r d
A
>
41
0
r
e
5
EL
USB D ATA
e
2
r
LEV
W
Y
S
R
l
o
O
ER
T
ON
O
49
TT
t TWIl
M
UA RT1
BA
1
a 0 SCLo 1 SD A 2 R X1 3 TX1
7
W
S
r
PC
eE2
15
t
r
6
7
n
C
DC
PC
A
RT
o
1449
ADC7 13
SW1
S W2 50
48
+
B KNOB PO
1 X1
12
cRESET
NO
RT T
VO
K
TA
DA
E2
45 A DC
435 ADC3
44 ADC4
42 A DC 2
US
46 ADC6
43
4 0 A DC 0
.
41 ADC1
TT
42 ADC2
41 ADC1
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
42 ADC2
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
SERVO PORT
42 ADC2
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
ADC7
c o n t r o l l er R b o a r d
43 ADC3
SW2
KNOB
50 ADC7
48
c o n t r o l l ecroRnbtoraorldl e r R b o a r d
43 A DC 3
KNOB ADC 7
c o nt r o ll er Rb o a rd c on t r ol l erR b o ar d
C r e a t o r e > > > > > > > > C r e a t o r e > >> > > > > >
43 A DC 3
BA
USB DATA
E2
RESET
USB DATA
E2
R ESET KNOB
U SB D ATA
E2
SERVO PORT
STAR T
START
0
5
4
7.2-9V BAT T.
7 .2 -9V B AT T.
KNOB
5
3
5
4
3
2
ON
ON
RESET
ON
R ESET
START
4
1
STAR T
3
S
4
3
2
2
0
-
1
1
7.2-9V BATT.
1
0
START
START
0
5
7 .2 -9V B AT T.
7.2-9V BATT.
Obstacle
Obstacle
Obstacle
Obstacle
7.
2-9
V
Experiment 11
AT-BOT avoid the obstacle by touching
Procedure
L11.1 Create the new sketch file. Type the Listing L10-1 and save as switch1_test.pde file.
L11.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable from the robot.
L11.3 Place the robot on the floor. Place some obstacle such as box or can to set the
demonstration field.
AT-BOT move forward. If it will bump a obstacle, it will step back and change a
direction to the left. After that the robot will move forward continuously.
#include <atx.h>
// Include the main library
#define POW 80
// Set the motor power to 60%
char mid;
// Declare the switch status variable
void forward(unsigned int time)
// Moving forward function
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for moving forward
}
void backward(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for moving backward
}
void turn_left(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for turning left
}
void turn_right(unsigned int time)
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for turning right
}
void setup()
{
lcd("SW1 Press!");
sw1_press();
}
void loop()
{
mid = in(40);
if(mid==0)
{
beep();
backward(500);
turn_left(800);
}
else
{
forward(1);
}
}
Code explanation
The program begins with display the title message for asking the SW1 pressing in order to
wait for pressing the switch of SW1 by the sw1_press function. When the SW1 on the AT-BOT is
pressed, the program will be able to follow a command in the next line, which is to work in the
loop function. It defines to repeat reading a status value of the ADC0/40 port, which is connected
with the switch input board or touch sensor. Store the value at the variable mid. Once the switch
input board is pressed, it will give the result as 0 and then the program will bring the value of
the variable to compare as the following:
The case of if(mind==0) : it is the checking the switch input board is pressed or
not. If it is true, this will influence the robot to drive a beep sound and move backward. After
that the robot will turn left to avoid an object (the value of time delay will be adjusted by a
developer as appropriate).
The case of else : it is inferred that the robot has not found any obstacle. If is true,
it will cause the robot to move forward for a short distance.
Experiment 12
Reading two touch sensors
This experiment purpose is reading the status of two of switch input boards. Now it
is called Touch sensor. The ATX board will read the status of switch pressing from the
switch input board connected with ADC0/40 and ADC2/41 ports to show at the LCD
module of the ATX board.
Switch input
board #2
connect to
ADC0/40
connect to
ADC1
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
ADC7
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
KNOB
10 11 12 13
SERVO PORT
c o n t ro l l erR b o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
USB DATA
E2
RESET
7.2-9V BATT.
START
Procedure
L12.1 Create the new sketch file. Type the Listing L12-1 and save as switch2_test.pde file.
L12.2 Compile and upload the sketch to the AT-BOT.
#include <atx.h>
// Include the main library
void setup()
{}
void loop()
{
lcd("Switch1: %d #nSwitch2: %d ",in(40),in(41));
// Read the switch input board status from ADC0/40
// and ADC1/41 port to display on the LCD module of the AT-BOT
}
Switch1: x
Switch2: y
therefore x and y are the reading data of the Swich input board #1 and 2
consequently
L12.5 Press the Switch input board #1 (at port ADC0/40) and see the operation.
The status value of the switch (x) will change to 0 and after release the switch, the
result will return to the value of 1 again.
L12.6 Press the Switch input board #1 (at port ADC1/41) and see the operation.
The status value of the switch (y) will change to 0 and after release the switch, the
result will return to the value of 1 again.
T
R
S TA
41 AD C1
43
2
4
E2
AD
C2
43
45
RX
E2
ES
R
SC
ET
I SDA
TW 1
AD
C5
44
4
A DC
40 ADC0
AD
C7
RV
SE
10
13
PC6
49
11
RT
PO 12
14
SW1
SW2
15
ON
USB DAT A
E2
PC6
49
SW2
15
50
PC7
48
MOTOR
48
MOTOR
50
44 AD C4
15 PC7
BATTERY LEVE L
SW2
TWI
UART1
0 SCL 1 SDA 2 RX 1 3 TX1
49
45 ADC5
14 PC 6
10 1 1 1 2 13
SERVO PORT
46 ADC6
14
45 ADC5
PC6
49
SW2
15
ADC7
10 11 1 2 13
SERVO PORT
KNOB
48
44 AD C4
50
PC7
MOTOR
14
SW1
PC 6
49
50
SW2 50
15 PC7
14
48
6
PC
MOTOR
MOTOR
BATTERY LEVE L
48
44 ADC4
PC7
46 ADC6 45 ADC5
1 0 1 1 12 1 3
SERVO PORT
KNOB A DC7
B
NO
K
C6
>
AD
>
46
> rd
>
0
C
ADC3 AD
42 AD C2 41 ADC1 >
40 AD C0 a 46 ADC6 45 ADC5 44 AD C4
40
o
>
b
>
48
R
>
r
50
e
V EL
e
2
r
LE
W
Cr e
RY
o a tlo r e > > > > > > > S>
TE
l
49
t
AT
1 r d B
cao n to r o l l e r R b o a
7
SW
r
PC
e
15
t
1
A DC
AT
D
T WI
UA RT1 T1 TX
AR 3
0 SC L 1 SDA 2 RX1 3 UTX1 1
41
ON
46 ADC6
43 AD
45 C3ADC5
42 ADC2
44 ADC4
41 AD C1
RESET
US
US B DATA
C3
AD
ON
40 ADC0
AR
T
42 ADC2
TWI
UART1
0 SCL 1 SDA 2 RX 1 3 TX1
KNOB
c o n t r o l l e r R b o acrodn t r o l l e r R b o a r d
C r e a t o r e > > > > > >C>r>e a t o r e > > > > > > > >
43 AD C3
ST
AD
C4
USB DAT A
E2
AD
44
48
44 AD C4
45
C5
MOTOR
ON
RESE T
>
MOTO R
45 ADC5
>
>
50
PC7
48
44 ADC4
50
1 5 PC 7
40 ADC0
46 ADC6
14
SW1
46 ADC6
>
>
a
>
SW2
15
BATTERY LEVEL
SW2
BATTERY LEVEL
41 ADC1
1 0 11 12 1 3
40 AD C0
1 0 1 1 12 1 3
AD
C2
>
49
PC6
45 ADC5
PC 6
49
42 AD C2
SERVO PORT
41 ADC1
SW1
c o n t r o l l er R b o a r d
43 ADC3
TWI
UA RT1
0 SC L 1 SD A 2 RX1 3 TX1
KNOB A DC 7
42 AD C2
SERVO PORT
ADC 7
c o n t r o l l er R b o a r d
43 ADC3
TWI
UA RT1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
C3
40 AD
42 C0
AD
e
R
b
14
SW1
14
SW1
43
41 ADC1
ADC7
48
10 11 1 2 1 3
50
LE
VE
SW
2
46 ADC6
1 0 1 1 12 13
42 ADC2
SERV O PORT
KNOB
49
MO
TO
BA
TT
ER
40 ADC0
SERVO PORT
KNOB
TT
US
B
TW
I
1 SD
ADC
P
C7
SW
1
41
DAT
C
A
A
r
DC1
c
40 > > > >
C r e ao t oe r
a e > >> >
AD
n
t
C0
c o n t r tor l lo e r R b o a r d
r
46
o
e
A
AD
l
C6
>
43 ADC3
0 SC
PO
KN
OB
RV
O
MOTO R
US B DATA
E2
US B DATA
E2
RESET
5
4
3
2
O
N
E
2
US B DATA
SE
SE
10
RT
13
15
2 RX U
AR
1
T1
3 TX
TWI
U1ART1
0 SCL 1 SDA 2 RX1 3 TX1
12
PC
6
48
TWI
UART1
0 S CL 1 S DA 2 RX1 3 TX1
50
PC7
15
ON
RESET
ON
RE
T.
AT
BE2
11
+
14
46 AD C6
43 ADC3
45 ADC5
42 AD
44C2ADC4
41 ADC1
RESET
9V
27.
ON
40 ADC0
USB DAT A
E2
SW2
PC6
49
MOTOR
MOTOR
41 ADC1
ON
+
14
10 11 12 13
44 AD C4
48
45 ADC5
50
PC7
15
48
44 ADC4
50
PC7
STA RT
START
BA
42 AD C2
C r e a t o r e > > > > > >C>r>e a t o r e > > > > > > > >
43 ADC3
SERVO P ORT
46 ADC6
SW2
BATTERY LEVEL
45 ADC5
15
BATTERY LEVEL
SW2
ADC7
c o n t r o l l e r R b o acrodn t r o l l e r R b o a r d
KNOB
40 ADC0
PC6
49
46 ADC6
PC6
49
7.2- 9V BATT.
2
- 9V
USB DAT A
41 ADC1
TWI
UAR T1
0 SCL 1 SDA 2 RX1 3 TX1
42 ADC2
+
14
SW1
co nt rol l erRb oa rd
43 ADC3
10 1 1 1 2 1 3
40 AD C0
14
E2
RESE T
USB DATA
SERV O PO RT
41 ADC1
START
ON
ON
KNO B ADC7
42 ADC2
TWI
U ART1
0 SCL 1 SDA 2 RX1 3 TX1
10 11 12 1 3
SW1
43 ADC3
TWI
U ART1
0 SCL 1 SDA 2 RX 1 3 TX1
E2
USB DATA
START
START
START
STA RT
0
5
4
Obstacle
Obstacle
Obstacle
Obstacle
2
1
0
5
4
3
2
1
0
S ERVO PORT
START
E2
RESET
ON
7.2-9V BATT .
5
4
3
2
1
0
STA RT
START
KNO B ADC7
1
0
7.2-9V BATT.
Obstacle
Obstacle
Obstacle
Obstacle
7.
Experiment 13
AT-BOT avoid the obstacle with two touch sensors
This experiment demonstrates about programming to using two switch input boards
as two of touch sensors. One is installed at the left front side of the AT-BOT. Another one is
on the right front side. The operated condition is as follows :
1. A robot does not find any collision, the robot will move straight forward
constantly.
2. A robot is crashed on the left side, there will be a loud sound out once. Then,
the robot will move backward and change the direction to the right and keep moving
forward to avoid the object.
3. A robot is crashed on the right side, there will be a loud sound out once. Then,
the robot will move backward and change the direction to the left and keep moving
TO
4. A robot is crashed on the front side. Both touch sensors are attacked. There will
be a loud sound out once. Then, the robot will move backward and change the direction
to the left and keep moving forward to avoid the object.
Obstacle
Obstacle
ON
1
49
S W2
BA
TTE
C6
A DC
AR
C4
ST
AD
44
>
>
>
9V
AD
45
>
50
48
RY
LE
15
P C7
VE
ADC4
48
MOT OR
P C6
46
>
ADC5 44
50
PC 7
SW
14
45
15
C0
>
C7
RT
13
SW2
48
MOTOR
44 AD C4
50
PC7
15
SW2
BATTERY LEVEL
ADC5
PC6
49
12
PO
BA
TT
.
11
er
>
ADC6
RV
O
10
>
46
14
SW1
AD
40 ADC0
ADC 7
1 0 11 12 1 3
OB
41 ADC1
SERVO P ORT
SE
C1
AD
42 ADC2
PC6
49
ADC6 45
AD
40
2 R UA RT
X1
1
3 TX
KN
41
A DC
KNOB
46
14
SW1
START
40 ADC0
42
START
C3
c o n t r o l l er R b o a r d
UART1
2 RX 1 3 TX1
E2
43 AD C3
RE
S ET
AD
USB D ATA
TWI
0 SCL 1 SDA
DA
TA
0 SC TW
I
L
1 SD
43
E2
43 45
42 44
41 AD C1
AD C6
ADC3ADC5
ADC2ADC4
U SB
ON
ON
RESE T
46
ADC7
10 11 1 2 13
S
40 ADC0
42 ADC2 41 ADC1
C r e a t o r e > > > > > >C>r>e a t o r e > > > > > > > >
T WI
UAR T1
0 SCL 1 SDA 2 RX1 3 TX 1
43 AD C3
E2
US B DATA
SERVO PORT
KNOB
48
MOT OR
50
1 5 PC 7
SW2
ON
PC6
49
7.2-9V BATT .
c o n t r o l l e r R b o acrodn t r o l l e r R b o a r d
UART1
2 RX 1 3 TX1
14
TWI
0 SCL 1 SDA
ADC4
1 0 11 12 1 3
S
ST ART
E2
44
SERVO PORT
ADC5
48
MOTOR
45
PC7
K NOB
ADC6
15
SW2 50
BA TTERY LEVE L
48
MOTOR
44 AD C4
50
PC7
USB D ATA
RESE T
46
PC6
ADC5
15
SW2
BATTERY LEV EL
STA RT
7.2-9V BATT .
41 ADC1 40 AD C0
14
SW1 49
ADC7
10 1 1 12 13
S
43 ADC3 42 AD C2
SERVO PORT
46 AD C6 45
c on tr o ll erR b oa r d
TWI
UA RT1
0 SCL 1 SD A 2 RX1 3 TX1
KNOB
41 ADC1 40 ADC0
PC6
49
14
SW1
co n tr o ll erR b oa r d
43 ADC3 42 ADC2
TWI
UART1
0 SC L 1 SDA 2 RX1 3 TX 1
ADC7
10 11 1 2 13
S
US B DATA
E2
US B DATA
E2
SERVO PORT
KNOB
2-
ON
RESET
ON
RESET
Obstacle
7.
Obstacle
STA RT
MO
TO
4 R
Procedure
L13.1 Create the new sketch file. Type the Listing L13-1 and save as robo_bumper2.pde.
L13.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable from the robot.
L13.3 Place the robot on the floor. Place some obstacle such as box or can to set the
demonstration field.
L13.4 Run the program.
AT-BOT display shows the title message : Press SW1
L13.5 Press the SW1 on the AT-BOT. Observe the robot operation.
AT-BOT will go straight constantly. If the robot finds a obstacle and there is collision
according to the defined condition, AT-BOT will be able to change the direction of
movement to avoid the obstacle.
#include <atx.h>
// Include the main library
#define POW 80
// Set the motor power to 60%
char left,right;
// Declare the switch status variable
void forward(unsigned int time)
// Moving forward function
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for moving forward
}
void backward(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for moving backward
}
void turn_left(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for turning left
}
void turn_right(unsigned int time)
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for turning right
}
void setup()
{
lcd("SW1 Press!");
// Display title message for asking to press the SW1
sw1_press();
// Wait until the SW1 is pressed
}
void loop()
{
// Read the left switch status to store to the left variable
left = in(40);
right = in(41);
// Read the right switch status to store to the right variable
if(left==1 && right==1)
// Check both switch are not pressed (no attack)
{
forward(1);
// Robot move forward short time
}
else if(left==0 && right==1) // Check only the left switch pressing
{
beep();
// If the left swith is pressed,
// drive a beep sound once
backward(500);
// Move backward 0.5 second
turn_right(800);
// Spin right 0.8 second
}
//for changing the direction of movement
}
}
Code explanation
At the beginning of the operation, the program will show the text of Press SW1 at the
LCD module to wait for pressing the SW1 switch on the AT-BOT. When the SW1 is pressed, CPU
will operate the command in the loop to repeat reading status values of the both switch input
boards at ACD0/40 and ADC1/41 to store at the variable of left and right respectively. Any
switch board is pressed, this will give the result value as 0 and then the program will take the
values of both variables to compare based on the below mentioned 4 cases:
Case 1: if(left==1 && right==1) verified whether there is no pressing both switches
or not. If it is true (no collision occurred), it will respond a robot to move forward in a short
distance because it has not found any obstacle.
Case 2: else if(left==0 && right==1) checked pressing only the left switch, so if
it is true (bumping at the left), there will be a response by making a beep sound and a robot will
step back to turn right in order to not clash with an obstacle.
Case 3: else if(left==1 && right==0) examined pressing only the right switch, if
it is correct (bumping at the right), it will react by a beep sound. Then, a robot will move
backward to turn left so it can avoid an obstacle.
Case 4: else if(left==0 && right==0) it is a test of pressing both switches. If it is
true (colliding with the front so both switches are pressed simultaneously), there will be 1
rhythm of a sound. Meanwhile, it will cause a robot to reverse and then turn left to avoid an
obstacle.
Program developers can modify the values of time delay used to define rhythmic movement
freely in each situation appropriately.
Chapter 8
AT-BOT Line tracking
One mission of learning about programming to control a small autonomous robot
is detection and locomotion along lines. Therefore, AT-BOT are able to perform this mission.
Contents in this chapter will start with explanation of function of light reflection sensors
which will be applied as line sensors and followed by preparation of field for test, examples
of sensor calibration to work efficiently. After this, entering to experimentls of programming
with C/C++ language to seek lines, move within the defined areas and move along the
lines which are not considered the junction and considered the junction.
Therefore, learners need efforts to understand and perform trials according to
sequences because the whole contents are related each and you will have to apply
some knowledge from the previous contents to integrate as well.
SFH310
+V
current
LED
510
10k
OUT
Super-bright
red LED
Photo-transistor
White surface
SFH310
+V
current
LED
510
10k
OUT
Super-bright
red LED
Photo-transistor
Black surface
3. Scissors or a Cutter
3 x 40mm. screw
ZX-03R
3 x 15mm.
screw
ZX-03R
3mm. nut
3mm. nut
25mm.
standoff
Middle ZX-03R is
connected to ADC1 port
25mm. plastic standoff
Left ZX-03R is connected
to ADC0 port
may be cut if it touch the
front wheel
Top view
3mm. nut
(2) Turn off power of AT-BOT and then attach the set of the ZX-03R structure from
step (1) at the front of the robot chasis by using 2 sets of 25mm. standoffs to cushion and
fasten them with 3 x 40mm. screws and 3mm. nuts 2 sets. As the result, the ZX-03R boards
are far from the floor about 5mm. Then, plug the cables of the left, middle and right ZX-03R
to ADC0, ADC1 and ADC2 port of AT-BOT respectively.
Finally, the AT-BOT is ready for the mission to detect surface and lines.
The objective of this style of installation sensors is to check surface and lines. The
sensors can detect both white and black lines including different colors such as purple
and yellow, green and red, etc.
Super-bright
red LED
Photo-transistor
Value from
analog function
White surface
400 to 900
Super-bright
red LED
Photo-transistor
Black line
Value from
analog function
10 to 300
If the ZX-03R is at the area of black lines, a value will be low and tends towards the
value 0.
If the sensor is at the area of a white surface, a value will be high and tends towards
the value 1023.
The calculation of the reference value used to identify white surface and black
lines will be as follows
Reference value = (value from the white surface + value from black lines)/2
For example, if the white surface values is 950 and black lines is 250, so the reference
value will be (950+250)/2 = 600
However, in a practical application user may configure to be wider than these but
should be in the range of 250 to 950 but should not choose values to be close to 250 and
950 too much.
Experiment 14
Determine the reference value for line detection
This experiment is a test to find reference values for detecting lines of AT-BOT with 3
of ZX-03R sensors. They are installed in the front and under the structure base of the AT-BOT.
The left sensor is connected with ADC0, the middle one connected with ADC1 and the
right one connected with ADC2. The result values will be processed and shown at the LCD
module of the AT-BOT robot.
The experiment will present and make the understanding about how to find the
reference value for distinguish between lines and surface. It is important knowledge for
making the line tracking robot.
The size of this field can be modified as appropriate. In this book, choose a white
PP board with the size of 90x60cm. stuck with black tapes to create the curve border in
the size of 70x40cm.
Hardware connection
Connect ADC0/40 port of AT-BOT with the left front ZX-03R sensor
Connect ADC1/41 port of AT-BOT with the middle front ZX-03R sensor
Connect ADC2/42 port of AT-BOT with the right front ZX-03R sensor
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
ADC7
SERVO PORT
9 10 11 12 13
c o n t r o l l er R b o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
#include <atxt.h>
// Include the main library
void setup()
{}
void loop()
{
lcd("L %d M%d
#nR %d
",analog(0),analog(1),analog(2));
// Read all sensor value from ADC0, ADC1 and ADC2 port
// to display on the AT-BOT display
}
Listing L14-1 : reflect_test.pde, the sketch file for reading sensor from
ADC0, ADC1 and ADC2 input to display at the AT-BOT
Procedure
L14.1 Create the new sketch file. Type the Listing L10-1 and save as reflect_test.pde file.
L14.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L14.3 Run the program.
AT-BOT display shows the title message :
L xxx M yyy
R zzz
therefore xxx ,yyy and zzz are the digital data from reading the sensor at left, middle
and right position of AT-BOT
L14.4 Place the robot on the white surface. Read and record the reading values which
are displayed on the AT-BOT .
If all 3 sets of the sensing boards read similar values, you will average all values. The
value is about 900 in this step from the test.
mid
right
(ADC0)
(ADC1)
(ADC2)
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
15 PC7
BATTERY LEVEL
45 ADC5
49
PC6
ADC7
SERVO PORT
9 10 11 12 13
c o n t r o l l er R b o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
L14.5 Place the robot above the black line and then read and record a measured value
which is shown on the LCD module.
All 3 sets of the sensing boards should read similar values. At this step in this test,
the average is about 100.
mid
right
(ADC1)
(ADC2)
ON
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
14
SW1
SW2
48
MOTOR
44 ADC4
50
PC7
BATTERY LEVEL
15
45 ADC5
49
PC6
ADC7
10 11 12 13
SERVO PORT
c o nt r o l l erR b o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
USB DATA
E2
RESET
7.2-9V BATT.
START
Experiment 15
Frame detection robot
This experiment demonstrates about controlling AT-BOT robots to move within a
rectangular frame with curve corners surrounded with black lines. This experiment use
only 2 of ZX-03R sensors that is left and right front position.
Procedure
L15.1 Create the new sketch file. Type the Listing L15-1 and save as robo_inner.pde file.
L15.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L15.3 Place the AT-BOT within the frame of the test field that making in Expeirment 14.
L15.4 Run the program.
AT-BOT display shows the title message :
Press SW1
L15.5 Press the SW1 button on the AT-BOT. Observe the robot operation.
AT-BOT will move within the black frame. If the sensor detect the black line, robot
will move backward and change direction similar the object avoider robot activity in
chapter 7 but changing from inspection of bumping to inspection of black lines and white
surface instead.
#include <atx.h>
// Include the main library
#define POW 80
// Set the motor power to 60%
#define REF 500
// Set the reference value as 500
unsigned int left,right;
// Declare the ZX-03R sensor variable
void forward(unsigned int time)
// Moving forward function
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for moving forward
}
void backward(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for moving backward
}
void turn_left(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for turning left
}
void turn_right(unsigned int time)
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for turning right
}
void setup()
{
lcd("SW1 Press!");
// Display title message for asking to press the SW1
sw1_press();
// Wait until the SW1 is pressed
}
void loop()
{
left = analog(0);
// Read the left sensor data
// to store to the variable left
right = analog(2);
// Read the left sensor data
// to store to the variable right
if(left>REF && right>REF)
// Verify both sensor still not
// detect the black line
{
forward(1);
// No line detect,
// move forward for short time
}
else if(left<REF && right>REF)
// Only the left sensor detect line ?
{
backward(500);
turn_right(800);
}
else if(left>REF && right<REF)
{
backward(500);
turn_left(800);
}
else if(left<REF && right<REF)
{
backward(500);
turn_left(1500);
}
Code explanation
When the program runs, at the LCD module there is message Press SW1 to wait for
pressing the SW1 button. After SW1 is pressed, CPU operate within the loop function to repeat
reading values from the ZX-03R sensors at ADC0 (left) and ADC2 (right) input of AT-BOT to store
at the variable left and right respectively. The values will be compared with the reference value
later. Therefore, the robot would have found the white surface or black lines.
If any ZX-03R sensor has the result value greater than REF (reference value equal 500),
the robot will decide that it has found the white surface. On the other hand, if the result value is
less than REF, the robot will consider that it has detected black lines already.
Then, the program will compare values of both variables based on 4 cases as follows:
1. if(left>REF && right>REF) : it is verification that the sensors have not detected
any line, true or not. If it is true (not found any strip), this will react to the robot to move
forward.
2. else if(left<REF && right>REF) : it is checking that the left sensor has found
only one line, true or not. If it is true (found a line or a black frame), this will respond to the
robot to back and then turn right in order to change the direction of motion.
3. else if(left>REF && right<REF) : it is examination that the right sensor has
detected only one line, true or not. If it is true (detected a line or black frame), it will affect the
robot to move backwards and then turn left to alter the direction of movement.
4. else if(left<REF && right>REF) : it is checkup that both side sensors have
found lines, true or not. It is true (discovered a line or black frame), will take action to the robot
moving back and turn left in order to change the direction of locomotion.
Note: REF value for comparing lines and surface in this experiment is 500, which comes from
the experiment 14. Developers may have different reference values depending on other external
factors, such as the amount of illumination from the sun around a test field, incandescent light
bulbs, or other light sources, including distance from sensors to the field floor.
Experiment 16
AT-BOT with the Zigzag movement
This is an additional example of searching and detecting lines of the AT-BOT by
specifying that there are 2 parallel black lines. Then, the robot will be released to move
along the direction that is an angle about 45 degrees with a black line and the robot will
move straight constantly until it has detected a line and then turns. AT-BOT continues moving
forward till it will found a line again, so it will turn to another direction again. Normally, it
at least 30cm.
works like this so on. Therefore, the robot has a route of zigzag motion between both black
lines as the following figure.
During the zigzag movement in this experiment, use only 2 of ZX-03R sensors in the
left and right front like the experimet 15.
Procedure
L16.1 Create the new sketch file. Type the Listing L15-1 and save as robo_pingponf.pde
L16.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L16.3 Place the robot at the start point at an angle about 45 degrees with a black line.
#include <atx.h>
// Include the main library
#define POW 80
// Set the motor power to 60%
#define REF 500
// Set the reference value as 500
unsigned int left,right;
// Declare the ZX-03R sensor variable
void forward(unsigned int time)
// Moving forward function
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for moving forward
}
void backward(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for moving backward
}
void turn_left(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for turning left
}
void turn_right(unsigned int time)
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for turning right
}
void setup()
{
lcd("SW1 Press!");
// Display title message for asking to press the SW1
sw1_press();
// Wait until the SW1 is pressed
}
void loop()
{
left = analog(0);
// Read the left sensor data
// to store to the variable left
right = analog(2);
// Read the left sensor data
// to store to the variable right
if(left>REF && right>REF)
// Verify both sensor still not
// detect the black line
{
forward(1);
// No line detect,
// move forward for short time
}
}
Code explanation
Starting the program with show the message to ask pressing the SW1 button at the LCD
of AT-BOT. After SW1 is pressed, CPU will start working in the loop function to repeat reading
values of the ZX-03R sensors from ADC0 (left) and ADC1 (right) to store at the variable left and
right respectively. Verify and check which sensor can detect black lines similar the previois
experiment. Then, compare both variable values as follows:
1. if(left>REF && right>REF) : it is verification that both side sensors have not
found any line, true or not. If it is true (not found any strip), this will react to the robot to move
forward continuously.
2. else if(left<REF && right>REF) : it is checking that the left sensor has found
only one line, true or not. In this case, it is interpreted that the robot has found the upper border
line. The program will define the robot to turn right to avoid the line. Program developers can
modify a delay time value in turning to have a turning angle as required.
3. else if(left>REF && right<REF) : it is examination that the right sensor has
detected only one line, true or not. If it is true, in this case will interpret that the robot has found
the lower border line. Then, the program will control the robot to turn left to be out of the line.
4. else if(left<REF && right>REF) : it is checkup that the line sensors in both
sides have found lines, true or not. If it is true (discovered a line), will react to the robot moving
back for a short time to be away from the line.
Moreover, developers may add commands to instruct robots turning around and turn with
other different angles in order to create the type of complete zigzag movement, may involving
adjusting the position and the distance of the line sensors from the floor and mechanical
adjustments as necessary to make the motion of the robot follow the requirement.
Press SW1
L16.5 Press the SW1 button on the AT-BOT. Observe the robot operation.
The AT-BOT will move straight constantly until it has found a line, it will turn with an
angle about 90 degrees. Then, it will go ahead again till it finds a line of another side, so it
will turn and walk forward to turn back to another side in a zigzag motion. Normally, the
robot will move between black lines of both sides and program developers have to observe
whether the movement of the robot and the angle of turning to change a direction are
suitable or not. If it is not complete enough, program developers can adjust appropriate
delay time value for turning in the program until the function of the robot is satisfied.
Experiment 17
Line tracking robot using 2 sensors
After learning and testing the line detection from the experiment 15 and 16, In this
experiment presents the line tracking robot activity by using 2 of ZX-03R sensors. The
demonstration field of this experiment is shown in the figure L17-1. The conditions to act the
mission as follows:
1. Robot moves along the black line.
2. When detect the junction, robot must stop for 3 seconds .
Operation :
(ADC2)
right
Operation :
right
(ADC0)
(ADC2)
Operation :
right
(ADC0)
(ADC2)
Operation :
Procedure
L17.1 Create the new sketch file. Type the Listing L15-1 and save as robo_line1.pde
L17.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L17.3 Place the robot bestride the black line of the field.
L17.4 Run the program.
AT-BOT display shows the title message :
Press SW1
#include <atx.h>
#define POW 80
#define REF 500
unsigned int left,right;
void forward(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void backward(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void turn_left(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void turn_right(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void setup()
{
lcd("SW1 Press!");
sw1_press();
}
void loop()
{
left = analog(0);
right = analog(2);
if(left>REF && right>REF)
//
//
//
//
//
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
forward
forward
forward
forward
forward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
backward
backward
backward
backward
backward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 backward
Motor-1 backward
Motor-2 forward
Motor-3 forward
turning left
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 forward
Motor-1 forward
Motor-2 backward
Motor-3 backward
turning right
//
//
//
//
//
//
{
forward(1);
}
}
Experiment 18
Line tracking robot using 3 sensors
This experiment is continuing of the experiment 17 by adding a ZX-03 sensor to apply
as the third line sensor. It will be installed at the middle position between the left and the
right sensor (In the experiment 17, if you did not take out the middle sensor at the bottom of
robot chasis, you will use it in this study). This is to help the AT-BOT able to detect the crossline
or junction better. For the test field, still use the same layout as the experiment 17 as well as
the hardware connection. The additional sensor is to connect with ADC1 port of AT-BOT.
The functioning conditions of AT-BOT robots in this study include:
1. A robot must move along the black line.
2. When a robot has discovered the crossline, it needs to stop and wait at the
junction for 3 seconds. And then, it will move on.
mid
right
(ADC0)
(ADC1)
(ADC2)
Operation :
mid
right
(ADC1)
(ADC2)
Operation :
mid
right
(ADC0)
(ADC1)
(ADC2)
Operation :
mid
right
(ADC1)
(ADC2)
Operation :
mid
right
(ADC0)
(ADC1)
(ADC2)
Operation :
mid
right
(ADC1)
(ADC2)
Operation :
Procedure
L18.1 Create the new sketch file. Type the Listing L18-1 and save as robo_line2.pde
L18.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L18.3 Place the robot bestride the black line of the field.
L18.4 Run the program.
AT-BOT display shows the title message :
Press SW1
L18.5 Press the SW1 button on the AT-BOT. Observe the robot operation.
Robot moves along the black line and stop for 3 seconds when detect the junction.
After that moves along line continually.
#include <atx.h>
#define POW 80
#define REF 500
unsigned int left,middle,right;
void forward(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void backward(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void turn_left(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void turn_right(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void setup()
{
lcd("SW1 Press!");
sw1_press();
}
void loop()
{
left = analog(0);
//
//
//
//
//
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
forward
forward
forward
forward
forward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
backward
backward
backward
backward
backward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 backward
Motor-1 backward
Motor-2 forward
Motor-3 forward
turning left
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 forward
Motor-1 forward
Motor-2 backward
Motor-3 backward
turning right
Code explanation
There are 4 conditions of the sensor operation to control the AT-BOT movement.
1. if(left>REF && mid<REF && right>REF) : it is checking about the robot still
bestride the line or not. If true, robot will move forward with a short time
2. else if(left<REF && mid>REF && right>REF) : it is checking about the robot
moves rightward away of the line or not. If true, robot is controlled to spin left with a short time
to back to bestride the line again.
3. else if(left>REF && mid>REF && right<REF) : it is checking about the robot
moves leftward away of the line or not. If true, robot is controlled to spin right with a short time
to back to bestride the line again.
4. else if(left<REF && mid<REF && right<REF) : it is checking about the robot
found the crossline or not. If true, it will stop at the junction for 3 seconds after that moves
forward 0.3 second to over the crossline.
Additional conclusion
From the experiment 17 and 18, the robot moves along the line with same concept
but their difference is the number of line sensors because the test field is not much
complexity so the application of only 2 line sensors can accommodate. However, in case
that a test field is more complex such as a left junction and a right junction available.
Using 3 line sensors will be more efficient than only 2 sensors. Consideration of comparable
cases will be shown as follows:
left
(ADC0)
(ADC2)
left
(ADC0)
(ADC2)
right
right
The result is only the left sensor detects the black line. It is inconclusive. Now,
the robot is moving out of the line to the right or straight to the left junction.
mid
right
(ADC1)
(ADC2)
With this techniques, the left and middle sensors will detect lines.
The conclusion is clear that now the robot is moving straight to the left junction.
left
right
left
right
(ADC0)
(ADC2)
(ADC0)
(ADC2)
The result is only the right sensor detects the black line. It is inconclusive.
Now, the robot is moving out of the line to the left or straight to the right junction.
With this techniques, the right and middle sensors will detect lines.
The conclusion is clear that now the robot is moving straight to the right junction.
Experiment 19
Advance line tracking robot
This experiment expands on the experiment 18 by adding the complexity of the
test field and further conditions of movement along lines as shown in the figure L19-1. ATBOT robots have to use 3 line sensors in the operation of this mission. The conditions of the
functioning compose of:
1. The robot has to be released from the start point.
2. The robot has to move to pass the left and the right crossroads of the way to
the triple junction.
3. When the robot has arrived to the junction, it must turn left and move along
the line in clockwise direction.
Procedure
L19.1 Create the new sketch file. Type the Listing L18-1 and save as robo_line3.pde
L19.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
START
Junction with
crossline
Figure L19-1 : The test field of the advance line tracking robot in the
experiment 19
#include <atx.h>
#define POW 80
#define REF 500
unsigned int left,middle,right;
void forward(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void backward(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void turn_left(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void turn_right(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void setup()
{
lcd("SW1 Press!");
sw1_press();
}
void loop()
{
left = analog(0);
//
//
//
//
//
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
forward
forward
forward
forward
forward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
backward
backward
backward
backward
backward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 backward
Motor-1 backward
Motor-2 forward
Motor-3 forward
turning left
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 forward
Motor-1 forward
Motor-2 backward
Motor-3 backward
turning right
{
turn_left(10);
// Spin left 0.01 second for trying to bestride the line
}
else if(left>REF && mid>REF && right<REF)
// Check the robot to move leftward away of the line
{
// Spin right 0.01 second for trying to bestride the line
turn_right(10);
}
else if(left<REF && mid<REF && right>REF)
// Check the robot to detect the left junction
{
forward(10);
// Move forward 0.01 second to pass the left junction
}
else if(left>REF && mid<REF && right<REF)
// Check the robot to detect the right junction
{
forward(10);
// Move forward 0.01 second to pass the right junction
}
else if(left<REF && mid<REF && right<REF)
// Check the robot to detect the crossline
{
// Move forward 0.1 second to pass the crossline
forward(100);
turn_left(200);
// Spin left 0.2 second for trying to bestride the line
// at the crossline again
}
}
Code explanation
There are 6 conditions of the sensor operation to control the AT-BOT movement.
1. if(left>REF && mid<REF && right>REF) : it is checking about the robot still
bestride the line or not. If true, robot will move forward with a short time
2. else if(left<REF && mid>REF && right>REF) : it is checking about the robot
moves rightward away of the line or not. If true, robot is controlled to spin left with a short time
to back to bestride the line again.
3. else if(left>REF && mid>REF && right<REF) : it is checking about the robot
moves leftward away of the line or not. If true, robot is controlled to spin right with a short time
to back to bestride the line again.
4. else if(left<REF && mid<REF && right>REF) : it is checking about the robot
detect the left junction or not. If true, robot will move forward to pass this junction.
5. else if(left>REF && mid<REF && right<REF) it is checking about the robot
detect the right junction or not. If true, robot will move forward to pass this junction.
6. else if(left<REF && mid<REF && right<REF) : it is checking about the robot
found the crossline or not. If true, robot will move forward 0.1 second and turn left 0.3 second
after that back to check all line tracking conditions continually
L19.3 Place the robot bestride the black line of the field.
L19.4 Run the program.
AT-BOT display shows the title message :
Press SW1
L18.5 Press the SW1 button on the AT-BOT. Observe the robot operation.
The robot AT-BOT will move along the black line until the robot has found the
triple junction, it will turn left and move along the curve in the clockwise direction constantly.
Start
Junction with
crossline
More information
From the previous experiments, the test fields have black strips and white surface.
If you will change to black surface and white lines, programming to control functioning
will be able to use the principles of line and surface analysis of the experiment 14 and the
principles of driving robots from the experiment 15 to 18 as guidelines of program
development.
For example, if you would like to test that a robot has found any crossline or not.
In the case that the field surface is white and the strips are black, apply this
condition to check.
else if(left<REF && mid<REF && right<REF)
But if the field surface is black and the strips are white, use this condition to verify.
else if(left>REF && mid>REF && right>REF)
Because strips have become white, if read a value from a line sensor of each
position and it shows that the value is greater than the reference value. Hence, the line
sensor of that position has found a white line.
Experiment 20
Line tracking robot with the white line mission
This experiment represents a guideline of the control program development for ATBOT to move along the white lines on a black surface. The appearance of the test field in
this experiment is opposite to that of the experiment 15 to 19, by which the test field in this
trial has the same feature with which of the experiment 18 but colors are changed that
black lines converts to white lines and the white surface change to black surface as
demonstrated in the figure L20-1.
The conditions of functioning include:
1. The robot must move along the white line.
2. When the robot detects the crossline, it will have to stop and wait for 3 seconds
approximately and then it will move on.
Figure L20-1 : The test field for Line tracking robot in the experiment 20
mid
right
(ADC1)
(ADC2)
Operation :
mid
right
(ADC0)
(ADC1)
(ADC2)
Operation :
mid
right
(ADC1)
(ADC2)
Operation :
mid
right
(ADC0)
(ADC1)
(ADC2)
Operation :
mid
right
(ADC1)
(ADC2)
Operation :
mid
right
(ADC0)
(ADC1)
(ADC2)
Operation :
Procedure
L20.1 Create the new sketch file. Type the Listing L20-1 and save as robo_line4.pde
L20.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L20.3 Place the robot bestride the white line of the field.
L20.4 Run the program.
AT-BOT display shows the title message :
Press SW1
L20.5 Press the SW1 button on the AT-BOT. Observe the robot operation.
Robot moves along the white line and stop for 3 seconds when detect the junction.
After that moves along line continually.
#include <atx.h>
#define POW 80
#define REF 500
unsigned int left,middle,right;
void forward(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void backward(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,-POW);
motor(3,-POW);
sleep(time);
}
void turn_left(unsigned int time)
{
motor(0,-POW);
motor(1,-POW);
motor(2,POW);
motor(3,POW);
sleep(time);
}
void turn_right(unsigned int time)
{
motor(0,POW);
motor(1,POW);
motor(2,-POW);
//
//
//
//
//
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
forward
forward
forward
forward
forward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0
Motor-1
Motor-2
Motor-3
moving
backward
backward
backward
backward
backward
//
//
//
//
//
Drive
Drive
Drive
Drive
Delay
the
the
the
the
for
Motor-0 backward
Motor-1 backward
Motor-2 forward
Motor-3 forward
turning left
motor(3,-POW);
sleep(time);
}
void setup()
{
lcd("SW1 Press!");
sw1_press();
}
void loop()
{
left = analog(0);
Chapter 9
AT-BOT with touchless object avoiding
In this chapter, it will present the application of a sensing module and a distance
measurement with the infrared distance sensor or Infrared ranger GP2D120 with AT-BOT. .
As the result, the AT-BOTs have ability to detect objects without contact with objects.
Therefore, the robots are able to go straight or avoid more wisely.
Infrared LED
Infrared Receiver
GP2D120
1.6
1.2
0.8
0.4
Supply
0
38.39.6 ms
Measurement
Vout
1st measure
Not stable
12
16
20
24
28
32
Distance (cm)
2nd measure
1st output
n
measure
2nd output
n output
5 ms
GP2D120 module
GP2D120
Front of the
AT-BOT
GP2D120
43 ADC3
42 ADC2
41 ADC1
40 ADC 0
46 ADC6
SW1
SW2
45 ADC5
49
44 ADC4
50
48
MOTOR
BATTERY LEVEL
ADC7
SERVO PORT
PC6
15 PC7
c o n t r o l l er R b o a r d
KNOB
14
44 ADC4
45 ADC5
9 10 11 12 13
46 ADC6
40 ADC 0
48
USB DATA
41 ADC1
50
MOTOR
7.2-9V BATT.
42 ADC2
SW2
15 PC7
BATTERY LEVEL
START
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
43 ADC3
49
PC6
14
SW1
c o n t r o l l er R b o a r d
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
ADC7
SERVO PORT
9 10 11 12 13
S
E2
RESET
USB DATA
KNOB
ON
ON
E2
RESET
7.2-9V BATT.
connect to ADC3
START
(4) Plug the signal cable of the GP2D120 to ADC3 port of the AT-BOT robot that can
detect the obstacles without any contact and be ready for the programming later on.
Experiment 21
Distance meaturement by GP2D120
This experiment is a programming to read distance values from the module GP2D120
by which the readable values are shown at the LCD module of AT-BOT.
Procedure
L21.1 Create the new sketch file. Type the Listing L21-1 and save as gp2d120_test.pde
L20.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
#include <atx.h>
//
#include <gp2d120_lib.h>
//
unsigned int dist;
//
void setup()
{}
void loop()
{
dist = getdist(3);
//
if(dist>=4 && dist<=32)
//
{
lcd(Distance: %d cm ,dist); //
}
else
{
lcd(Out of Range!
);
//
//
}
sleep(100);
//
}
out of range
Code explanation
The distance value that read from GP2D120 with getdist function is stored in the variable
dist. Then, the value will be analyzed whether it is in the range of 4 to 32cm. or not before
displayed at the LCD module. If the value is less than 4 and greater than 32, it is considered that
the data is not reliable. After this, the message as Out of Range! will be displayed at the LCD
module.
Distance: xxx cm
therefore xxx is the distance value in centimetre unit.
and displays the message
Out of Range!
when the distance value is out of the range 4 to 32cm.
L21.4 Put an object or your hand to block in the front of the GP2D120 in the operating
distance, which is 4 to 32 cm. Then, move in and away the object from the GP2D120.
Finally, monitor the readable distance value at the LCD module.
If the object is in the operating distance of the GP2D120, at the LCD module, there
will be a display of the distance value in centimetre. But if the object is not in the operating
distance, at the LCD module will be displayed the message Out or Range!, instead.
4cm.
7.2-9V BATT.
14
PC6
15 PC7
MOTOR
+
S
10 11 12 13
BATTERY LEVEL
SERVO PORT
0
RESET
KNOB
ADC7
SW1
49
SW2
50
48
move object
E2
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
ON
USB DATA
GP2D120
c o n t r o l l er R b o a r d
C r e a t o r e > >> > > > > >
4
43 ADC3
42 ADC2
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
START
connect to ADC3
32cm.
Experiment 22
Touchless object avoiding robot
This is the ability development of AT-BOT robos. Previously, AT-BOT used to avoid
obstacles by bumping. However, this experiment is different from the mentioned experiment
that this experiment will use the GPD120 sensor to help for detecting and avoiding the
obstacles without contact. There are conditions of functioning as follows:
1. In case that a robot does not detect any obstruction in the distance of 14 cm.
The robot will move forward.
2. In case that a robot finds obstruction in the distance less than 14 cm. The
robot will move backwards and then turn left to change the movement direction.
Procedure
L22.1 Create the new sketch file. Type the Listing L22-1 and save as robo_ranger.pde
L22.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L22.3 Place the robot on the floor. Place some obstacle such as box or can to set the
demonstration field.
L22.4 Run the program.
AT-BOT display shows the title message : Press SW1
L18.5 Press the SW1 button on the AT-BOT. Observe the robot operation.
The AT-BOT will go straight constantly. When the robot will be able to detect
obstruction, it will reverse and turn left. After that, the AT-BOT will move forward in order to
avoid the obstruction. If the robot turns around and finds an object, it will go backward
again and turn left. The pattern will be repeated until the robot will be able to pass objects
and move straight later on.
Obstacle
Obstacle
Obstacle
Obstacle
#include <atx.h>
// Include the main library
#include <gp2d120_lob.h>
// Include the GP2D120 library
#define POW 80
// Set the motor power to 80%
unsignd int dist;
// Declare the distance variable
void forward(unsigned int time)
// Moving forward function
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for moving forward
}
void backward(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for moving backward
}
void turn_left(unsigned int time)
{
motor(0,-POW);
// Drive the Motor-0 backward
motor(1,-POW);
// Drive the Motor-1 backward
motor(2,POW);
// Drive the Motor-2 forward
motor(3,POW);
// Drive the Motor-3 forward
sleep(time);
// Delay for turning left
}
void turn_right(unsigned int time)
{
motor(0,POW);
// Drive the Motor-0 forward
motor(1,POW);
// Drive the Motor-1 forward
motor(2,-POW);
// Drive the Motor-2 backward
motor(3,-POW);
// Drive the Motor-3 backward
sleep(time);
// Delay for turning right
}
void setup()
{
lcd("SW1 Press!");
// Display title message for asking to press the SW1
sw1_press();
// Wait until the SW1 is pressed
}
void loop()
{
dist = getdist(3);
// Read the distance from GP2D120 at ADC3 input
if(dist>=4 && dist<15)
// Found the object within 4 to 14cm. or not ?
{
backward(500);
// If found, move backward 0.5 second
turn_left(800);
// Spin left 0.8 second
}
// to change the movement direction
else
{
forward(1);
// Move forward with a short time
}
}
Code explanation
At the beginning of the program, there will be a display of the text Press SW1 at the LCD
module. When pressing the SW1 is done, the CPU will operate in the loop function to repeat
reading values from the GP2D120, which is connected to the ADC3 input.
Those values will be collected at the variable dist. Then, the program will take distance
values to compare based on these cases:
1. if(dist>=4 && dist<15) : it is verification that if the robot finds an object in the
range of 4 to 14 cm. or not. If it is true (a barrier present), the program will respond the robot
by moving backward and turning left to avoid the obstruction.
2. else : if the condition of the case 1 is not true, that is meant that there is no barrier
in the interesting distance, so the AT-BOT is designed to move forward.
More information
The development of the control program for AT-BOTs cooperated with the GP2D120 will
run the getdist function from the gp2d120_lib.h library to read distance values from barriers
in the centimetre.
Chapter 10
AT-BOT with Servo motor
In this chapter, it will introduce the control of servo motors of the AT-BOT. It can
drive 6 of 4.8 to 6V R/C servo motors through the ports 8 to 13.
Horn
Plug
Cable
STANDARD
SERVO MOTOR
Case
Figure 10-2 : Standard Servo motor Figure 10-3 : Standard Servo motor
cable assignment
plug type
Controlling of the servo motors is used to pulse controlling. The control pulse is positive
going pulse with length of 1 to 2 ms which is repeated about 50 to 60 times a second. You
can check the details in the figure 10-4. Start by generating a pulse a period 20 millisecond
and adjust the positive pulse width 1 millsecond. The servo motor will move the horn to last
left position. The pulse width 1.5 millisecond move the servo horn to center and pulse
width 2 millsecond causes the servo horn to last right position.
The important specification of servo motor are 2 points, Speed or Servo turn rate or
transit time and Torque. The servo turn rate, or transit time, is used for determining servo
rotational velocity. This is the amount of time it takes for the servo to move a set amount,
usually 60 degrees. For example, suppose you have a servo with a transit time of 0.17sec/
60 degrees at no load. This means it would take nearly half a second to rotate an entire
180 degrees. More if the servo were under a load. This information is very important if high
servo response speed is a requirement of your robot application. It is also useful for
determining the maximum forward velocity of your robot if your servo is modified for full
rotation. Remember, the worst case turning time is when the servo is at the minimum
rotation angle and is then commanded to go to maximum rotation angle, all while under
load. This can take several seconds on a very high torque servo.
Torque is the tendency of a force to rotate an object about an axis. The torque
unit is ounce-inches (oz-in) or kilogram-centimetre (kg-cm). It tell you know about this servo
motor can drive a load weight in 1 oz. to move 1 inche or 1kg. weight to moved 1
centimeter (1oz. = 0.028kg. or 1kg. = 25.274oz.). Normally the RC servo motor has 3.40 kgcm/47oz-in torque.
1 to 2 millsecond pulse
1 millisecond pulse
STANDARD
SERVO MOTOR
STANDARD
SERVO MOTOR
2 millisecond pulse
STANDARD
SERVO MOTOR
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
The power supply voltage of servo motors comes from a battery connected with
the circuit board of ATX through the control circuit of the constant power supply. At +6V
can supply the electric current 1500mA, so it can be applied to all models of small servo
motors, which use the power supply in the range of 4.8 to 6V.
c o n t r o l l er R b o a r d
USB DATA
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
E2
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
9
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RESET
14
PC6
15 PC7
MOTOR
Syntax
void servo(unsigned char _ch, int _pos)
Parameter
_ch - Servo motor output (8 to 13)
Define as 8 for servo motor output #1 (8)
Define as 9 for servo motor output #2 (9)
Define as 10 for servo motor output #3 (10)
Define as 11 for servo motor output #4 (11)
Define as 12 for servo motor output #5 (12)
Define as 13 for servo motor output #6 (13)
_pos - Set the sevo motor shaft poistion (0 to 180 and -1)
If set to -1, disable selected servo motor output
Experiment 23
AT-BOT controlled the servo motor
In this experiment presents about how to test the positional control of the servo
motorat ch. 10 of an AT-BOT by pressing the SW1 (adding a positional value) and SW2
(reducing a position value) swithes as well as monitoring a value of the reference position
of the servo motor. The reference position value will be shown at the LCD module on the
AT-BOT robot.
Procedure
L23.1 Create the new sketch file. Type the Listing L23-1 and save as servo_test.pde
L23.2 Compile and upload the sketch to the AT-BOT. Unplug the USB cable.
L23.3 Run the program.
AT-BOT display shows the title message :
Position: xx
41 ADC1
40 ADC0
46 ADC6
45 ADC5
44 ADC4
42 ADC2
43 ADC3
START
Servo motor
Decrease
position
USB DATA
ON
TWI
UART1
0 SCL 1 SDA 2 RX1 3 TX1
KNOB
ADC7
SW1
49
SW2
50
48
SERVO PORT
8
BATTERY LEVEL
10 11 12 13
S
7.2-9V BATT.
RESET
Increase
position
E2
14
PC6
15 PC7
MOTOR
STANDARD
SERVO MOTOR
L23.4 Try to press the SW1 switch on the AT-BOT to increase the postion value.
The servo motor shaft is driven to upper position. Also at the display of AT-BOT shows
the position value. However if the value is greater than 90 greatly, tthe servo motor may
not stable to maintain position.
L23 .5 Press the SW2 switch on the AT-BOT to decrease the postion value.
The servo motor shaft is driven to lower position. At the display of AT-BOT shows the
position value. However if the value is less than 20 greatly, the servo motor may not stable
to maintain position also.
Note: About the positional range of servo motors, each manufacturer may have
different positional range or direction of position. Therefore, developers have to create
programming about testing positional values of servo motors in order to know how many
a positional value is in the control program when you need to control a servo motor to be
located at a desired position.
#include <atx.h>
unsigned int pos=0;
void setup()
{}
void loop()
{
lcd(Position: %d
servo(10,pos);
if(sw1()==0)
{
pos++;
sleep(100);
}
if(sw2()==0)
{
pos - - ;
sleep(100);
}
}
,pos);
Code explanation
The program will operate in the loop function to repeat showing the result of the positional
values of the servo motor at port 10 of AT-BOT and define the values constantly. At the same
time, the function will verify addition and deduction of the positional values of servo motor shaft
form pressing the switches SW1 and SW2 respectively. The program will work like this repeatedly
and continuously.