-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlac_control.ino
93 lines (78 loc) · 1.9 KB
/
lac_control.ino
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*This file controls the PQ12 linear actuator that opens and closes the claw*/
#include "tow_controller.h"
int lac_min =0;
int lac_max =1000;
void lac_setup()
{
pinMode(DC_MOTOR_EN, OUTPUT);
pinMode(DC_MOTOR_1, OUTPUT);
pinMode(DC_MOTOR_2, OUTPUT);
pinMode(DC_POT_PIN, INPUT);
pinMode(HAIRTRIGGER_PIN,INPUT_PULLUP);
}
claw_state grab()
{
PRINTLN("grabbing");
int lac_d = lac_state();
if(lac_d <95){
PRINTLN("extending ");
PRINT(" lac_d ");
PRINTLN(lac_d);
analogWrite(DC_MOTOR_EN, HIGH);
digitalWrite(DC_MOTOR_1, LOW);
digitalWrite(DC_MOTOR_2, HIGH);
return CLAW_CLOSING;
}
else
return CLAW_CLOSED;
}
claw_state release()
{
PRINTLN("release");
int lac_d = lac_state();
if(lac_d >5){
PRINT(" lac_d ");
PRINTLN(lac_d);
analogWrite(DC_MOTOR_EN, HIGH);
digitalWrite(DC_MOTOR_2, LOW);
digitalWrite(DC_MOTOR_1, HIGH);
return CLAW_OPENING;
}
else
return CLAW_OPEN;
}
void stop_actuator()
{
analogWrite(DC_MOTOR_EN, LOW);
digitalWrite(DC_MOTOR_2, LOW);
digitalWrite(DC_MOTOR_1, LOW);
}
void calibrate_lac()
{
/*analogWrite(DC_MOTOR_EN, HIGH);*/
digitalWrite(DC_MOTOR_2, LOW);
digitalWrite(DC_MOTOR_1, HIGH);
delay(1500);
lac_min = analogRead(DC_POT_PIN);
PRINT("lac min: ");
PRINTLN(lac_min);
/*analogWrite(DC_MOTOR_EN, HIGH);*/
digitalWrite(DC_MOTOR_1, LOW);
digitalWrite(DC_MOTOR_2, HIGH);
delay(1500);
lac_max = analogRead(DC_POT_PIN);
PRINT("lac max: ");
PRINTLN(lac_max);
/*analogWrite(DC_MOTOR_EN, HIGH);*/
digitalWrite(DC_MOTOR_2, LOW);
digitalWrite(DC_MOTOR_1, HIGH);
delay(1000);
stop_actuator();
}
int lac_state()
{
int lacp_val = analogRead(DC_POT_PIN);
/*PRINT(" lac_p ");*/
/*PRINTLN(lacp_val);*/
return map(lacp_val,lac_min,lac_max,0,100);;
}