Pololu 3pi Guía De Usuario página 18

Tabla de contenido

Publicidad

101.
print_long(bat);
1
02.
print("mV");
103.
lcd_goto_xy(0,1);
104.
print("Press B");
105.
delay_ms(100);
106.
}
107.
// Always wait for the butt
108.
// start moving until yo
109.
wait_for_button_release(BUTTON_B);
110.
delay_ms(1000);
111.
// Auto-calibration: turn right and left while calib
112.
// sensors.
113.
for(counter=0;count
114.
{
115.
if(counter < 20 || counter >= 60)
116.
set_motors(40,-40);
117.
else
118.
set_motors(-40,40);
119.
// This function records a se
120.
// track of the minimum and
121.
// IR_EMITTERS_ON argument means that the IR LEDs will be
122.
// turned on during the reading, which is usually what you
123.
// want.
124.
calibrate_line_sensors(IR_EMITTERS_ON);
125.
// Since our counter runs to 80, the total delay will be
126.
// 80*20 = 1
127.
delay_ms(20);
128.
}
129.
set_motors(0,0);
130.
// Display calibrated v
131.
while(!button_is_pr
132.
{
133.
// Read the sensor values and get the position m
134.
unsigned int position = read_line(se
135.
// Display the position measurement, which will go from 0
136.
// (when the leftmost sensor is over the line) to 4000 (when
137.
// the rightmost sensor is over the line) on the 3pi, along
138.
// with a bar graph of the sensor readings.
139.
// to make sure the robot is ready to go.
140.
clear();
141.
print_long(position);
142.
lcd_goto_xy(0,1);
143.
display_read
144.
delay_ms(100);
145.
}
146.
wait_for_button_release(BUTTON_B)
147.
clear();
148.
print("Go!");
149.
// Play music and wait for it to finish b
150.
play_from_program_space(
151.
while(is_playing());
152.
}
153.
// This is the main function, where
154.
// must have a main() funct
155.
int main()
156.
{
157.
unsigned int sensors[5]; // an array to hold senso
158.
// set up the
159.
in
itialize
160.
// This is the "main loop" - it will run forever.
161.
while(1)
162.
{
163.
// Get the position of the line.
164.
// the "sensors
165.
// are not interested in the individual sensor readings.
166.
unsigned int position = read_line(sensors,IR_EMITTERS_ON);
167.
if(position < 1000)
168.
{
169.
// We are far to the right of the line: turn left.
170.
// Set the right motor to 100
171.
// to do a sharp turn to the left.
172.
// value of either motor speed is 255, so we are driving
173.
// it at just about 40% of the max.
174.
set_motors(0,100);
175.
// Just for fun, indicate the direction we are turning on
176.
// the LEDs.
177.
left_led(1);
178.
right_led(0);
179.
}
180.
else if(position < 3
on to be released so that 3pi doesn't
ur
hand is away from it.
er<80;counter++)
t of sensor r
maximum values encountered.
600 ms.
alues as a bar graph.
essed(BUTTON_B))
ings(sensors);
go);
ion def
3pi
();
" argument to read_line() here, even though we
and the left motor to zero,
000)
rating the
eadings and keeps
easurement.
nsors,IR_EMITTERS_ON);
This allows you
;
efore we start driving.
the code starts.
ined somewhere.
r values
Note that we must p
rovide
Note that the max
imum
The
All C program
s

Publicidad

Tabla de contenido
loading

Productos relacionados para Pololu 3pi

Tabla de contenido