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.
Dependencies: mbed MODSERIAL FATFileSystem
LinearActuator.hpp
00001 #ifndef LINEARACTUATOR_HPP 00002 #define LINEARACTUATOR_HPP 00003 00004 #include "mbed.h" 00005 #include "PololuHBridge.hpp" 00006 #include "PidController.hpp" 00007 #include "ltc1298.hpp" 00008 #include "PosVelFilter.hpp" 00009 00010 //Dependencies 00011 //This Class requires adc readings to sense the position of the piston 00012 //This is a resource that ends up being shared among other classes in the vehicle 00013 //for this reason it makes sense for it to be its own entity that is started in 00014 //the main line code 00015 00016 class LinearActuator { 00017 public: 00018 LinearActuator(float interval, PinName pwm, PinName dir, PinName reset, PinName limit, int adc_ch); 00019 00020 // functions for setting up 00021 void init(); 00022 void update(); 00023 // start and stop were removed, legacy functionality (one ticker runs clocks now) 00024 void pause(); 00025 void unpause(); 00026 00027 void runLinearActuator(); //new 03/12/2018 00028 00029 void refreshPVState(); 00030 00031 // setting and getting variables 00032 void setPosition_mm(float dist); 00033 float getSetPosition_mm(); 00034 00035 float getPosition_mm(); 00036 float getPosition_counts(); 00037 float getVelocity_mms(); 00038 00039 void setControllerP(float P); 00040 float getControllerP(); 00041 00042 void setControllerI(float I); 00043 float getControllerI(); 00044 00045 void setControllerD(float D); 00046 float getControllerD(); 00047 00048 void setZeroCounts(int zero); 00049 int getZeroCounts(); 00050 00051 void setTravelLimit(float limit); 00052 float getTravelLimit(); 00053 00054 void setPotSlope(float slope); 00055 float getPotSlope(); 00056 00057 void homePiston(); 00058 bool getSwitch(); //get state of limit switch 00059 00060 float getOutput(); 00061 00062 void setFilterFrequency(float frequency); 00063 float getFilterFrequency(); // 7/11/18 00064 00065 void setDeadband(float deadband); 00066 float getDeadband(); 00067 bool toggleDeadband(bool toggle); 00068 00069 void setPIDHighLimit(float high_limit); 00070 void setPIDLowLimit(float low_limit); 00071 00072 bool getHardwareSwitchStatus(); //new 00073 00074 protected: 00075 PololuHBridge _motor; 00076 PosVelFilter _filter; 00077 PIDController _pid; 00078 Ticker _pulse; 00079 InterruptIn _limitSwitch; 00080 00081 void _switchPressed(); 00082 void _switchReleased(); 00083 void _calculateSensorSlope(); 00084 00085 bool _init; 00086 bool _paused; 00087 bool _limit; 00088 00089 int _adc_channel; 00090 00091 float _filterFrequency; 00092 00093 float _dt; 00094 00095 float _SetPoint_mm; 00096 00097 // position and velocity in counts (PVF runs on counts) 00098 float _position; 00099 float _velocity; 00100 00101 // position and velocity converted to mm and mm/s 00102 float _position_mm; 00103 float _velocity_mms; 00104 00105 // linear actuator servo PID gains 00106 float _Pgain; 00107 float _Igain; 00108 float _Dgain; 00109 00110 float _deadband; 00111 00112 int _zeroCounts; //gets assigned by homing function. can also be stored in config 00113 float _extendLimit; //config variable, limits the extension of the piston, this is same as datum for normal operation, 00114 00115 float _slope; 00116 int dist_to_counts(float dist); 00117 float counts_to_dist(int count); 00118 float counts_to_velocity(int count); 00119 00120 float _pid_high_limit; 00121 float _pid_low_limit; 00122 }; 00123 00124 00125 template <typename T> 00126 T clamp(T value, T min, T max) 00127 { 00128 if(value < min) { 00129 return min; 00130 } else if(value > max) { 00131 return max; 00132 } else { 00133 return value; 00134 } 00135 }; 00136 00137 #endif
Generated on Thu Jul 14 2022 10:54:35 by
