this code is for inverted pendulum balancer. it is based on two-loop PID controller. One controller is for Angle and another one is for velocity.
Dependencies: HCSR04 L298HBridge mbed
controller/controller.h@0:489498e8dae5, 2017-08-25 (annotated)
- Committer:
- dudu941014
- Date:
- Fri Aug 25 21:10:23 2017 +0000
- Revision:
- 0:489498e8dae5
this code is for inverted pendulum balancer. it is based on two-loop PID controller. one PID controller is for angle and another one is for velocity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudu941014 | 0:489498e8dae5 | 1 | //#ifndef CONTROLLER_H |
dudu941014 | 0:489498e8dae5 | 2 | //#define CONTROLLER_H |
dudu941014 | 0:489498e8dae5 | 3 | |
dudu941014 | 0:489498e8dae5 | 4 | #include "mbed.h" |
dudu941014 | 0:489498e8dae5 | 5 | #include "PID.h" |
dudu941014 | 0:489498e8dae5 | 6 | #include "L298HBridge.h" |
dudu941014 | 0:489498e8dae5 | 7 | |
dudu941014 | 0:489498e8dae5 | 8 | #define controllerAng_update_dt 0.005 |
dudu941014 | 0:489498e8dae5 | 9 | #define controllerVel_Update_dt 0.005 |
dudu941014 | 0:489498e8dae5 | 10 | |
dudu941014 | 0:489498e8dae5 | 11 | #define AngleOutputLimit 600 //attitude output limit at 60% power |
dudu941014 | 0:489498e8dae5 | 12 | #define AngleErrLimit 450 //attitude pitch error limit at 45degree * 10 = 450 |
dudu941014 | 0:489498e8dae5 | 13 | #define velOutputLimit 600 //altitude output limit at 60% power |
dudu941014 | 0:489498e8dae5 | 14 | #define VelocityLimit 100 |
dudu941014 | 0:489498e8dae5 | 15 | #define offset_moving 400 //the duty start at 40% |
dudu941014 | 0:489498e8dae5 | 16 | |
dudu941014 | 0:489498e8dae5 | 17 | |
dudu941014 | 0:489498e8dae5 | 18 | |
dudu941014 | 0:489498e8dae5 | 19 | extern PidObject pidAngle; |
dudu941014 | 0:489498e8dae5 | 20 | extern PidObject pidVelocity; |
dudu941014 | 0:489498e8dae5 | 21 | |
dudu941014 | 0:489498e8dae5 | 22 | //extern float pitchOutput; |
dudu941014 | 0:489498e8dae5 | 23 | //extern float AngleOutput; |
dudu941014 | 0:489498e8dae5 | 24 | |
dudu941014 | 0:489498e8dae5 | 25 | extern L298HBridge Motor_PWM; |
dudu941014 | 0:489498e8dae5 | 26 | extern float Motor; |
dudu941014 | 0:489498e8dae5 | 27 | |
dudu941014 | 0:489498e8dae5 | 28 | extern float I_term; |
dudu941014 | 0:489498e8dae5 | 29 | |
dudu941014 | 0:489498e8dae5 | 30 | void controller_init(void); |
dudu941014 | 0:489498e8dae5 | 31 | float controller_Angle_PID(float angle_result); |
dudu941014 | 0:489498e8dae5 | 32 | float controller_Velocity_PID(float Velocity_result); |
dudu941014 | 0:489498e8dae5 | 33 | void controllerResetAllPID(void); |
dudu941014 | 0:489498e8dae5 | 34 | float controllerGetActuatorOutput(); |
dudu941014 | 0:489498e8dae5 | 35 | void MOTOR_Update(float Motor); |
dudu941014 | 0:489498e8dae5 | 36 | |
dudu941014 | 0:489498e8dae5 | 37 | |
dudu941014 | 0:489498e8dae5 | 38 |