1. Calling
pololu_3pi_init
(2000) to set up the 3pi, with the sensor timeout set to 2000×0.4 us
= 800 us. This means that the sensor values will vary from 0 (completely white) to 2000
(completely black), where a value of 2000 indicates that the sensor’s capacitor took at least
800 us to discharge.
2. Displaying the battery voltage returned by the
read_battery_millivolts()
function. It is
important to monitor battery voltage so that your robot does not surprisingly run out of
batteries and shut down during the middle of a competition or during programming. For more
information, see
of the
[https://www.pololu.com/docs/0J18]
3. Calibrating the sensors. This is accomplished by turning the 3pi to the right and left on the line
while calling the
calibrate_line_sensors()
function. The minimum and maximum values read
during this time are stored in RAM. This allows the
read_line_sensors_calibrated()
function
to return values that are adjusted to range from 0 to 1000 for each sensor, even if some of
your sensors respond differently than the others. The
read_line()
function used later in the
code also depends on having calibrated values. For more information, see
of the
[https://www.pololu.com/docs/0J18]
.
4. Displaying the calibrated line sensor values in a bar graph. This demonstrates the use of
the
lcd_load_custom_character()
function together with
print_character()
to make it easy
to see whether the line sensors are working properly before starting the robot. For more
information on this and other LCD commands, see
of the
[https://www.pololu.com/docs/0J18]
.
5. Waiting for the user to press a button. It’s very important for your robot not to start driving
until you want it to start, or it could unexpectedly drive off of a table or out of your hands when
you are trying to program it. We use the
button_is_pressed()
function to wait for you to press
the B button while displaying the battery voltage or sensor readings. For more information
on button commands, see
of the
In the second phase of the program, your 3pi will take a sensor reading and set the motor speed
appropriately based on the reading. The general idea is that if the robot is off on either side, it should
turn to get back on, but if it’s on the line, it should try to drive straight ahead. The following steps occur
inside of a
while(1)
loop, which will continue repeating over and over until the robot is turned off or
reset.
1. The function
read_line()
is called. This takes a sensor reading and returns an estimate of
the robot’s position with respect to the line, as a number between 0 and 4000. A value of
0 means that the line is to the left of sensor 0, value of 1000 means that the line is directly
under sensor 1, 2000 means that the line is directly under sensor 2, and so on.
2. The value returned by
read_line()
is divided into three possible cases:
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
7. Example Project #1: Line Following
Page 28 of 85
Содержание 0J5840
Страница 24: ...Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 5 How Your 3pi Works Page 24 of 85...
Страница 67: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 67 of 85...
Страница 77: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 77 of 85...