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

Dependencies:   mbed UniServ

Committer:
obrie829
Date:
Mon May 29 13:03:28 2017 +0000
Revision:
8:351b0b7b05b2
Child:
11:05d5539141c8
with speed control

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 8:351b0b7b05b2 17 //SpeedControl();
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 void init(PwmOut* pwmL, PwmOut* pwmR); // initializes pwm to set desired speed
obrie829 8:351b0b7b05b2 24
obrie829 8:351b0b7b05b2 25 LowpassFilter speedLeftFilter;
obrie829 8:351b0b7b05b2 26 LowpassFilter speedRightFilter;
obrie829 8:351b0b7b05b2 27
obrie829 8:351b0b7b05b2 28 //DigitalOut my_led(LED1);
obrie829 8:351b0b7b05b2 29
obrie829 8:351b0b7b05b2 30 private:
obrie829 8:351b0b7b05b2 31
obrie829 8:351b0b7b05b2 32 //static allows you to initialize variables within the header
obrie829 8:351b0b7b05b2 33 static const float PERIOD = 0.001f; // period of control task, given in [s]
obrie829 8:351b0b7b05b2 34 static const float COUNTS_PER_TURN = 1200.0f; // resolution of encoder counter
obrie829 8:351b0b7b05b2 35 static const float LOWPASS_FILTER_FREQUENCY = 300.0f; // frequency of lowpass filter for actual speed values, given in [rad/s]
obrie829 8:351b0b7b05b2 36 static const float KN = 40.0f; // speed constant of motor, given in [rpm/V]
obrie829 8:351b0b7b05b2 37 static const float KP = 0.2f; // speed controller gain, given in [V/rpm]
obrie829 8:351b0b7b05b2 38 static const float KI = 0.1f; //speed controller integral term gain [V/rpm]
obrie829 8:351b0b7b05b2 39 static const float MAX_VOLTAGE = 12.0f; // supply voltage for power stage in [V]
obrie829 8:351b0b7b05b2 40 static const float MIN_DUTY_CYCLE = 0.02f; // minimum allowed value for duty cycle (2%)
obrie829 8:351b0b7b05b2 41 static const float MAX_DUTY_CYCLE = 0.98f; // maximum allowed value for duty cycle (98%)
obrie829 8:351b0b7b05b2 42
obrie829 8:351b0b7b05b2 43 DigitalOut* enableMotorDriver;
obrie829 8:351b0b7b05b2 44 PwmOut* pwmLeft;
obrie829 8:351b0b7b05b2 45 PwmOut* pwmRight;
obrie829 8:351b0b7b05b2 46 EncoderCounter* counterRight;
obrie829 8:351b0b7b05b2 47 EncoderCounter* counterLeft;
obrie829 8:351b0b7b05b2 48
obrie829 8:351b0b7b05b2 49 short previousValueCounterRight ; // was = 0
obrie829 8:351b0b7b05b2 50 short previousValueCounterLeft; // same
obrie829 8:351b0b7b05b2 51
obrie829 8:351b0b7b05b2 52 float desiredSpeedLeft;
obrie829 8:351b0b7b05b2 53 float desiredSpeedRight;
obrie829 8:351b0b7b05b2 54
obrie829 8:351b0b7b05b2 55 float actualSpeedLeft;
obrie829 8:351b0b7b05b2 56 float actualSpeedRight;
obrie829 8:351b0b7b05b2 57 };
obrie829 8:351b0b7b05b2 58
obrie829 8:351b0b7b05b2 59 #endif /* SPEED_CONTROL_H_ */