Decoupled position and current control working.

Dependencies:   QEI mbed-src

Committer:
abuchan
Date:
Tue Nov 24 03:56:22 2015 +0000
Revision:
4:5ae9f8b3a16f
Decoupled position and current control working.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abuchan 4:5ae9f8b3a16f 1 #include "mbed.h"
abuchan 4:5ae9f8b3a16f 2 #include "QEI.h"
abuchan 4:5ae9f8b3a16f 3 #include "Encoder.h"
abuchan 4:5ae9f8b3a16f 4 #include "HBridge.h"
abuchan 4:5ae9f8b3a16f 5 #include "CurrentSense.h"
abuchan 4:5ae9f8b3a16f 6 #include "PID.h"
abuchan 4:5ae9f8b3a16f 7
abuchan 4:5ae9f8b3a16f 8 #ifndef MOTOR_H
abuchan 4:5ae9f8b3a16f 9 #define MOTOR_H
abuchan 4:5ae9f8b3a16f 10
abuchan 4:5ae9f8b3a16f 11 class Motor {
abuchan 4:5ae9f8b3a16f 12 public:
abuchan 4:5ae9f8b3a16f 13 Motor(
abuchan 4:5ae9f8b3a16f 14 PinName pwm_pin, PinName min_1_pin, PinName min_2_pin, float pwm_period,
abuchan 4:5ae9f8b3a16f 15 PinName current_pin,
abuchan 4:5ae9f8b3a16f 16 PinName enc_a_pin, PinName enc_b_pin,
abuchan 4:5ae9f8b3a16f 17 float pid_cur_p_gain, float pid_cur_d_gain, float pid_cur_i_gain
abuchan 4:5ae9f8b3a16f 18 );
abuchan 4:5ae9f8b3a16f 19
abuchan 4:5ae9f8b3a16f 20 float position;
abuchan 4:5ae9f8b3a16f 21 float velocity;
abuchan 4:5ae9f8b3a16f 22 float current;
abuchan 4:5ae9f8b3a16f 23 float torque;
abuchan 4:5ae9f8b3a16f 24 float command;
abuchan 4:5ae9f8b3a16f 25
abuchan 4:5ae9f8b3a16f 26 // output to PWM
abuchan 4:5ae9f8b3a16f 27 float output;
abuchan 4:5ae9f8b3a16f 28
abuchan 4:5ae9f8b3a16f 29 // Update all state variables and apply command
abuchan 4:5ae9f8b3a16f 30 void update(void);
abuchan 4:5ae9f8b3a16f 31
abuchan 4:5ae9f8b3a16f 32 float get_position(void);
abuchan 4:5ae9f8b3a16f 33 float get_velocity(void);
abuchan 4:5ae9f8b3a16f 34 float get_current(void);
abuchan 4:5ae9f8b3a16f 35
abuchan 4:5ae9f8b3a16f 36 // Set current controller commanded value
abuchan 4:5ae9f8b3a16f 37 void set_command(float command);
abuchan 4:5ae9f8b3a16f 38
abuchan 4:5ae9f8b3a16f 39 //float get_pulse_current(float pulse_time, float pulse_interval);
abuchan 4:5ae9f8b3a16f 40
abuchan 4:5ae9f8b3a16f 41 private:
abuchan 4:5ae9f8b3a16f 42 Timer timer_;
abuchan 4:5ae9f8b3a16f 43 HBridge hbridge_;
abuchan 4:5ae9f8b3a16f 44 CurrentSense current_sense_;
abuchan 4:5ae9f8b3a16f 45 Encoder encoder_;
abuchan 4:5ae9f8b3a16f 46 PIDController current_controller_;
abuchan 4:5ae9f8b3a16f 47
abuchan 4:5ae9f8b3a16f 48 };
abuchan 4:5ae9f8b3a16f 49
abuchan 4:5ae9f8b3a16f 50 #endif