These are the core files for the Robot at Team conception.

Dependencies:   mbed UniServ

Committer:
obrie829
Date:
Wed Jun 07 11:35:59 2017 +0000
Revision:
17:ec52258b9472
Parent:
15:4efc66de795a
v18

Who changed what in which revision?

UserRevisionLine numberNew contents of line
obrie829 8:351b0b7b05b2 1 /*
obrie829 8:351b0b7b05b2 2 * SpeedControl.h
obrie829 8:351b0b7b05b2 3 */
obrie829 8:351b0b7b05b2 4
obrie829 8:351b0b7b05b2 5 #ifndef SPEED_CONTROL_H_
obrie829 8:351b0b7b05b2 6 #define SPEED_CONTROL_H_
obrie829 8:351b0b7b05b2 7
obrie829 8:351b0b7b05b2 8 #include <cstdlib>
obrie829 8:351b0b7b05b2 9 #include <mbed.h>
obrie829 8:351b0b7b05b2 10 #include "EncoderCounter.h"
obrie829 8:351b0b7b05b2 11 #include "LowpassFilter.h"
obrie829 8:351b0b7b05b2 12
obrie829 8:351b0b7b05b2 13 class SpeedControl
obrie829 8:351b0b7b05b2 14 {
obrie829 8:351b0b7b05b2 15
obrie829 8:351b0b7b05b2 16 public:
obrie829 15:4efc66de795a 17
obrie829 8:351b0b7b05b2 18 SpeedControl(PwmOut* pwmLeft, PwmOut* pwmRight, EncoderCounter* counterLeft, EncoderCounter* counterRight); // constructor
obrie829 8:351b0b7b05b2 19 virtual ~SpeedControl(); //destructor
obrie829 8:351b0b7b05b2 20
obrie829 8:351b0b7b05b2 21 void speedCtrl();
obrie829 8:351b0b7b05b2 22 void setDesiredSpeed( float L, float R);
obrie829 8:351b0b7b05b2 23
obrie829 8:351b0b7b05b2 24 LowpassFilter speedLeftFilter;
obrie829 8:351b0b7b05b2 25 LowpassFilter speedRightFilter;
obrie829 8:351b0b7b05b2 26
obrie829 8:351b0b7b05b2 27 private:
obrie829 8:351b0b7b05b2 28
obrie829 8:351b0b7b05b2 29 //static allows you to initialize variables within the header
obrie829 17:ec52258b9472 30 static const float PERIOD = 0.002f; // period of control task, given in [s]
obrie829 8:351b0b7b05b2 31 static const float COUNTS_PER_TURN = 1200.0f; // resolution of encoder counter
obrie829 8:351b0b7b05b2 32 static const float LOWPASS_FILTER_FREQUENCY = 300.0f; // frequency of lowpass filter for actual speed values, given in [rad/s]
obrie829 8:351b0b7b05b2 33 static const float KN = 40.0f; // speed constant of motor, given in [rpm/V]
obrie829 8:351b0b7b05b2 34 static const float KP = 0.2f; // speed controller gain, given in [V/rpm]
obrie829 17:ec52258b9472 35 //static const float KI = 0.1f; //speed controller integral term gain [V/rpm]
obrie829 8:351b0b7b05b2 36 static const float MAX_VOLTAGE = 12.0f; // supply voltage for power stage in [V]
obrie829 8:351b0b7b05b2 37 static const float MIN_DUTY_CYCLE = 0.02f; // minimum allowed value for duty cycle (2%)
obrie829 8:351b0b7b05b2 38 static const float MAX_DUTY_CYCLE = 0.98f; // maximum allowed value for duty cycle (98%)
obrie829 8:351b0b7b05b2 39
obrie829 8:351b0b7b05b2 40 DigitalOut* enableMotorDriver;
obrie829 8:351b0b7b05b2 41 PwmOut* pwmLeft;
obrie829 8:351b0b7b05b2 42 PwmOut* pwmRight;
obrie829 8:351b0b7b05b2 43 EncoderCounter* counterRight;
obrie829 8:351b0b7b05b2 44 EncoderCounter* counterLeft;
obrie829 15:4efc66de795a 45 Ticker t2;
obrie829 8:351b0b7b05b2 46
obrie829 8:351b0b7b05b2 47 short previousValueCounterRight ; // was = 0
obrie829 8:351b0b7b05b2 48 short previousValueCounterLeft; // same
obrie829 8:351b0b7b05b2 49
obrie829 8:351b0b7b05b2 50 float desiredSpeedLeft;
obrie829 8:351b0b7b05b2 51 float desiredSpeedRight;
obrie829 8:351b0b7b05b2 52
obrie829 8:351b0b7b05b2 53 float actualSpeedLeft;
obrie829 8:351b0b7b05b2 54 float actualSpeedRight;
obrie829 8:351b0b7b05b2 55 };
obrie829 8:351b0b7b05b2 56
obrie829 8:351b0b7b05b2 57 #endif /* SPEED_CONTROL_H_ */