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

Committer:
danstrider
Date:
Mon Oct 23 12:50:53 2017 +0000
Revision:
10:085ab7328054
Parent:
9:d5fcdcb3c89d
Child:
11:3b241ecb75ed
checked out on the hardware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danstrider 10:085ab7328054 1 #ifndef LINEARACTUATOR_HPP
danstrider 10:085ab7328054 2 #define LINEARACTUATOR_HPP
mkelly10 9:d5fcdcb3c89d 3
mkelly10 9:d5fcdcb3c89d 4 #include "mbed.h"
mkelly10 9:d5fcdcb3c89d 5 #include "PololuHbridge.hpp"
danstrider 10:085ab7328054 6 #include "PidController.hpp"
mkelly10 9:d5fcdcb3c89d 7 #include "ltc1298.hpp"
mkelly10 9:d5fcdcb3c89d 8 #include "PosVelFilter.hpp"
mkelly10 9:d5fcdcb3c89d 9
mkelly10 9:d5fcdcb3c89d 10 //Dependencies
mkelly10 9:d5fcdcb3c89d 11 //This Class requires adc readings to sense the position of the piston
mkelly10 9:d5fcdcb3c89d 12 //This is a resource that ends up being shared among other classes in the vehicle
mkelly10 9:d5fcdcb3c89d 13 //for this reason it makes sense for it to be its own entity that is started in
mkelly10 9:d5fcdcb3c89d 14 //the main line code
mkelly10 9:d5fcdcb3c89d 15
danstrider 10:085ab7328054 16 class LinearActuator {
mkelly10 9:d5fcdcb3c89d 17 public:
mkelly10 9:d5fcdcb3c89d 18 LinearActuator(float interval, PinName pwm, PinName dir, PinName reset, PinName limit, int adc_ch);
mkelly10 9:d5fcdcb3c89d 19
mkelly10 9:d5fcdcb3c89d 20 // functions for setting up
mkelly10 9:d5fcdcb3c89d 21 void init();
mkelly10 9:d5fcdcb3c89d 22 void update();
mkelly10 9:d5fcdcb3c89d 23 void start();
mkelly10 9:d5fcdcb3c89d 24 void stop();
mkelly10 9:d5fcdcb3c89d 25 void pause();
mkelly10 9:d5fcdcb3c89d 26 void unpause();
mkelly10 9:d5fcdcb3c89d 27
mkelly10 9:d5fcdcb3c89d 28 void refreshPVState();
mkelly10 9:d5fcdcb3c89d 29
mkelly10 9:d5fcdcb3c89d 30 // setting and getting variables
mkelly10 9:d5fcdcb3c89d 31 void setPosition_mm(float dist);
mkelly10 9:d5fcdcb3c89d 32 float getPosition_mm();
mkelly10 9:d5fcdcb3c89d 33 float getVelocity_mms();
danstrider 10:085ab7328054 34 // float getPosition_counts();
mkelly10 9:d5fcdcb3c89d 35
mkelly10 9:d5fcdcb3c89d 36 void setControllerP(float P);
mkelly10 9:d5fcdcb3c89d 37 float getControllerP();
mkelly10 9:d5fcdcb3c89d 38
mkelly10 9:d5fcdcb3c89d 39 void setControllerI(float I);
mkelly10 9:d5fcdcb3c89d 40 float getControllerI();
mkelly10 9:d5fcdcb3c89d 41
mkelly10 9:d5fcdcb3c89d 42 void setControllerD(float D);
mkelly10 9:d5fcdcb3c89d 43 float getControllerD();
mkelly10 9:d5fcdcb3c89d 44
mkelly10 9:d5fcdcb3c89d 45 void setZeroCounts(int zero);
mkelly10 9:d5fcdcb3c89d 46 int getZeroCounts();
mkelly10 9:d5fcdcb3c89d 47
mkelly10 9:d5fcdcb3c89d 48 void setTravelLimit(float limit);
mkelly10 9:d5fcdcb3c89d 49 float getTravelLimit();
mkelly10 9:d5fcdcb3c89d 50
mkelly10 9:d5fcdcb3c89d 51 void setPotSlope(float slope);
mkelly10 9:d5fcdcb3c89d 52 float getPotSlope();
mkelly10 9:d5fcdcb3c89d 53
mkelly10 9:d5fcdcb3c89d 54 void homePiston();
danstrider 10:085ab7328054 55 bool getSwitch();
mkelly10 9:d5fcdcb3c89d 56
mkelly10 9:d5fcdcb3c89d 57 float getOutput();
mkelly10 9:d5fcdcb3c89d 58
danstrider 10:085ab7328054 59 void setFilterFrequency(float frequency);
mkelly10 9:d5fcdcb3c89d 60
mkelly10 9:d5fcdcb3c89d 61 void setDeadband(float deadband);
mkelly10 9:d5fcdcb3c89d 62 bool toggleDeadband(bool toggle);
mkelly10 9:d5fcdcb3c89d 63
mkelly10 9:d5fcdcb3c89d 64 protected:
mkelly10 9:d5fcdcb3c89d 65 PololuHBridge _motor;
mkelly10 9:d5fcdcb3c89d 66 PosVelFilter _filter;
mkelly10 9:d5fcdcb3c89d 67 PIDController _pid;
mkelly10 9:d5fcdcb3c89d 68 Ticker _pulse;
mkelly10 9:d5fcdcb3c89d 69 InterruptIn _limitSwitch;
mkelly10 9:d5fcdcb3c89d 70
mkelly10 9:d5fcdcb3c89d 71 void _switchPressed();
mkelly10 9:d5fcdcb3c89d 72 void _switchReleased();
mkelly10 9:d5fcdcb3c89d 73 void _calculateSensorSlope();
mkelly10 9:d5fcdcb3c89d 74
mkelly10 9:d5fcdcb3c89d 75 bool _init;
mkelly10 9:d5fcdcb3c89d 76 bool _paused;
mkelly10 9:d5fcdcb3c89d 77 bool _limit;
mkelly10 9:d5fcdcb3c89d 78
mkelly10 9:d5fcdcb3c89d 79 int _adc_channel;
mkelly10 9:d5fcdcb3c89d 80
mkelly10 9:d5fcdcb3c89d 81 float _filterFrequency;
mkelly10 9:d5fcdcb3c89d 82
mkelly10 9:d5fcdcb3c89d 83 float _dt;
mkelly10 9:d5fcdcb3c89d 84
mkelly10 9:d5fcdcb3c89d 85 float _SetPoint_mm;
mkelly10 9:d5fcdcb3c89d 86
danstrider 10:085ab7328054 87 // position and velocity in counts (PVF runs on counts)
mkelly10 9:d5fcdcb3c89d 88 float _position;
danstrider 10:085ab7328054 89 float _velocity;
danstrider 10:085ab7328054 90
danstrider 10:085ab7328054 91 // position and velocity converted to mm and mm/s
mkelly10 9:d5fcdcb3c89d 92 float _position_mm;
mkelly10 9:d5fcdcb3c89d 93 float _velocity_mms;
mkelly10 9:d5fcdcb3c89d 94
danstrider 10:085ab7328054 95 // linear actuator servo PID gains
mkelly10 9:d5fcdcb3c89d 96 float _Pgain;
mkelly10 9:d5fcdcb3c89d 97 float _Igain;
mkelly10 9:d5fcdcb3c89d 98 float _Dgain;
mkelly10 9:d5fcdcb3c89d 99
mkelly10 9:d5fcdcb3c89d 100 float _deadband;
mkelly10 9:d5fcdcb3c89d 101
mkelly10 9:d5fcdcb3c89d 102 int _zeroCounts; //gets assigned by homing function. can also be stored in config
mkelly10 9:d5fcdcb3c89d 103 float _extendLimit; //config variable, limits the extension of the piston, this is same as datum for normal operation,
mkelly10 9:d5fcdcb3c89d 104
mkelly10 9:d5fcdcb3c89d 105 float _slope;
mkelly10 9:d5fcdcb3c89d 106 int dist_to_counts(float dist);
mkelly10 9:d5fcdcb3c89d 107 float counts_to_dist(int count);
mkelly10 9:d5fcdcb3c89d 108 float counts_to_velocity(int count);
mkelly10 9:d5fcdcb3c89d 109
mkelly10 9:d5fcdcb3c89d 110 };
danstrider 10:085ab7328054 111
danstrider 10:085ab7328054 112
danstrider 10:085ab7328054 113 template <typename T>
danstrider 10:085ab7328054 114 T clamp(T value, T min, T max)
danstrider 10:085ab7328054 115 {
danstrider 10:085ab7328054 116 if(value < min) {
danstrider 10:085ab7328054 117 return min;
danstrider 10:085ab7328054 118 } else if(value > max) {
danstrider 10:085ab7328054 119 return max;
danstrider 10:085ab7328054 120 } else {
danstrider 10:085ab7328054 121 return value;
danstrider 10:085ab7328054 122 }
danstrider 10:085ab7328054 123 };
danstrider 10:085ab7328054 124
mkelly10 9:d5fcdcb3c89d 125 #endif