The following code examples are for Atmel AVR microprocessors using the gcc-avr compiler and tool chain.
Encoder Structure:
typedef struct{
int direction; // Encoder rotation direction.
int count; // Encoder count.
} encoder, *pencoder;
encoder REncoder;
encoder LEncoder;
Motor Structure:
typedef struct{
float kp; // Proportional gain
float ki; // Intigral gain
float kd; // Dirivitive gain
float velocity_setpoint; // Motor velocity setpoint in encoder counts per control loop
float velocity; // Motor velocity in encoder counts per control loop
float previous_error; // Motor's previous proportional error
float integral_error; // Motor's integral error
} motor, *pmotor;
motor RMotor;
motor LMotor;