Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Revision:
23:1901cb6d0d95
Parent:
22:7ba09c0af0d0
--- a/motors/motors.cpp	Thu May 03 14:20:04 2012 +0000
+++ b/motors/motors.cpp	Fri May 04 02:50:07 2012 +0000
@@ -25,14 +25,14 @@
         Encoder2 (p27, p28, NC, 1856 ,QEI::X4_ENCODING),    //connects to motor2 quadracture encoders
         Motor1A(p17), Motor1B(p18), Motor2A(p19), Motor2B(p13), //connects to direction pins
         Motor1Enable(p25), Motor2Enable(p26),   //Connects to control board enable pins to control motors speeds. PWM pins. Remember enable must be set before the direction pins changed!!
-        //PIDControllerMotor1(2.25, 0.3, 0.00001, 0.010), PIDControllerMotor2(2.25, 0.3, 0.00001, 0.010) 
-         PIDControllerMotor1(3.5, 0.5, 0.0, 0.010), PIDControllerMotor2(3.5, 0.5, 0.0, 0.010){
+        PIDControllerMotor1(2.25, 0.3, 0.00001, 0.010), PIDControllerMotor2(2.25, 0.3, 0.00001, 0.010) {
+         //PIDControllerMotor1(3.5, 0.5, 0.0, 0.010), PIDControllerMotor2(3.5, 0.5, 0.0, 0.010){
 
 //Initialise PID controllers
     PIDControllerMotor1.setMode(MANUAL_MODE);
     PIDControllerMotor2.setMode(MANUAL_MODE);
-    PIDControllerMotor1.setBias(-16);
-    PIDControllerMotor2.setBias(-16);
+    PIDControllerMotor1.setBias(0);
+    PIDControllerMotor2.setBias(0);
     PIDControllerMotor1.setOutputLimits(-127, 127);
     PIDControllerMotor2.setOutputLimits(-127, 127);
     PIDControllerMotor1.setInputLimits(-102, 102);
@@ -57,6 +57,8 @@
 //*********************************************
 void Motors::speedRegulatorTask() {
 
+    if (_enableSpeed == 1) {
+
     int latestMotor1Speed = 0;
     int latestMotor2Speed = 0;
     int computedSpeed1 = 0;
@@ -122,6 +124,7 @@
     _setSpeed(computedSpeed1, computedSpeed2);
 
 }
+}
 
 //*********************************************
 //
@@ -146,7 +149,7 @@
     _motorSpeed2 = speed2;
     _lastEncoder1 = getEncoder1();
     _lastEncoder2 = getEncoder2();
-
+    _enableSpeed = 1; 
     //acceleration control
     if (accelerationRegister == 1) {
         //target accelerated speed
@@ -171,6 +174,19 @@
 
 //*********************************************
 //
+//  @Description    stops motors
+//
+//*********************************************
+void  Motors::coastStop()
+{
+    setSpeed(0);
+    _enableSpeed = 0;
+    
+}
+
+
+//*********************************************
+//
 //  @Description    resets motor1 and motor encoders
 //
 //*********************************************