first commit

Dependencies:   mbed MMA8451Q

Revision:
6:d2bd68ba99c9
Parent:
3:25c6bf0abc00
Child:
7:05ea1c004b49
--- a/main.cpp	Mon Oct 25 02:14:11 2021 +0000
+++ b/main.cpp	Mon Oct 25 03:15:51 2021 +0000
@@ -25,12 +25,15 @@
     DigitalOut led_b(LED_BLUE);
     //Set the period of the servo motor control signal
     servo_motor_pwm.period(1/SERVO_MOTOR_FREQ);
+    motorLeft.period(1/freq);
+    motorRight.period(1/freq);
     //Center the servo motor
     servo_motor_pwm.write(CENTER_DUTY_CYCLE);
 
     //Start the control systm using a Ticker object
       steering_control_ticker.attach(&steering_control, TI);
-     
+      motorLoop.attach(&PI,TI);
+      //bt.attach(&btReceive);
     
     // call landmark_counter wjen a landmark is detected 
     left_landmark_sensor.rise(&landmark_counter);
@@ -40,7 +43,6 @@
     run_button.rise(&state_update);
     wait_button.rise(&state_update);
  
- 
  bt.baud(BLUETOOTHBAUDRATE);
  //Sets the communication rate of the micro-controller to the Bluetooth module.
 pc.printf("Hello World!\n");
@@ -49,18 +51,6 @@
 t.start();
 float time = t.read();
 
-//bt.attach(&btReceive);
-motorLoop.attach(&PI,TI);
-
-motorLeft.period(1/freq);
-motorRight.period(1/freq);
-
-//setpointLeft = 0.0; //target speed, 0.0 to 1.0
-//setpointRight = 0.0;
-
-setpointLeft = 0.7; //target speed, 0.0 to 1.0
-setpointRight = 0.7;
-
  //prints the string to the Tera-Term Console using the Bluetooth object ‘bt’.
  while(1) {
      
@@ -72,7 +62,8 @@
      pc.printf("\r\nRight voltage : %f"      , right_distance_sensor.read());
      pc.printf("\r\nCurrent duty cycle : %f ", current_duty_cycle);
        fault_check();
-      wait(0.5);
+      //wait(0.5); //commented out the wait bc it slows down the fault_check, and it breaks the analogIn readings for the driving input
+                    //the driving input ticker is faster than the analog.read() function, so all analog.read() methods must be in the main loop
      switch(current_state ){
          case STOP :    pc.printf("\r\nCurrent state is stop"); break; 
          case RUN:      pc.printf("\r\nCurrent state is RUN"); break; 
@@ -81,15 +72,12 @@
      switch(fault_type) {
          case CLEAR :       pc.printf("\r\nFault: CLEAR"); break; 
          case OFF_TRACK:    pc.printf("\r\nFault: OFF TRACK"); break;
-         case BUMPER :      pc.printf("\r\nFault: OBSTECALE"); break;
+         case BUMPER :      pc.printf("\r\nFault: OBSTACLE"); break;
          case LOW_VOLTAGE : pc.printf("Fault: LOW VOLTAGE");  break;
           }
           
 x = abs(acc.getAccX());
 pot1Voltage = pot1 * 3.3f;
-batteryVoltage = battInput * 3.3 * battDividerScalar;
-avgCellVoltage = batteryVoltage / 3.0;
-
 //dutyCycleLeft = (pot1 * fullBatScalar);
 //dutyCycleRight = (pot1 * fullBatScalar);