Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SpeedControl.h
00001 /* 00002 * SpeedControl.h 00003 */ 00004 00005 #ifndef SPEED_CONTROL_H_ 00006 #define SPEED_CONTROL_H_ 00007 00008 #include <cstdlib> 00009 #include <mbed.h> 00010 #include "EncoderCounter.h" 00011 #include "LowpassFilter.h" 00012 00013 class SpeedControl 00014 { 00015 00016 public: 00017 00018 SpeedControl(PwmOut* pwmLeft, PwmOut* pwmRight, EncoderCounter* counterLeft, EncoderCounter* counterRight); // constructor 00019 virtual ~SpeedControl(); //destructor 00020 00021 void speedCtrl(); 00022 void setDesiredSpeed( float L, float R); 00023 00024 LowpassFilter speedLeftFilter; 00025 LowpassFilter speedRightFilter; 00026 00027 private: 00028 00029 //static allows you to initialize variables within the header 00030 static const float PERIOD = 0.002f; // period of control task, given in [s] 00031 static const float COUNTS_PER_TURN = 1200.0f; // resolution of encoder counter 00032 static const float LOWPASS_FILTER_FREQUENCY = 300.0f; // frequency of lowpass filter for actual speed values, given in [rad/s] 00033 static const float KN = 40.0f; // speed constant of motor, given in [rpm/V] 00034 static const float KP = 0.2f; // speed controller gain, given in [V/rpm] 00035 //static const float KI = 0.1f; //speed controller integral term gain [V/rpm] 00036 static const float MAX_VOLTAGE = 12.0f; // supply voltage for power stage in [V] 00037 static const float MIN_DUTY_CYCLE = 0.02f; // minimum allowed value for duty cycle (2%) 00038 static const float MAX_DUTY_CYCLE = 0.98f; // maximum allowed value for duty cycle (98%) 00039 00040 DigitalOut* enableMotorDriver; 00041 PwmOut* pwmLeft; 00042 PwmOut* pwmRight; 00043 EncoderCounter* counterRight; 00044 EncoderCounter* counterLeft; 00045 Ticker t2; 00046 00047 short previousValueCounterRight ; // was = 0 00048 short previousValueCounterLeft; // same 00049 00050 float desiredSpeedLeft; 00051 float desiredSpeedRight; 00052 00053 float actualSpeedLeft; 00054 float actualSpeedRight; 00055 }; 00056 00057 #endif /* SPEED_CONTROL_H_ */
Generated on Wed Jul 13 2022 21:19:49 by
1.7.2