Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- Zachary Sunberg
- Date:
- 2015-07-20
- Revision:
- 2:483c2e492a36
- Parent:
- 1:a7aab5937375
- Child:
- 3:47cd6b9e4dbb
File content as of revision 2:483c2e492a36:
#include "robot.h"
#include <sstream>
volatile double leftspeed;
volatile double rightspeed;
char received[80];
int r_index;
int sensors[5];
/*
parses a single command from the stream
*/
int parse_command(const char* cmd)
{
//xbee.printf("%s\n", cmd);
if(cmd[1]==':'){
if(cmd[0]=='l'){
leftspeed = atof(&cmd[2]);
}else if(cmd[0]=='r'){
rightspeed = atof(&cmd[2]);
}else{
xbee.printf("%s\n",cmd);
}
}else{
xbee.printf("%s\n",cmd);
}
return 0;
}
void Rx_interrupt()
{
// assume recursive interrupt is not possible
led2 = 1;
char read;
while(xbee.readable()){
read = xbee.getc();
if(read=='\n'){
received[r_index]='\0'; // put a null character at the end
parse_command(received);
r_index=0;
//command.str("");
} else {
if(r_index >= 80){
r_index=0;
}
received[r_index]=read;
r_index++;
//command << read;
}
}
led2=0;
return;
}
int main() {
xbee.attach(&Rx_interrupt, Serial::RxIrq);
xbeeReset = 0;
wait(2);
xbeeReset = 1;
pi.sensor_auto_calibrate();
r_index = 0;
received[0] = '\0';
while(1){
led1 = 1;
wait_ms(50);
pi.left_motor(leftspeed);
pi.right_motor(rightspeed);
led1 = 0;
wait_ms(50);
pi.sensor_reading(sensors);
int* s = sensors;
__disable_irq();
xbee.printf("s:%i,%i,%i,%i,%i\n", s[0], s[1], s[2], s[3], s[4]);
__enable_irq();
__disable_irq();
xbee.printf("p:%f\n", pi.line_position());
__enable_irq();
// xbee.printf("%s\n",received)
}
return 0;
}
