Commit 2c4a4417 authored by markus's avatar markus

Wait before tightening brake after usage

parent 350793b0
#include "brake.h"
Brake::Brake(int brake_pin)
Brake::Brake(int brake_pin, int release_cache_in_ms)
{
last_release_ = 0;
brake_counter_ = 0;
brake_tightened_ = true;
brake_pin_ = brake_pin;
release_cache_in_ms_ = release_cache_in_ms;
//Pin Settings
pinMode(brake_pin_, OUTPUT);
......@@ -16,16 +19,27 @@ void Brake::doBreak()
{
if(brake_counter_ == 0)
{
digitalWrite(brake_pin_, HIGH);
if(brake_tightened_ == false)
{
int diff = millis() - last_release_;
if((diff > release_cache_in_ms_) || (diff < 0))
{
digitalWrite(brake_pin_, HIGH);
brake_tightened_ = true;
}
}
}
else
{
digitalWrite(brake_pin_, LOW);
last_release_ = millis();
brake_tightened_ = false;
}
}
void Brake::release()
{
last_release_ = millis();
brake_counter_++;
}
......
......@@ -7,14 +7,17 @@
class Brake
{
public:
Brake(int brake_pin);
Brake(int brake_pin, int release_cache_in_ms);
void doBreak();
void tighten();
void release();
private:
int last_release_;
int brake_counter_;
int brake_pin_;
int release_cache_in_ms_;
byte brake_tightened_;
};
#endif //BRAKE_H
......@@ -2,7 +2,7 @@
Rotor::Rotor()
{
brake_ = new Brake(AZIM_RE_BREAK);
brake_ = new Brake(AZIM_RE_BREAK, 10000);
azimuth_ = new Motor(AZIM_MAX, AZIM_MIN, AZIM_RE_CW, AZIM_RE_CCW, brake_, AZIM_POT, AZIM_DEG, AZIM_RES, AZIM_SPAN);
elevation_ = new Motor(ELEV_MAX, ELEV_MIN, ELEV_RE_DWN, ELEV_RE_UP, brake_, ELEV_POT, ELEV_DEG, ELEV_RES, ELEV_SPAN);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment