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

Tabla de contenido

Publicidad

173.
// clear the slave's LCD and display "Connect" and "OK" on two lines
174.
// Put OK in the center to test x-y positioning
175.
slave_clear();
176.
slave_print("Connect");
177.
slave_lcd_goto_xy(3,1);
178.
slave_print("OK");
179.
// play a tune
180.
char tune[] = "\xB3 l16o6gab>c";
181.
tune[1] = sizeof(tune)-3;
182.
serial_send_blocking(tune,sizeof(tune)-1);
183.
// wait
184.
wait_for_button(ALL_BUTTONS);
185.
// reset calibration
186.
slave_reset_calibration();
187.
time_reset();
188.
slave_auto_calibrate();
189.
190.
// read sensors in a loop
191.
while(1)
192.
{
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
}
243.
}
(1);
244.
while
245.
}
char
unsigned
speed1 = 0, speed2 = 0;
serial_send("\x87",1);
// read 10 characters
if(serial_receive_blocking(buffer, 10, 100))
break;
// get the line position
serial_send("\xB6", 1);
int line_position[1];
if(serial_receive_blocking((char *)line_position, 2, 100))
break;
// get the battery voltage
serial_send("\xB1",1);
// read 2 bytes
int battery_millivolts[1];
if(serial_receive_blocking((char *)battery_millivolts, 2, 100))
break;
// display readings
display_levels((unsigned int*)buffer);
lcd_goto_xy(5,0);
line_position[0] /= 4;
if(line_position[0] == 1000)
line_position[0] = 999;
print_long(line_position[0]);
print("
");
lcd_goto_xy(0,1);
print_long(battery_millivolts[0]);
print(" mV
");
delay_ms(10);
// if button A is pressed, increase motor1 speed
if(button_is_pressed(BUTTON_A) && speed1 < 127)
speed1 ++;
else if(speed1 > 1)
speed1 -= 2;
else if(speed1 > 0)
speed1 = 0;
// if button C is pressed, control motor2
if(button_is_pressed(BUTTON_C) && speed2 < 127)
speed2 ++;
else if(speed2 > 1)
speed2 -= 2;
else if(speed2 > 0)
speed2 = 0;
// if button B is pressed, do PID control
if(button_is_pressed(BUTTON_B))
slave_set_pid(40, 1, 20, 3, 2);
else
{
slave_stop_pid();
slave_set_motors(speed1, speed2);
}
// returns calibrated sensor values
// to get it into the range of 0-1000
// to keep it to a maximum of 3 characters

Publicidad

Tabla de contenido
loading

Productos relacionados para Pololu 3pi

Tabla de contenido