most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown
Dependencies: mbed MODSERIAL FATFileSystem
Diff: LinearActuator/LinearActuator.hpp
- Revision:
- 9:d5fcdcb3c89d
- Child:
- 10:085ab7328054
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LinearActuator/LinearActuator.hpp Fri Oct 20 11:41:22 2017 +0000 @@ -0,0 +1,116 @@ +#ifndef BCE_HPP +#define BCE_HPP + +#include "mbed.h" +#include "PololuHbridge.hpp" +#include "controller.hpp" +#include "ltc1298.hpp" +#include "PosVelFilter.hpp" + +//Dependencies +//This Class requires adc readings to sense the position of the piston +//This is a resource that ends up being shared among other classes in the vehicle +//for this reason it makes sense for it to be its own entity that is started in +//the main line code + +class LinearActuator +{ +public: + //BuoyancyEngine(PololuHBridge motor, SpiADC adc, PosVelFilter filter, PositionController pid); + LinearActuator(float interval, PinName pwm, PinName dir, PinName reset, PinName limit, int adc_ch); + + // functions for setting up + void init(); + void update(); + void start(); + void stop(); + void pause(); + void unpause(); + + void refreshPVState(); + + // setting and getting variables + void setPosition_mm(float dist); + + float getPosition_mm(); + float getPosition_counts(); + + float getVelocity_mms(); + + void setControllerP(float P); + float getControllerP(); + + void setControllerI(float I); + float getControllerI(); + + void setControllerD(float D); + float getControllerD(); + + void setZeroCounts(int zero); + int getZeroCounts(); + + void setTravelLimit(float limit); + float getTravelLimit(); + + void setPotSlope(float slope); + float getPotSlope(); + + void homePiston(); + void setFilterFrequency(float frequency); + + float getOutput(); + + bool getSwitch(); + + void setDeadband(float deadband); + bool toggleDeadband(bool toggle); + +protected: + PololuHBridge _motor; + PosVelFilter _filter; + PIDController _pid; + //Timer _time; + Ticker _pulse; + InterruptIn _limitSwitch; + + void _switchPressed(); + void _switchReleased(); + void _calculateSensorSlope(); + + + bool _init; + bool _paused; + bool _limit; + + int _adc_channel; + + float _filterFrequency; + + float _dt; + + float _SetPoint_mm; + + float _position; + float _position_mm; + + float _velocity; + float _velocity_mms; + + float _Pgain; + float _Igain; + float _Dgain; + + float _deadband; + + int _zeroCounts; //gets assigned by homing function. can also be stored in config + float _extendLimit; //config variable, limits the extension of the piston, this is same as datum for normal operation, + float _pos_vel_wn; //config variable, natural frequecny of the position velocity filter + + float _slope; + int dist_to_counts(float dist); + float counts_to_dist(int count); + float counts_to_velocity(int count); + +}; + +#endif \ No newline at end of file