-
Notifications
You must be signed in to change notification settings - Fork 0
/
motors-setup.srv.h
54 lines (42 loc) · 1009 Bytes
/
motors-setup.srv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Encoder encoder(ENCODER1_PIN, ENCODER2_PIN);
VarSpeedServo myServo;
// SERVO
void attachServo()
{
Serial.println("attachServo()");
myServo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object
}
void detachServo()
{
Serial.println("detachServo()");
myServo.detach();
}
// ENCODER
void attachEncoder(Encoder *encoder)
{
Serial.println("Starting encoder");
pinMode(DIR1_PWM_PIN, OUTPUT);
pinMode(DIR2_PWM_PIN, OUTPUT);
encoder->write(0);
isEncoderMoving = false;
Serial.println(String("encoder loc: ") + (abs(encoder->read())));
}
boolean detachEncoder()
{
Serial.println("Stopping encoder");
//stop motor
digitalWrite(DIR1_PWM_PIN, LOW);
digitalWrite(DIR2_PWM_PIN, LOW);
delay(1000);
// release motor hold
pinMode(DIR1_PWM_PIN, INPUT);
pinMode(DIR2_PWM_PIN, INPUT);
}
// GENERAL
void finishPain()
{
Serial.println(String("finishPain()"));
state = BEFORE_START;
detachServo();
detachEncoder();
}