Pololu 3pi Robot User Manual
Page 55
![background image](/manuals/570392/55/background.png)
set_motors(-60, 60);
while(get_ms() < 750)
calibrate_line_sensors(IR_EMITTERS_ON);
set_motors(60, -60);
while(get_ms() < 1000)
calibrate_line_sensors(IR_EMITTERS_ON);
set_motors(0, 0);
serial_send_blocking("c",1);
}
// Turns on PID according to the supplied PID constants
void set_pid()
{
unsigned char constants[5];
unsigned char i;
for(i=0;i<5;i++)
{
constants[i] = read_next_byte();
if(check_data_byte(constants[i]))
return;
}
// make the max speed 2x of the first one, so that it can reach 255
max_speed = (constants[0] == 127 ? 255 : constants[0]*2);
// set the other parameters directly
p_num = constants[1];
p_den = constants[2];
d_num = constants[3];
d_den = constants[4];
// enable pid
pid_enabled = 1;
}
// Turns off PID
void stop_pid()
{
set_motors(0,0);
pid_enabled = 0;
}
/////////////////////////////////////////////////////////////////////
int main()
{
pololu_3pi_init(2000);
play_mode(PLAY_CHECK);
clear();
print("Slave");
// start receiving data at 115.2 kbaud
serial_set_baud_rate(115200);
serial_set_mode(SERIAL_CHECK);
serial_receive_ring(buffer, 100);
while(1)
{
// wait for a command
char command = read_next_byte();
// The list of commands is below: add your own simply by
// choosing a command byte and introducing another case
// statement.
switch(command)
{
case (char)0x00:
// slient error - probable master resetting
break;
case (char)0x81:
send_signature();
break;
case (char)0x86:
send_raw_sensor_values();
Pololu 3pi Robot User's Guide
© 2001–2014 Pololu Corporation
10. Expansion Information
Page 55 of 63