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:
joel_ssc
Date:
Mon May 13 19:25:26 2019 +0000
Revision:
92:52a91656458a
Parent:
74:d281aaef9766
version for first flight test, timeouts not yet set correctly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tnhnrl 52:f207567d3ea4 1 #ifndef SERVODRIVER_HPP
tnhnrl 52:f207567d3ea4 2 #define SERVODRIVER_HPP
tnhnrl 52:f207567d3ea4 3
tnhnrl 52:f207567d3ea4 4 #include "mbed.h"
tnhnrl 52:f207567d3ea4 5
tnhnrl 52:f207567d3ea4 6 class ServoDriver {
tnhnrl 52:f207567d3ea4 7 public:
tnhnrl 52:f207567d3ea4 8 ServoDriver(PinName pwm);
tnhnrl 52:f207567d3ea4 9
tnhnrl 52:f207567d3ea4 10 void endPoints(float lower_endpoint, float upper_endpoint);
tnhnrl 52:f207567d3ea4 11 void neutralPosition(float input_neutral_position);
tnhnrl 52:f207567d3ea4 12 void setPosition_deg(float input_position);
tnhnrl 52:f207567d3ea4 13
tnhnrl 74:d281aaef9766 14 void setPWM(float input_pwm); // 8/2/2018
tnhnrl 74:d281aaef9766 15
tnhnrl 52:f207567d3ea4 16 float slope();
tnhnrl 52:f207567d3ea4 17
tnhnrl 52:f207567d3ea4 18 void setMinPWM(float pwm_input);
tnhnrl 52:f207567d3ea4 19 void setMaxPWM(float pwm_input);
tnhnrl 52:f207567d3ea4 20 void setCenterPWM(float pwm_input);
tnhnrl 52:f207567d3ea4 21 void setMinDeg(float deg);
tnhnrl 52:f207567d3ea4 22 void setMaxDeg(float deg);
tnhnrl 52:f207567d3ea4 23
tnhnrl 74:d281aaef9766 24 float getSetPosition_deg();
tnhnrl 74:d281aaef9766 25 float getSetPosition_pwm();
tnhnrl 52:f207567d3ea4 26
tnhnrl 52:f207567d3ea4 27 void init();
tnhnrl 52:f207567d3ea4 28
tnhnrl 52:f207567d3ea4 29 void pwm_pulse_off();
tnhnrl 52:f207567d3ea4 30 void pwm_pulse_on();
tnhnrl 52:f207567d3ea4 31 void pause();
tnhnrl 52:f207567d3ea4 32 void unpause();
tnhnrl 52:f207567d3ea4 33
tnhnrl 52:f207567d3ea4 34 void runServo();
tnhnrl 52:f207567d3ea4 35
tnhnrl 52:f207567d3ea4 36 float getMinPWM();
tnhnrl 52:f207567d3ea4 37 float getMaxPWM();
tnhnrl 52:f207567d3ea4 38 float getCenterPWM();
tnhnrl 52:f207567d3ea4 39 float getMinDeg();
tnhnrl 52:f207567d3ea4 40 float getMaxDeg();
tnhnrl 52:f207567d3ea4 41
tnhnrl 52:f207567d3ea4 42 private:
tnhnrl 52:f207567d3ea4 43 float _min_pwm;
tnhnrl 52:f207567d3ea4 44 float _max_pwm;
tnhnrl 52:f207567d3ea4 45 float _center_pwm;
tnhnrl 52:f207567d3ea4 46 float _min_deg;
tnhnrl 52:f207567d3ea4 47 float _max_deg;
tnhnrl 52:f207567d3ea4 48
tnhnrl 74:d281aaef9766 49 volatile bool _paused;
tnhnrl 74:d281aaef9766 50
tnhnrl 52:f207567d3ea4 51 float _degrees_set_position;
tnhnrl 52:f207567d3ea4 52
tnhnrl 52:f207567d3ea4 53 volatile unsigned int _valid_servo_position_pwm; //signal in microseconds, for example 1580 microseconds (close to center of servo)
tnhnrl 52:f207567d3ea4 54 volatile unsigned int _period_cnt;
tnhnrl 52:f207567d3ea4 55
tnhnrl 52:f207567d3ea4 56 Ticker pwm_pulse_on_ticker;
tnhnrl 52:f207567d3ea4 57 Ticker pwm_pulse_off_ticker;
tnhnrl 52:f207567d3ea4 58 Timeout pwm_pulse_off_timeout;
tnhnrl 52:f207567d3ea4 59
tnhnrl 52:f207567d3ea4 60 DigitalOut _pwm_out; //cannot be volatile
tnhnrl 52:f207567d3ea4 61 };
tnhnrl 52:f207567d3ea4 62
tnhnrl 52:f207567d3ea4 63 template <typename T>
tnhnrl 52:f207567d3ea4 64 T servoClamp(T value, T min, T max)
tnhnrl 52:f207567d3ea4 65 {
tnhnrl 52:f207567d3ea4 66 if(value < min) {
tnhnrl 52:f207567d3ea4 67 return min;
tnhnrl 52:f207567d3ea4 68 } else if(value > max) {
tnhnrl 52:f207567d3ea4 69 return max;
tnhnrl 52:f207567d3ea4 70 } else {
tnhnrl 52:f207567d3ea4 71 return value;
tnhnrl 52:f207567d3ea4 72 }
tnhnrl 52:f207567d3ea4 73 };
tnhnrl 52:f207567d3ea4 74
tnhnrl 52:f207567d3ea4 75 #endif