Practical Robotics Modular Robot Library

Dependents:   ModularRobot

Revision:
4:c2e933d53bea
Parent:
3:8762f6b2ea8d
Child:
5:6da8daaeb9f7
--- a/robot.cpp	Mon Nov 28 22:41:14 2016 +0000
+++ b/robot.cpp	Mon Jan 02 15:17:22 2017 +0000
@@ -8,27 +8,30 @@
 char debug_mode = DEBUG_MODE;
 char debug_output = DEBUG_OUTPUT_STREAM;
 
+SerialComms serial;
 Led led;
 Sensors sensors;
 Motors motors;
 
 Serial pc(USBTX,USBRX);
+Serial bt(p13,p14);
+
 DigitalIn rpi1(p5,PullDown);
 I2C primary_i2c (p9, p10);
-Serial bt(p13,p14);
 DigitalOut case_led(p15);
 DigitalOut mbed_led1(LED1);
 DigitalOut mbed_led2(LED2);
 DigitalOut mbed_led3(LED3);
 DigitalOut mbed_led4(LED4);
 AnalogIn vin_battery(p17);
-char status_message [16];
+char status_message [8];
 
 
 // Public functions
 
+
 void Robot::update_status_message(){
-    // Compose a 16-byte status message indicating all the current sensor values
+    // Compose an 8-character status message indicating the current status values
     // First two bytes are uptime in 1/10ths of seconds
     int current_uptime = (int) ((get_uptime() * 10.0)) % 65536;
     status_message[0] = current_uptime / 256;
@@ -44,20 +47,25 @@
     // Next byte is left motor current * 96
     status_message[6] = (int) (motors.get_current_left() * 96.0);
     // Next byte is right motor current * 96
-    status_message[7] = (int) (motors.get_current_right() * 96.0);
-    for(int i=0;i<8;i++){
-        status_message[i+8] = sensors.get_adc_value(i);
-    }    
+    status_message[7] = (int) (motors.get_current_right() * 96.0);   
+}
+
+void Robot::case_led_toggle(){
+    case_led = 1-case_led;   
 }
 
 void Robot::init(){
+    //Flash the case LED during init routine
+    Ticker case_led_ticker;
+    case_led_ticker.attach(this,&Robot::case_led_toggle, 0.25);
+    
     //Start the uptime timer
     timer_minute_count = 0;
     timer_ticker.attach(this,&Robot::_update_minutes, 300);  //Update minutes resets the uptime timer every 5 minutes to prevent stop overruns
     mbed_uptime.start();   
     
     //Setup serial interfaces
-    setup_serial_interfaces();
+    serial.setup_serial_interfaces();
     debug("Practical Robotics Modular Robot\n");
     
     //Setup the primary i2c bus to 400kHz baud rate
@@ -90,9 +98,13 @@
     
     //Wait for R-Pi pin to become high
     debug("Waiting for Raspberry Pi Zero...\n");
-    led.start_test();
+    led.start_animation(9,40);
     while(rpi1==0) wait_us(50);
+    led.stop_animation();
     led.all_off();
+    case_led_ticker.detach();
+    case_led = 1;
+    led.start_animation(0,25);
     debug("Initialisation finished: Starting program. \n");
 }
 
@@ -122,29 +134,6 @@
     }
 }
 
-void Robot::setup_serial_interfaces()
-{
-    if(ENABLE_PC_SERIAL) {
-        pc.baud(PC_BAUD);
-        pc.attach(this,&Robot::_pc_rx_callback, Serial::RxIrq);
-    }
-    if(ENABLE_BLUETOOTH) {
-        bt.baud(BLUETOOTH_BAUD);
-        bt.attach(this,&Robot::_bt_rx_callback, Serial::RxIrq);
-    }
-}
-
-// Private functions
-
-void Robot::_pc_rx_callback()
-{
-    
-}
-
-void Robot::_bt_rx_callback()
-{
- 
-}
 
 
 void Robot::_update_minutes()