Motor current controller

Fork of CURRENT_CONTROL by LDSC_Robotics_TAs

Committer:
adam_z
Date:
Fri Apr 22 16:29:35 2016 +0000
Revision:
3:c787d1c5ad6a
Parent:
2:562bd14dfd3a
Child:
4:1a6ba05e7736
basically works

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 3:c787d1c5ad6a 8
adam_z 3:c787d1c5ad6a 9 class LPF
adam_z 3:c787d1c5ad6a 10 {public:
adam_z 3:c787d1c5ad6a 11 float output, outputLast;
adam_z 3:c787d1c5ad6a 12
adam_z 3:c787d1c5ad6a 13 LPF(float samplingTime);
adam_z 3:c787d1c5ad6a 14 float filter(float input, float cutOff);
adam_z 3:c787d1c5ad6a 15
adam_z 3:c787d1c5ad6a 16 private:
adam_z 3:c787d1c5ad6a 17 float Ts;
adam_z 3:c787d1c5ad6a 18 };
adam_z 3:c787d1c5ad6a 19
adam_z 3:c787d1c5ad6a 20
adam_z 0:955aa05c968a 21 class CURRENT_CONTROL
adam_z 0:955aa05c968a 22 {
adam_z 0:955aa05c968a 23 public:
adam_z 1:c5973a56d474 24 typedef enum {
adam_z 1:c5973a56d474 25 PWM1,
adam_z 1:c5973a56d474 26 PWM2
adam_z 1:c5973a56d474 27 } PWMIndex;
adam_z 1:c5973a56d474 28
adam_z 1:c5973a56d474 29 CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float samplingTime);
adam_z 1:c5973a56d474 30 void Control(float curRef);
adam_z 2:562bd14dfd3a 31 void SetAnalog2Cur(float ratio);
adam_z 3:c787d1c5ad6a 32
adam_z 2:562bd14dfd3a 33 //functions for test////////
adam_z 0:955aa05c968a 34 void ChangePwmPeriod(float microSeconds);
adam_z 1:c5973a56d474 35 void SetPWMDuty(float ratio);
adam_z 2:562bd14dfd3a 36 float GetAnalogIn(void);
adam_z 2:562bd14dfd3a 37 float GetCurrent(void);
adam_z 2:562bd14dfd3a 38 //////////////////////////
adam_z 1:c5973a56d474 39 PWMIndex pwmIndex_;
adam_z 0:955aa05c968a 40 PID pid;
adam_z 0:955aa05c968a 41 PwmOut MotorPlus;
adam_z 0:955aa05c968a 42 PwmOut MotorMinus;
adam_z 0:955aa05c968a 43 float controlOutput;
adam_z 0:955aa05c968a 44
adam_z 0:955aa05c968a 45 float currentOffset;
adam_z 1:c5973a56d474 46 float curFeedBack;
adam_z 1:c5973a56d474 47 float analog2Cur;
adam_z 1:c5973a56d474 48 AnalogIn currentAnalogIn;
adam_z 2:562bd14dfd3a 49 float analogInValue;
adam_z 2:562bd14dfd3a 50
adam_z 3:c787d1c5ad6a 51 LPF lpFilter;
adam_z 3:c787d1c5ad6a 52
adam_z 3:c787d1c5ad6a 53
adam_z 0:955aa05c968a 54 private:
adam_z 0:955aa05c968a 55
adam_z 0:955aa05c968a 56 float Ts;
adam_z 1:c5973a56d474 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
adam_z 0:955aa05c968a 75
adam_z 0:955aa05c968a 76
adam_z 0:955aa05c968a 77
adam_z 0:955aa05c968a 78
adam_z 0:955aa05c968a 79
adam_z 0:955aa05c968a 80
adam_z 0:955aa05c968a 81
adam_z 0:955aa05c968a 82
adam_z 0:955aa05c968a 83
adam_z 0:955aa05c968a 84
adam_z 0:955aa05c968a 85
adam_z 0:955aa05c968a 86
adam_z 0:955aa05c968a 87
adam_z 0:955aa05c968a 88
adam_z 0:955aa05c968a 89
adam_z 0:955aa05c968a 90
adam_z 3:c787d1c5ad6a 91
adam_z 3:c787d1c5ad6a 92
adam_z 0:955aa05c968a 93 #endif