-
Notifications
You must be signed in to change notification settings - Fork 0
/
scooper-scoop-utils.c
181 lines (150 loc) · 6.77 KB
/
scooper-scoop-utils.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <kovan/kovan.h>
#include "drive-utils.h"
#include "scooper-constants.h"
#include "utils.h"
#include "scoop-utils.h"
void open_doors_wide() {
clear_motor_position_counter(kMotorPortScoopDoor);
msleep(50);
motor(kMotorPortScoopDoor, 100);
while (get_motor_position_counter(kMotorPortScoopDoor) < kMotorPositionScoopDoorWide) {} //500
motor(kMotorPortScoopDoor, 0);
}
void open_doors_narrow() {
clear_motor_position_counter(kMotorPortScoopDoor);
msleep(50);
motor(kMotorPortScoopDoor, 100);
while (get_motor_position_counter(kMotorPortScoopDoor) < 500) {} //500
motor(kMotorPortScoopDoor, 0);
}
void close_doors_wide() {
clear_motor_position_counter(kMotorPortScoopDoor);
msleep(50);
motor(kMotorPortScoopDoor, -100);
while (get_motor_position_counter(kMotorPortScoopDoor) > -(kMotorPositionScoopDoorWide)) {} //was + 50
motor(kMotorPortScoopDoor, 0);
}
void raise_scoop_very_high() {
int time = 800;
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopMaxLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopMaxRight, time);
pthread_t tiltThreadLeft = set_servo_pos_millis_async(kServoPortScoopTiltLeft, kServoPositionScoopTiltVeryHigh, time);
pthread_t tiltThreadRight = set_servo_pos_millis_async(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltVeryHigh, time);
msleep(time);
pthread_cancel(tiltThreadLeft);
pthread_cancel(tiltThreadRight);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
}
void dump() {
set_servo_position(kServoPortScoopTiltLeft, kServoPositionScoopTiltDump);
set_servo_position(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltDump);
msleep(200);
}
void dump_shake() {
pthread_t threadLeaft = set_servo_pos_millis_async(kServoPortScoopTiltLeft, kServoPositionScoopTiltDumpLow, 300);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltDumpLow, 300);
msleep(300);
pthread_cancel(threadLeaft);
pthread_cancel(threadRight);
}
void lower_scoop() {
int time = 800;
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopBottomLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopBottomRight, time);
msleep(time);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
//set_servo_position(kServoPortScoopLeft, kServoPositionScoopBottomLeft);
//set_servo_position(kServoPortScoopRight, kServoPositionScoopBottomRight);
}
void lower_scoop_time(int time) {
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopBottomLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopBottomRight, time);
msleep(time);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
//set_servo_position(kServoPortScoopLeft, kServoPositionScoopBottomLeft);
//set_servo_position(kServoPortScoopRight, kServoPositionScoopBottomRight);
}
void mid_scoop_level() {
int time = 800;
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopMidLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopMidRight, time);
pthread_t tiltThreadLeft = set_servo_pos_millis_async(kServoPortScoopTiltLeft, kServoPositionScoopTiltLow, time);
pthread_t tiltThreadRight = set_servo_pos_millis_async(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltLow, time);
msleep(time);
pthread_cancel(tiltThreadLeft);
pthread_cancel(tiltThreadRight);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
}
void raise_scoop() {
int time = 800;
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopTopLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopTopRight, time);
msleep(time);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
}
void raise_scoop_level() {
int time = 800;
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopTopLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopTopRight, time);
pthread_t tiltThreadLeft = set_servo_pos_millis_async(kServoPortScoopTiltLeft, kServoPositionScoopTiltHigh, time);
pthread_t tiltThreadRight = set_servo_pos_millis_async(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltHigh, time);
msleep(time);
pthread_cancel(tiltThreadLeft);
pthread_cancel(tiltThreadRight);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
}
void lower_scoop_level() {
int time = 800;
pthread_t threadLeft = set_servo_pos_millis_async(kServoPortScoopLeft, kServoPositionScoopBottomLeft, time);
pthread_t threadRight = set_servo_pos_millis_async(kServoPortScoopRight, kServoPositionScoopBottomRight, time);
pthread_t tiltThreadLeft = set_servo_pos_millis_async(kServoPortScoopTiltLeft, kServoPositionScoopTiltLow, time);
pthread_t tiltThreadRight = set_servo_pos_millis_async(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltLow, time);
msleep(time);
pthread_cancel(tiltThreadLeft);
pthread_cancel(tiltThreadRight);
pthread_cancel(threadLeft);
pthread_cancel(threadRight);
}
void tilt_scoop_low() {
set_servo_position(kServoPortScoopTiltLeft, kServoPositionScoopTiltLow);
set_servo_position(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltLow);
}
void tilt_scoop_high() {
set_servo_position(kServoPortScoopTiltLeft, kServoPositionScoopTiltHigh);
set_servo_position(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltHigh);
}
void tilt_scoop_dump() {
set_servo_position(kServoPortScoopTiltLeft, kServoPositionScoopTiltDump);
set_servo_position(kServoPortScoopTiltRight, 2047 - kServoPositionScoopTiltDump);
}
void open_scoop_doors() {
clear_motor_position_counter(kMotorPortScoopDoor);
msleep(50);
motor(kMotorPortScoopDoor, 100);
while (get_motor_position_counter(kMotorPortScoopDoor) < kMotorPositionScoopDoor) {} //500
motor(kMotorPortScoopDoor, 0);
}
void close_scoop_doors() {
clear_motor_position_counter(kMotorPortScoopDoor);
msleep(50);
motor(kMotorPortScoopDoor, -100);
while (get_motor_position_counter(kMotorPortScoopDoor) > -(kMotorPositionScoopDoor + 50)) {} //700
motor(kMotorPortScoopDoor, 0);
}
void scoop() {
open_scoop_doors();
lower_scoop();
motor(0, 100);
motor(2, 100);
msleep(1000);
motor(0, 0);
motor(2, 0);
close_scoop_doors();
raise_scoop();
}