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.
Dependencies: millis
Diff: main.cpp
- Revision:
- 27:5f801d4ca461
- Parent:
- 26:6275acef6bfd
- Child:
- 28:1086791972d0
diff -r 6275acef6bfd -r 5f801d4ca461 main.cpp
--- a/main.cpp	Mon Jun 13 10:01:29 2022 +0000
+++ b/main.cpp	Mon Jun 13 11:06:32 2022 +0000
@@ -57,7 +57,7 @@
 }
 
 //Brake code 
-void brakeControl(int brakeRate) {
+void brakeControl(int brakeRate) { //set brake rate to float for regen
   if (driveMode == 2) {   // PARK MODE
     //  All Mechanical brakes applied
     motor1.throttle(0.0f);
@@ -66,15 +66,39 @@
   }
   else {//REGEN BRAKING
     if (challenge.regenBrakingActive == true) { // REGEN BRAKING WITH OVERVOLTAGE SAFETY CHECK
-      if (brakeRate > 0) {
         //motor1.setPark();
-        motor1.brake(brakeRate);
+        switch (brakeRate) { //using switch cases like throttle to set regen braking brake tate with values between 0.1f and 1.0f which represents analog pin out values upto 3.3V
+        
+            
+            default:
+            break;
+            
+            case 0:
+            motor1.brake(0.0f);
+            break;
+
+            case 1:
+            motor1.brake(0.25f);
+            break;
+            
+            case 2:
+            motor1.brake(0.5f);
+            break;
+
+            case 3:
+            motor1.brake(0.75f);
+            break;
+            
+            case 4:
+            motor1.brake(1.0f);
+            break;
       }
       //else {
         //motor1.setForward();
       //}
-    }
+    
     else {  // MECHANICAL BRAKING
+   // int bR=static_cast <int>(brakeRate); //type casting brake rate to int for mechanical cases
       switch (brakeRate) {
         case 0:     // NO BRAKING
           brakeValve32 = 1;//(PF_2)