Last active 2 hours ago

Revision 670c8d0f9130c6ebd4a83b8dd169ed8a370bde89

mecanum_route.c Raw
1#include <kipr/wombat.h>
2#include <stdlib.h>
3#define BLACK_VALUE 3700
4//comment
5
6int stop_at_line(int min_ticks){
7 if(analog(1)>BLACK_VALUE && gmpc(0)> min_ticks){
8 printf("reach end of ramp\n");
9 return 1;
10 }
11 printf("keep going analog_1=%d, gmpc_0=%d\n",analog(1), gmpc(0));
12 return 0;
13}
14void follow_the_line(){
15 if (analog(0)<BLACK_VALUE){
16 motor(0,90);
17 motor(1,15);
18 motor(2,90);
19 motor(3,15);
20 }
21 else{
22 motor(0,15);
23 motor(1,90);
24 motor(2,15);
25 motor(3,90);
26 }
27}
28
29int down_ramp()
30{
31 printf("down ramp\n");
32
33 motor(0,100);
34 motor(1,100);
35 motor(2,100);// square up
36 motor(3,100);
37 msleep(2200);
38 cmpc(0);
39 while (stop_at_line(9000) ==0){
40 follow_the_line();
41 msleep(30);
42 }
43 return 0;
44}
45int up_ramp(){
46 printf("up ramp/n");
47 motor(0,100);
48 motor(1,100);
49 motor(2,100);
50 motor(3,100);
51 msleep(5500);
52
53 cmpc(0);
54 while (stop_at_line(6000) ==0){
55 follow_the_line();
56 msleep(30);
57 }
58 return 0;
59}
60
61void mechanum_drive_forward_tick(int distance){
62 cmpc(0);
63 int direction;
64 if(distance > 0){
65 direction = 1;
66 } else {direction = -1;}
67 motor(0,70*direction);
68 motor(1,70*direction);
69 motor(2,70*direction);
70 motor(3,70*direction);
71 int target_pos = distance;
72 while(abs(gmpc(0)) < abs(target_pos)){
73 printf("zzz...\n\n");
74 msleep(10);
75 }
76 ao();
77}
78
79void section_1() {
80 /*
81 * Task: Drive from upper floor start box to the lower start box while pushing poms, then drops the poms
82 * turns right and drives into the middle area and strafes sideways until lined up with the doors
83 *
84 * Start Position: upper start box facing ramp
85 * End Position: facing doors, backed against the side of the upper storage
86 *
87 */
88 down_ramp();
89
90 ao();
91 msleep(500);
92
93 motor(0,100);
94 motor(1,100);
95 motor(2,100);
96 motor(3,100);
97 msleep(1000);
98
99 ao();
100 msleep(500);
101
102 motor(0,-100);
103 motor(1,-100);
104 motor(2,100);
105 motor(3,100);
106 msleep(1160);
107
108 ao();
109 msleep(500);
110
111 motor(0,-100);
112 motor(1,-100);
113 motor(2,-100);
114 motor(3,-100);
115 msleep(1000);
116
117 ao();
118 msleep(500);
119
120 // End section_1
121}
122
123void section_2(){
124 /*
125 Task: drive forward, open the doors, grab botguy, backup
126
127 Start position: back against the wall facing the doors
128 End position: back against the wall facing the doors
129 */
130 printf("ROUTE#I\n\n");
131
132 cmpc(0);
133 while (stop_at_line(50) ==0){
134 motor(0,100);
135 motor(1,100);
136 motor(2,100);
137 motor(3,100);
138 msleep(30);
139 }
140 ao();
141 msleep(900);
142 //code for moving left
143 motor(0,70);
144 motor(1,-70);
145 motor(2,70);
146 motor(3,-70);
147 msleep(8000);
148 mechanum_drive_forward_tick(2000);
149}
150
151void section_3() {
152 /*
153 Task: strafe left until it's in front of the start box, backs up and squares up against the outer wall,
154 then turns right and backs up to square up against outer wall while facing the ramp
155
156 Start Position: back against the upper storage wall facing the doors
157 End Position: back against outer wall facing the ramp
158
159 */
160 motor(0,-100);
161 motor(1,-100);
162 motor(2,-100);
163 motor(3,-100);
164 msleep(700);
165 printf("go backwards\n");
166 set_servo_position(3,2047);//put down arm
167 msleep(1000);
168 printf("arm down\n");
169 set_servo_position(0,2047);//close claw //pick up cone
170 msleep(1000);
171 printf("claw closed\n");
172 set_servo_position(0,900);//open claw
173 msleep(1000);
174 printf("claw open\n");
175 motor(0,-100);
176 motor(1,100);
177 motor(2,-100);
178 motor(3,100);
179 msleep(4600);
180 printf("go sideways\n");
181 motor(0,-100);
182 motor(1,-100);
183 motor(2,-100);
184 motor(3,-100);
185 msleep(3300);
186 printf("go backwards\n");
187 motor(0,-100);
188 motor(1,-100);
189 motor(2,100);
190 motor(3,100);
191 msleep(1300);
192 printf("turn\n");
193 motor(0,-100);
194 motor(1,-100);
195 motor(2,-100);
196 motor(3,-100);
197 msleep(1600);
198 printf("go backwards\n");
199
200}
201
202void section_4() {
203 /*
204 Task: drives up the ramp to drop botguy in the upper storage startbox
205
206 Start Position: back against outer wall facing the ramp
207 End Position: inside upper storage start box with botguy on the ground
208 */
209 up_ramp();
210}
211int main(){
212
213 printf("Starting Section 1\n");
214 section_1();
215
216 printf("Starting Section 2\n");
217 section_2();
218
219 printf("Starting Section 3\n");
220 section_3();
221
222 printf("Starting Section 4\n");
223}
224