User Guide
178. unsigned char i;
179. for(i=0;i<5;i++)
180. {
181. constants[i] = read_next_byte();
182. if(check_data_byte(constants[i]))
183. return;
184. }
185. // make the max speed 2x of the first one, so that it can reach 255
186. max_speed = (constants[0] == 127 ? 255 : constants[0]*2);
187. // set the other parameters directly
188. p_num = constants[1];
189. p_den = constants[2];
190. d_num = constants[3];
191. d_den = constants[4];
192. // enable pid
193. pid_enabled = 1;
194. }
195. // Turns off PID
196. void stop_pid()
197. {
198. set_motors(0,0);
199. pid_enabled = 0;
200. }
201. /////////////////////////////////////////////////////////////////////
202. int main()
203. {
204. pololu_3pi_init(2000);
205. play_mode(PLAY_CHECK);
206. clear();
207. print(“Slave”);
208. // start receiving data at 115.2 kbaud
209. serial_set_baud_rate(115200);
210. serial_set_mode(SERIAL_CHECK);
211.
serial_receive_ring(buffer, 100);
212. while(1)
213. {
214. // wait for a command
215. char command = read_next_byte();
216. // The list of commands is below: add your own simply by
217. // choosing a command byte and introducing another case
218. // statement.
219. switch(command)
220. {
221. case (char)0x00:
222. // slient error - probable master resetting
223. break;
224. case (char)0x81:
225. send_signature();
226. break;
227. case (char)0x86:
228. send_raw_sensor_values();
229. break;
230. case (char)0x87:
231. send_calibrated_sensor_values(1);
232. break;
233. case (char)0xB0:
234. send_trimpot();
235. break;
236. case (char)0xB1:
237. send_battery_millivolts();
238. break;
239. case (char)0xB3:
240. do_play();
241. break;
242. case (char)0xB4:
243. calibrate_line_sensors(IR_EMITTERS_ON);
244. send_calibrated_sensor_values(1);
245.
break;
246. case (char)0xB5:
247. line_sensors_reset_calibration();
248. break;
249. case (char)0xB6:
250. send_line_position();
251. break;
252. case (char)0xB7:
253. do_clear();
254. break;
255. case (char)0xB8:
256. do_print();
257. break;










