Michael Ernst Peter / PM2_Libary

Dependencies:   LSM9DS1 RangeFinder FastPWM

Dependents:   PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SpeedController.h Source File

SpeedController.h

00001 #ifndef SpeedController_H_
00002 #define SpeedController_H_
00003 #include <cstdlib>
00004 #include <mbed.h>
00005 #include "EncoderCounter.h"
00006 #include "LowpassFilter.h"
00007 #include "ThreadFlag.h"
00008 #include "FastPWM.h"
00009 #include "Motion.h"
00010 
00011 class SpeedController
00012 {
00013 public:
00014 
00015     SpeedController(float counts_per_turn, float kn, float max_voltage, FastPWM& pwm, EncoderCounter& encoderCounter);
00016 
00017     virtual ~SpeedController();
00018 
00019     void     setDesiredSpeedRPS(float desiredSpeed);
00020     float    getSpeedRPS();
00021     float    getSpeedRPM();
00022     void     setFeedForwardGain(float kn);
00023     void     setSpeedCntrlGain(float kp);
00024     void     setMaxVelocityRPS(float maxVelocityRPS);
00025     void     setMaxVelocityRPM(float maxVelocityRPM);
00026     void     setMaxAccelerationRPS(float maxAccelerationRPS);
00027     void     setMaxAccelerationRPM(float maxAccelerationRPM);
00028 
00029 private:
00030 
00031     void     setDesiredSpeedRPM(float desiredSpeed);
00032 
00033     static const float TS;
00034     static const float LOWPASS_FILTER_FREQUENCY;
00035     static const float MIN_DUTY_CYCLE;
00036     static const float MAX_DUTY_CYCLE;
00037 
00038     float counts_per_turn;
00039     float kn;
00040     float kp;
00041     float max_voltage;
00042 
00043     FastPWM&           pwm;
00044     EncoderCounter&    encoderCounter;
00045     short              previousValueCounter;
00046     LowpassFilter      speedFilter;
00047     float              desiredSpeed;
00048     float              actualSpeed;
00049     // float              actualAngle;
00050     
00051     Motion             motion;
00052 
00053     ThreadFlag         threadFlag;
00054     Thread             thread;
00055     Ticker             ticker;
00056 
00057     void               run();
00058     void               sendThreadFlag();
00059 };
00060 
00061 #endif /* SpeedController_H_ */