Skip to content

Commit

Permalink
Update motor start
Browse files Browse the repository at this point in the history
- enforced motor off before any move
- removed state checks before motor move

Signed-off-by: Martin Mihálek <aenniw@gmail.com>
  • Loading branch information
aenniw committed Nov 6, 2018
1 parent e9cb23f commit 10a3026
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions skarsta/lib/motor/Motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ void Motor::off()
if (mode != UNCALIBRATED)
updateEEPROM(ADDRESS_POSITION, position);
#endif
if (state == OFF)
{
return;
}

digitalWrite(power_pin, HIGH);
#ifdef __DEBUG__
Serial.print("m off ");
Expand All @@ -66,32 +61,32 @@ void Motor::off()

void Motor::dir_cw()
{
if (state == CW || (position >= end_stop && mode == CALIBRATED))
if (position >= end_stop && mode == CALIBRATED)
{
return;
}

#ifdef __DEBUG__
Serial.println("m cw");
#endif
digitalWrite(power_pin, HIGH);
digitalWrite(dir_pin, HIGH);
delay(DIRECTION_CHANGE_DELAY);
digitalWrite(power_pin, LOW);
state = CW;
}

void Motor::dir_ccw()
{
if (state == CCW || (position <= 0 && mode != UNCALIBRATED))
if (position <= 0 && mode != UNCALIBRATED)
{
return;
}

#ifdef __DEBUG__
Serial.println("m ccw");
#endif
digitalWrite(power_pin, HIGH);
digitalWrite(dir_pin, LOW);
delay(DIRECTION_CHANGE_DELAY);
digitalWrite(power_pin, LOW);
state = CCW;
}
Expand Down

0 comments on commit 10a3026

Please sign in to comment.