Motor current controller

Fork of CURRENT_CONTROL by LDSC_Robotics_TAs

Committer:
adam_z
Date:
Fri Apr 22 15:21:31 2016 +0000
Revision:
2:562bd14dfd3a
Parent:
1:c5973a56d474
Child:
3:c787d1c5ad6a
no problem till now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adam_z 0:955aa05c968a 1 #ifndef __CURRENT_CONTROL_H__
adam_z 0:955aa05c968a 2 #define __CURRENT_CONTROL_H__
adam_z 0:955aa05c968a 3
adam_z 0:955aa05c968a 4 #include "mbed.h"
adam_z 0:955aa05c968a 5 #include "PID.h"
adam_z 0:955aa05c968a 6
adam_z 0:955aa05c968a 7
adam_z 0:955aa05c968a 8 class CURRENT_CONTROL
adam_z 0:955aa05c968a 9 {
adam_z 0:955aa05c968a 10 public:
adam_z 1:c5973a56d474 11 typedef enum {
adam_z 1:c5973a56d474 12 PWM1,
adam_z 1:c5973a56d474 13 PWM2
adam_z 1:c5973a56d474 14 } PWMIndex;
adam_z 1:c5973a56d474 15
adam_z 1:c5973a56d474 16 CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float samplingTime);
adam_z 1:c5973a56d474 17 void Control(float curRef);
adam_z 2:562bd14dfd3a 18 void SetAnalog2Cur(float ratio);
adam_z 2:562bd14dfd3a 19 //functions for test////////
adam_z 0:955aa05c968a 20 void ChangePwmPeriod(float microSeconds);
adam_z 1:c5973a56d474 21 void SetPWMDuty(float ratio);
adam_z 2:562bd14dfd3a 22 float GetAnalogIn(void);
adam_z 2:562bd14dfd3a 23 float GetCurrent(void);
adam_z 2:562bd14dfd3a 24 //////////////////////////
adam_z 1:c5973a56d474 25 PWMIndex pwmIndex_;
adam_z 0:955aa05c968a 26 PID pid;
adam_z 0:955aa05c968a 27 PwmOut MotorPlus;
adam_z 0:955aa05c968a 28 PwmOut MotorMinus;
adam_z 0:955aa05c968a 29 float controlOutput;
adam_z 0:955aa05c968a 30
adam_z 0:955aa05c968a 31 float currentOffset;
adam_z 1:c5973a56d474 32 float curFeedBack;
adam_z 1:c5973a56d474 33 float analog2Cur;
adam_z 1:c5973a56d474 34 AnalogIn currentAnalogIn;
adam_z 2:562bd14dfd3a 35 float analogInValue;
adam_z 2:562bd14dfd3a 36
adam_z 0:955aa05c968a 37 private:
adam_z 0:955aa05c968a 38
adam_z 0:955aa05c968a 39 float Ts;
adam_z 1:c5973a56d474 40
adam_z 0:955aa05c968a 41
adam_z 0:955aa05c968a 42 };
adam_z 0:955aa05c968a 43
adam_z 0:955aa05c968a 44
adam_z 0:955aa05c968a 45
adam_z 0:955aa05c968a 46
adam_z 0:955aa05c968a 47
adam_z 0:955aa05c968a 48
adam_z 0:955aa05c968a 49
adam_z 0:955aa05c968a 50
adam_z 0:955aa05c968a 51
adam_z 0:955aa05c968a 52
adam_z 0:955aa05c968a 53
adam_z 0:955aa05c968a 54
adam_z 0:955aa05c968a 55
adam_z 0:955aa05c968a 56
adam_z 0:955aa05c968a 57
adam_z 0:955aa05c968a 58
adam_z 0:955aa05c968a 59
adam_z 0:955aa05c968a 60
adam_z 0:955aa05c968a 61
adam_z 0:955aa05c968a 62
adam_z 0:955aa05c968a 63
adam_z 0:955aa05c968a 64
adam_z 0:955aa05c968a 65
adam_z 0:955aa05c968a 66
adam_z 0:955aa05c968a 67
adam_z 0:955aa05c968a 68
adam_z 0:955aa05c968a 69
adam_z 0:955aa05c968a 70
adam_z 0:955aa05c968a 71
adam_z 0:955aa05c968a 72
adam_z 0:955aa05c968a 73
adam_z 0:955aa05c968a 74 #endif