PID motor controll for the biorobotics project.
Dependents: PID_example Motor_calibration Demo_mode Demo_mode ... more
Revision 14:e5fc69651b1d, committed 2018-11-05
- Comitter:
- MAHCSnijders
- Date:
- Mon Nov 05 16:03:11 2018 +0000
- Parent:
- 13:9be1857401f8
- Commit message:
- Fixed constant r
Changed in this revision
motor.h | Show annotated file Show diff for this revision Revisions of this file |
pid.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9be1857401f8 -r e5fc69651b1d motor.h --- a/motor.h Thu Nov 01 12:55:32 2018 +0000 +++ b/motor.h Mon Nov 05 16:03:11 2018 +0000 @@ -1,4 +1,4 @@ -#pragma once +#pragma once // Include only once #include "mbed.h" #include "FastPWM.h" @@ -10,8 +10,8 @@ // Amount of motor encoder pulses per rotation. When using X4 encoding. const int PULSES_PER_ROTATION = 6533; -const double MOTOR_THRESHOLD_RPS = 0.1; // Rad/s under which we send 0 to the motor, to prevent it from jittering around. -const double MOTOR_STALL_PWM = 0.45; // PWM fraction above which the motor starts to move. +const double MOTOR_THRESHOLD_RPS = 0.1; // Motor speed fraction under which we send 0 to the motor, to prevent it from jittering around. +const double MOTOR_STALL_PWM = 0.45; // PWM fraction above which the motor starts to move (below it motor will start to stall). class Motor { /// Rotates a motor to a given angle using PID control.
diff -r 9be1857401f8 -r e5fc69651b1d pid.cpp --- a/pid.cpp Thu Nov 01 12:55:32 2018 +0000 +++ b/pid.cpp Mon Nov 05 16:03:11 2018 +0000 @@ -53,7 +53,7 @@ error_integral += error * pid_period; double u_i = Ki * error_integral; - // Derivative part + // Derivative part (needs filter) double error_der = (error-error_previous)/pid_period; double filtered_error_der = biquad_step(error_der); double u_d = Kd * filtered_error_der;