Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leak detecting #18

Closed
wants to merge 10 commits into from
20 changes: 20 additions & 0 deletions src/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ bool AnalogKillSwitch::getValueThresh() {
return (getValueRaw() > threshold);
}


LeakDetector::LeakDetector(PinName pin, float thresh) :
AnalogInput(pin),
threshold(thresh)
{

}

LeakDetector::~LeakDetector() {}

void updateLeak()
{
hasLeak = leakDetector.getValueThresh();
}

bool LeakDetector::getValueThresh()
{
return (getValueRaw() > threshold);
}

void updateKill() {
isAlive = kill.getValueThresh();
}
19 changes: 18 additions & 1 deletion src/analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/*
* Generic class for devices that output analog to the mbed.
* Currently, these are the pressure sensor and the killswitch.
* Currently, these are the pressure sensor, leak detector, and killswitch.
*/
class AnalogInput {
public:
Expand Down Expand Up @@ -52,12 +52,29 @@ class AnalogKillSwitch : public AnalogInput {
float value, threshold;
};

class LeakDetector : AnalogInput
{
public:
LeakDetector(PinName pin, float thresh);
~LeakDetector();

bool getValueThresh();

private:
float threshold;

};

extern volatile bool hasLeak;
void updateLeak();


void updateKill();

//The two analog devices are the killswitch and pressure sensor.
extern AnalogKillSwitch kill;
extern AnalogPressureSensor pressure;
extern LeakDetector leakDetector;
extern volatile bool isAlive;

#endif
5 changes: 3 additions & 2 deletions src/avnavcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ int main() {
imu.p_device->attach(&rx_interrupt_imu, Serial::RxIrq);

//create the tickers here
Ticker tick[5];
Ticker tick[6];
if (!debug) {
tick[0].attach(&send_status_pc, 0.1);
}
tick[1].attach(&do_pid, DT);
tick[2].attach(&motor_send_wrapper, DT/2);
tick[3].attach(&updateKill, .01);
tick[4].attach(&updatePressure, 0.1);
tick[5].attach(&updateLeak, .01);

while (true) {
while (!hasLeak) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we stop running the main loop upon leak, the mbed will appear to have crashed. Also, pololu may still have motor values cached.

if (!motor.isTxEmpty()) {
tx_interrupt_motor();
}
Expand Down
4 changes: 4 additions & 0 deletions src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// TODO: check the magic threshold 0.85f. Too high/low?
AnalogKillSwitch kill(p16, p18, 0.85f); // Vin, Vout

//TODO: I picked 0.85f because that's what kill used. Check this.
LeakDetector leakDetector(p20, 0.85f); //pin 20

/*
* Daniel's was depth = adc_buffer[ADC_PRESS] * 0.361904762 - 101.33333;
* That was based on the dsPIC33FJ family's ADC converter.
Expand Down Expand Up @@ -47,3 +50,4 @@ bool debug = false;

volatile bool isAlive = false;
volatile int depth(0);
volatile bool hasLeak = false;