SmartVehicle-Basis
SmartFactory
Hoist.cpp
Go to the documentation of this file.
1 
19 #include "Hoist.h"
20 
21 //=====PUBLIC====================================================================================
22 Hoist::Hoist(int hoistServoPin, int hoistServoDelay, int posMax, int posMin) : servoPin(hoistServoPin),
23  position(posMin),
24  positionMin(posMin),
25  positionMax(posMax),
26  servoDelay(hoistServoDelay) {
27  DBFUNCCALLln("Hoist::Hoist(int hoistServoPin, int hoistServoDelay, int posMax, int posMin)");
28  Hoist::init();
29 }
30 
31 /*
32  * hoistServo.read() only reads the current angle of the servo (the value passed to the LAST call to write()).
33  */
34 void Hoist::init() {
35  Hoist::attach();
36  position -= 5; //lift the hoist some degree so that the lower-function works correctly
37  while (!lower()) {
38  }
39  Hoist::detach();
40 }
41 
42 bool Hoist::raise() {
43  DBFUNCCALLln("Hoist::raise()");
44  currentMillis = millis();
47  if (position > positionMax) {
48  position--;
49  hoistServo.write(position); //< Update Servo-position
50  }
51  }
52  if (position == positionMax) {
53  DBSTATUSln("Hoist raised!");
54  return true;
55  }
56  return false;
57 }
58 
59 bool Hoist::lower() {
60  DBFUNCCALLln("Hoist::lower()");
61  currentMillis = millis();
64  if (position < positionMin) {
65  position++;
66  hoistServo.write(position);
67  }
68  }
69  if (position == positionMin) {
70  DBSTATUSln("Hoist lowered!");
71  return true;
72  }
73  return false;
74 }
75 
76 //=====PRIVATE====================================================================================
void detach()
detach servo from servopin
Definition: Hoist.h:76
void init()
Initialise the Hoist in the low position.
Definition: Hoist.cpp:34
bool lower()
Lower the Hoist 1° per servodelay/call until it's at positionMin.
Definition: Hoist.cpp:59
unsigned long currentMillis
will store current time for non blocking delay
Definition: Hoist.h:89
int servoDelay
delay in ms between raise/lower per 1 degree. This sets the servospeed
Definition: Hoist.h:87
int positionMin
minimal possible position (Hardware-Restriction)
Definition: Hoist.h:85
int positionMax
maximal possible position (Hardware-Restriction)
Definition: Hoist.h:86
int position
actual servo-position
Definition: Hoist.h:84
Servo hoistServo
Instance of servo object.
Definition: Hoist.h:82
bool raise()
Raise the Hoist 1° per servodelay/call until it's at positionMax.
Definition: Hoist.cpp:42
The Class Hoist provides the basic functions for the hoist.
void attach()
attache servo to servopin
Definition: Hoist.h:67
unsigned long previousMillis
will store last time called for non blocking delay
Definition: Hoist.h:90