Pololu 3pi Robot User Manual

Page 52

Advertising
background image

}

// 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.

char check_data_byte(char byte)

{

if(is_data(byte))

return 0;

play("o3c");

clear();

print("Bad data");

lcd_goto_xy(0,1);

print_hex_byte(byte);

previous_byte();

return 1;

}

/////////////////////////////////////////////////////////////////////

// COMMAND FUNCTIONS

//

// Each function in this section corresponds to a single serial

// command. The functions are expected to do their own argument

// handling using read_next_byte() and check_data_byte().

// Sends the version of the slave code that is running.

// This function also shuts down the motors and disables PID, so it is

// useful as an initial command.

void send_signature()

{

serial_send_blocking("3pi1.0", 6);

set_motors(0,0);

pid_enabled = 0;

}

// Reads the line sensors and sends their values. This function can

// do either calibrated or uncalibrated readings. When doing calibrated readings,

// it only performs a new reading if we are not in PID mode. Otherwise, it sends

// the most recent result immediately.

void send_sensor_values(char calibrated)

{

if(calibrated)

{

if(!pid_enabled)

read_line_sensors_calibrated(sensors, IR_EMITTERS_ON);

}

else

read_line_sensors(sensors, IR_EMITTERS_ON);

serial_send_blocking((char *)sensors, 10);

}

// Sends the raw (uncalibrated) sensor values.

void send_raw_sensor_values()

{

send_sensor_values(0);

}

// Sends the calibated sensor values.

void send_calibrated_sensor_values()

{

send_sensor_values(1);

}

// Computes the position of a black line using the read_line()

// function, and sends the value.

// Returns the last value computed if PID is running.

void send_line_position()

{

Pololu 3pi Robot User's Guide

© 2001–2014 Pololu Corporation

10. Expansion Information

Page 52 of 63

Advertising