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.
Fork of SAILORSbot by
Diff: main.cpp
- Revision:
- 25:c4577daa425a
- Parent:
- 24:62cad0ea47da
- Child:
- 26:49945d96d461
--- a/main.cpp Wed Aug 05 05:22:32 2015 +0000
+++ b/main.cpp Tue Aug 04 22:34:15 2015 -0700
@@ -89,18 +89,22 @@
void communicate()
{
led1 = 1;
+ __disable_irq();
pi.sensor_reading(sensors);
+ __enable_irq();
int* s = sensors; // just to make the next line more compact
- __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("m:%d\n", mode);
- __enable_irq();
led1 = 0;
}
+void signal_comm(){
+ comm_time = true;
+}
+
int parse_command(const char* cmd)
{
if(cmd[1]==':'){
@@ -117,9 +121,7 @@
// mode
}else if(cmd[0]=='c'){
mode = atoi(&cmd[2]);
- __disable_irq();
xbee.printf("a:c:%d\n", mode);// acknowledge the mode change
- __enable_irq();
// xbee.printf("mode set to %d\n", mode);
// gains
}else if(cmd[0]=='g'){
@@ -130,9 +132,7 @@
}else if(cmd[2]=='d'){
k_d = atof(&cmd[4]);
}
- __disable_irq();
xbee.printf("gains p:%f, i:%f, d:%f\n", k_p, k_i, k_d);
- __enable_irq();
// battery
}else if(cmd[0]=='b'){
@@ -140,9 +140,7 @@
xbee.printf("battery voltage: %f\n", pi.battery());
__enable_irq();
}else{
- __disable_irq();
xbee.printf("%s\n",cmd);
- __enable_irq();
}
}else{
xbee.printf("%s\n",cmd);
@@ -150,12 +148,8 @@
return 0;
}
-void Rx_interrupt()
-{
- // assume recursive interrupt is not possible
+void check_incoming(){
led2 = 1;
- char read;
-
while(xbee.readable()){
read = xbee.getc();
if(read=='\n'){
@@ -170,18 +164,16 @@
r_index++;
}
}
-
led2=0;
-
- return;
}
-
void control()
{
if(mode==LINE_FOLLOW_MODE){
line_follow_loop();
}
+ pi.left_motor(rightspeed);
+ pi.right_motor(leftspeed);
}
int main() {
@@ -193,21 +185,25 @@
pi.sensor_auto_calibrate();
leftspeed = 0.0;
rightspeed = 0.0;
+ char read;
r_index = 0;
received[0] = '\0';
mode = MANUAL_MODE;
- communication.attach(&communicate, 0.1);
+ communication.attach(&signal_comm, 0.1);
controls.attach(&control, 0.02);
+ // main loop
while(1){
led3 = mode;
- __disable_irq();
- pi.left_motor(rightspeed);
- pi.right_motor(leftspeed);
- __enable_irq();
+ check_incoming();
+
+ if(comm_time){
+ communicate();
+ comm_time = false;
+ }
}
