63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
if
(power_difference < 0)
set_motors(mapower_difference, max_speed);
else
set_motors(max_speed, max_speed-power_difference);
}
// A global ring buffer for data coming in.
This is used by the
// read_next_byte() and previous_byte() functions, below.
char
buffer[100];
// A pointer to where we are reading from.
unsigned
char
read_index = 0;
// Waits for the next byte and returns it.
Runs play_check to keep
// the music playing and serial_check to keep receiving bytes.
// Calls pid_check() to keep following the line.
char
read_next_byte()
{
while
(serial_get_received_bytes() == read_index)
{
serial_check();
play_check();
// pid_check takes some time; only run it if we don't
// have more bytes to process
if
(serial_get_received_bytes() == read_index)
pid_check();
}
char
ret = buffer[read_index];
read+;
if
(read_index >= 100)
read_index = 0;
return
ret;
}
// Backs up by one byte in the ring buffer.
void
previous_byte()
{
read_index --;
if
(read_index == 255)
read_index = 99;
}
// Returns true if and only if the byte is a command byte (>= 0x80).
char
is_command(
char
byte)
{
if
(byte < 0)
return
1;
return
0;
}
// Returns true if and only if the byte is a data byte (< 0x80).
char
is_data(
char
byte)
{
if
(byte < 0)
return
0;
return
1;
}
// If it's not a data byte, beeps, backs up one, and returns true.
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
10. Expansion Information
Page 69 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...