Custom version for NXP cup car

Dependents:   NXPCUPcar

Committer:
Clarkk
Date:
Wed Jul 05 20:29:37 2017 +0000
Revision:
3:170c22171ec2
Parent:
2:0d5c994d8135
Child:
4:66154ae82263
Added fixed PWM mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Clarkk 0:a1bb4583940a 1 #include "mbed.h"
Clarkk 0:a1bb4583940a 2 #include "TFC.h"
Clarkk 0:a1bb4583940a 3
Clarkk 0:a1bb4583940a 4 #ifndef _MOTORCONTROL_H
Clarkk 0:a1bb4583940a 5 #define _MOTORCONTROL_H
Clarkk 0:a1bb4583940a 6
Clarkk 0:a1bb4583940a 7 #define MOTSAMPLECOUNT 100
Clarkk 1:7ce4ffeb8ccb 8 #define BATSAMPLECOUNT 50
Clarkk 0:a1bb4583940a 9
Clarkk 0:a1bb4583940a 10 class Motors
Clarkk 0:a1bb4583940a 11 {
Clarkk 0:a1bb4583940a 12 public:
Clarkk 0:a1bb4583940a 13
Clarkk 0:a1bb4583940a 14 Motors();
Clarkk 0:a1bb4583940a 15 void start();
Clarkk 0:a1bb4583940a 16 void stop();
Clarkk 0:a1bb4583940a 17 void saveBatteryVoltageMeasure(uint16_t ADCresult);
Clarkk 0:a1bb4583940a 18 void saveMotorCurrentMeasure(uint16_t MotA_ADCresult, uint16_t MotB_ADCresult);
Clarkk 0:a1bb4583940a 19 float getWheelSpeed(char mot);
Clarkk 0:a1bb4583940a 20 float getWheelRPS(char mot);
Clarkk 2:0d5c994d8135 21 float getCarSpeed();
Clarkk 3:170c22171ec2 22 void setPWM(float value);
Clarkk 3:170c22171ec2 23 void setFixedPWMMode(void);
Clarkk 3:170c22171ec2 24 void setRegulatedPWMMode(void);
Clarkk 0:a1bb4583940a 25 void processTasks();
Clarkk 2:0d5c994d8135 26 float getMotCurrent(char mot);
Clarkk 2:0d5c994d8135 27 float getMotPWM(char mot);
Clarkk 0:a1bb4583940a 28 float getAverageMotCurrent(char mot);
Clarkk 0:a1bb4583940a 29 float getAverageBatteryVoltage();
Clarkk 0:a1bb4583940a 30 void setFixedPWMValue(float pwm);
Clarkk 2:0d5c994d8135 31 void setSpeedTargetValue(float speed);
Clarkk 2:0d5c994d8135 32
Clarkk 2:0d5c994d8135 33 float getSpeedError();
Clarkk 0:a1bb4583940a 34
Clarkk 0:a1bb4583940a 35 private:
Clarkk 0:a1bb4583940a 36
Clarkk 3:170c22171ec2 37 bool PWMRegulatedMode;
Clarkk 3:170c22171ec2 38 int16_t fixedPWM;
Clarkk 3:170c22171ec2 39
Clarkk 2:0d5c994d8135 40 int16_t motorAPWM[MOTSAMPLECOUNT];
Clarkk 2:0d5c994d8135 41 int16_t motorBPWM[MOTSAMPLECOUNT];
Clarkk 0:a1bb4583940a 42 uint16_t motorACurrent[MOTSAMPLECOUNT];
Clarkk 0:a1bb4583940a 43 uint16_t motorBCurrent[MOTSAMPLECOUNT];
Clarkk 0:a1bb4583940a 44 uint16_t batteryVoltage[BATSAMPLECOUNT];
Clarkk 0:a1bb4583940a 45
Clarkk 0:a1bb4583940a 46 uint8_t motorCurrentIndex;
Clarkk 0:a1bb4583940a 47 uint8_t batVoltageIndex;
Clarkk 0:a1bb4583940a 48
Clarkk 2:0d5c994d8135 49 int16_t nextPWM;
Clarkk 2:0d5c994d8135 50 // int16_t torqueDiffAvg;
Clarkk 2:0d5c994d8135 51 uint8_t motorDriveIndex;
Clarkk 2:0d5c994d8135 52 float currentMotAPWM;
Clarkk 2:0d5c994d8135 53 float currentMotBPWM;
Clarkk 2:0d5c994d8135 54
Clarkk 2:0d5c994d8135 55 int32_t speedTarget;
Clarkk 2:0d5c994d8135 56 int32_t speederror1000000;
Clarkk 0:a1bb4583940a 57 };
Clarkk 0:a1bb4583940a 58
Clarkk 0:a1bb4583940a 59 #endif