Commit c5e40cb3 authored by markus's avatar markus

Support stop and brake

parent 650c8164
#include "brake.h"
Brake::Brake(int brake_pin, int release_cache_in_ms)
Brake::Brake(int brake_pin, int release_delay_in_ms)
{
last_release_ = 0;
brake_counter_ = 0;
brake_tightened_ = true;
brake_pin_ = brake_pin;
release_cache_in_ms_ = release_cache_in_ms;
brake_tightened_ = true;
release_delay_in_ms_ = release_delay_in_ms;
//Pin Settings
pinMode(brake_pin_, OUTPUT);
......@@ -22,7 +22,7 @@ void Brake::doBreak()
if(brake_tightened_ == false)
{
int diff = millis() - last_release_;
if((diff > release_cache_in_ms_) || (diff < 0))
if((diff > release_delay_in_ms_) || (diff < 0))
{
digitalWrite(brake_pin_, HIGH);
brake_tightened_ = true;
......@@ -37,6 +37,11 @@ void Brake::doBreak()
}
}
void Brake::skipDelay()
{
last_release_ = millis() - release_delay_in_ms_ - 1;
}
void Brake::release()
{
last_release_ = millis();
......
......@@ -7,16 +7,17 @@
class Brake
{
public:
Brake(int brake_pin, int release_cache_in_ms);
Brake(int brake_pin, int release_delay_in_ms);
void doBreak();
void tighten();
void release();
void skipDelay();
private:
int last_release_;
int brake_counter_;
int brake_pin_;
int release_cache_in_ms_;
int release_delay_in_ms_;
byte brake_tightened_;
};
......
......@@ -99,5 +99,15 @@ Control::hamlibError Control::executeActiveCommandSubstring(String substring)
if(err == Motor::ROT_VAL_OUT_OF_RANGE)
return HAMLIB_NOK;
}
else if (substring == "stop") {
rotor_->stopAzimuth();
rotor_->stopElevation();
}
else if (substring == "brake") {
rotor_->stopAndBreakAzimuth();
rotor_->stopAndBreakElevation();
}
else
return HAMLIB_NOK;
return HAMLIB_OK;
}
......@@ -14,17 +14,15 @@ public:
ROT_ALREADY_IN_SPAN };
Motor(double max, double min, int down_pin, int up_pin, Brake *brake, int sensor_pin, double degree, double resolution, double span);
void doMotor();
void stop();
double getPosition() const;
motorError setPosition(double);
private:
void releaseBrake();
void tightenBrake();
void stop();
motorError setPosition(double);
motorError rotateUp();
motorError rotateDown();
private:
motorError readMotSensor();
double readADC(int);
......
......@@ -14,26 +14,6 @@ void Rotor::doRotor()
brake_->doBreak();
}
void Rotor::releaseBrakeAzimuth()
{
azimuth_->releaseBrake();
}
void Rotor::releaseBrakeElevation()
{
elevation_->releaseBrake();
}
void Rotor::tightenBrakeAzimuth()
{
azimuth_->tightenBrake();
}
void Rotor::tightenBrakeElevation()
{
elevation_->tightenBrake();
}
void Rotor::stopAzimuth()
{
azimuth_->stop();
......@@ -44,24 +24,16 @@ void Rotor::stopElevation()
elevation_->stop();
}
Motor::motorError Rotor::rotateCW()
{
return azimuth_->rotateDown();
}
Motor::motorError Rotor::rotateCCW()
{
return azimuth_->rotateUp();
}
Motor::motorError Rotor::rotateUp()
void Rotor::stopAndBreakAzimuth()
{
return elevation_->rotateUp();
stopAzimuth();
brake_->skipDelay();
}
Motor::motorError Rotor::rotateDown()
void Rotor::stopAndBreakElevation()
{
return elevation_->rotateDown();
stopElevation();
brake_->skipDelay();
}
double Rotor::getAzimuth() const
......
......@@ -21,20 +21,13 @@ public:
double getAzimuth() const;
double getElevation() const;
void releaseBrakeAzimuth();
void releaseBrakeElevation();
void tightenBrakeAzimuth();
void tightenBrakeElevation();
void stopAzimuth();
void stopElevation();
void stopAndBreakAzimuth();
void stopAndBreakElevation();
Motor::motorError setAzimuth(double);
Motor::motorError setElevation(double);
Motor::motorError rotateCW();
Motor::motorError rotateCCW();
Motor::motorError rotateUp();
Motor::motorError rotateDown();
private:
Motor *azimuth_;
Motor *elevation_;
......
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