Pololu 3pi Robot User Manual

Page 58

Advertising
background image

// character, and character 255 (a full black box), we get 10

// characters in the array.

// The variable c will have values from 0 to 9, since

// values are in the range of 0 to 1000, and 1000/101 is 9

// with integer math.

char c = bar_graph_characters[sensors[i]/101];

// Display the bar graph characters.

print_character(c);

}

}

// set the motor speeds

void slave_set_motors(int speed1, int speed2)

{

char message[4] = {0xC1, speed1, 0xC5, speed2};

if(speed1 < 0)

{

message[0] = 0xC2; // m1 backward

message[1] = -speed1;

}

if(speed2 < 0)

{

message[2] = 0xC6; // m2 backward

message[3] = -speed2;

}

serial_send_blocking(message,4);

}

// do calibration

void slave_calibrate()

{

serial_send("\xB4",1);

int tmp_buffer[5];

// read 10 characters (but we won't use them)

serial_receive_blocking((char *)tmp_buffer, 10, 100);

}

// reset calibration

void slave_reset_calibration()

{

serial_send_blocking("\xB5",1);

}

// calibrate (waits for a 1-byte response to indicate completion)

void slave_auto_calibrate()

{

int tmp_buffer[1];

serial_send_blocking("\xBA",1);

serial_receive_blocking((char *)tmp_buffer, 1, 10000);

}

// sets up the pid constants on the 3pi for line following

void slave_set_pid(char max_speed, char p_num, char p_den, char d_num, char d_den)

{

char string[6] = "\xBB";

string[1] = max_speed;

string[2] = p_num;

string[3] = p_den;

string[4] = d_num;

string[5] = d_den;

serial_send_blocking(string,6);

}

// stops the pid line following

void slave_stop_pid()

{

serial_send_blocking("\xBC", 1);

}

// clear the slave LCD

void slave_clear()

{

serial_send_blocking("\xB7",1);

}

Pololu 3pi Robot User's Guide

© 2001–2014 Pololu Corporation

10. Expansion Information

Page 58 of 63

Advertising