BroBot Code for ESE350 Lab6 part 3 (Skeleton)
Dependencies: MPU6050_V3 mbed-rtos mbed
Fork of BroBot_RTOS_ESE350 by
Diff: stepper_motors.h
- Revision:
- 11:2553f5798f84
- Parent:
- 6:62cdb7482b50
- Child:
- 12:16d1a5390022
--- a/stepper_motors.h Tue Jan 10 21:10:39 2017 +0000 +++ b/stepper_motors.h Thu Jan 19 19:18:54 2017 +0000 @@ -1,6 +1,6 @@ //STEPPER MOTORS #define ZERO_SPEED 1000000 //65535 -#define MAX_ACCEL 7 +#define MAX_ACCEL 2 #define ENABLE 0 #define DISABLE 1 @@ -57,8 +57,12 @@ void setMotor1Speed(int16_t speed) { long timer_period; + //If the speed has not changed, do not update the timer! + if(speed_M1 == speed){ + return; + } speed = CAP(speed, MAX_CONTROL_OUTPUT); - + //Calculate acceleration from the desired speed int16_t desired_accel = speed_M1 - speed; if(desired_accel > MAX_ACCEL) @@ -87,6 +91,10 @@ void setMotor2Speed(int16_t speed) { long timer_period; + //If the speed has not changed, do not update the timer! + if(speed_M2 == speed){ + return; + } speed = CAP(speed, MAX_CONTROL_OUTPUT); //Calculate acceleration from the desired speed