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

Committer:
dudu941014
Date:
2017-08-25
Revision:
1:ce626b794a6c
Parent:
0:489498e8dae5

File content as of revision 1:ce626b794a6c:

//#ifndef CONTROLLER_H
//#define CONTROLLER_H

#include "mbed.h"
#include "PID.h"
#include "L298HBridge.h"

#define controllerAng_update_dt 0.005
#define controllerVel_Update_dt 0.005

#define AngleOutputLimit 600 //attitude output limit at 60% power
#define AngleErrLimit 450 //attitude pitch error limit at 45degree * 10 = 450
#define velOutputLimit 600 //altitude output limit at 60% power
#define VelocityLimit 100
#define offset_moving 400 //the duty start at 40%



extern PidObject pidAngle;
extern PidObject pidVelocity;

//extern float pitchOutput;
//extern float AngleOutput;

extern L298HBridge Motor_PWM;
extern float Motor;

extern float I_term;

void controller_init(void);
float controller_Angle_PID(float angle_result); 
float controller_Velocity_PID(float Velocity_result); 
void controllerResetAllPID(void);
float controllerGetActuatorOutput();
void MOTOR_Update(float Motor);