-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels
799 lines (687 loc) · 26.8 KB
/
models
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
#!/usr/bin/env python3
'''Hello to the world from ev3dev.org'''
# importing the ev3 libres
from ev3dev2.motor import MediumMotor, LargeMotor,OUTPUT_A, OUTPUT_B,OUTPUT_D ,OUTPUT_C, SpeedPercent, MoveTank, MoveSteering
from ev3dev2.sound import Sound
import ev3dev2.motor as motor
from ev3dev2.sensor.lego import GyroSensor, UltrasonicSensor, TouchSensor
from pixycamev3.pixy2 import Pixy2
from ev3dev2.sensor import INPUT_1,INPUT_4,INPUT_2,INPUT_3
# importing extra libres
from time import sleep
import time
import logging
import random
sound = Sound()
pixy2 = Pixy2(port=1, i2c_address=0x54) # define the pixy2 camera.
# Definition importint intgers.
wait_duration = 120
ball_loc = int()
catcher_Motor = MediumMotor(OUTPUT_D)
signtaure = 1# this intger use in the pixy code.
ball_loc = int()
class GPSRobot:
""" This class is responsible for determining the location of the robot."""
def __init__(self,d = 0,x = 30,y=0):
self.d = d
self.x = x
self.y =y
class Robot:
"""This class is responsible for the movement of the robot."""
#Defining the robot variabled
def __init__(self):
self.r_Motor = MediumMotor(OUTPUT_C)
self.l_Motor = MediumMotor(OUTPUT_B)
self.r_Motor.POLARITY_INVERSED
self.drive_Base = MoveTank(OUTPUT_B, OUTPUT_C, motor_class=MediumMotor)
self.steerbase = MoveSteering(OUTPUT_B, OUTPUT_C, motor_class=MediumMotor)
self.r_Motor.POLARITY_INVERSED
self.gyro = GyroSensor(INPUT_4)
self.pixy2 = Pixy2(port=1, i2c_address=0x54) # define the pixy2 camera.
self.drive_Base.gyro = self.gyro
self.catcher_Motor = MediumMotor(OUTPUT_D)
self.hiter_Motor = LargeMotor(OUTPUT_A)
self.r_Motor.polarity = MediumMotor.POLARITY_INVERSED
#A function that throws the ball when the robot discover it
def throw_ball(self):
""" this function make the robot throw the ball"""
self.hiter_Motor.on_for_degrees(100, 20, True,True)
self.catcher_Motor.on_for_degrees(100,-145,True,False)
sleep(0.01)
self.hiter_Motor.on_for_degrees(-100, 100,True,True)
#A function that throws the ball when the robot discover it
def catch_ball(self):
""" this funtion make the robot catch the ball"""
self.catcher_Motor.on_for_degrees(100,145,True, True)
def open_cather(self):
""" this funtion make the robot catch the ball"""
self.catcher_Motor.on_for_degrees(-100,145,True, True)
#A function that drive untill the robot hits a wall
def drive_to_wall(self, speed: int):
"""This function makes the robot crawl up the wall"""
start_time = time.time()
while not self.drive_Base.is_stalled:
self.drive_Base.on(speed, speed)
if time.time() - start_time >= 4:
break
self.drive_Base.stop(brake=True)
def turn_hiter_back(self):
"""This function makes the batter prepare to hit the ball."""
while self.hiter_Motor.is_stalled == False:
self.hiter_Motor.on(100, True, True)
else:
self.hiter_Motor.stop()
#A method that moves only one motor to make a long turn using the gyro sensor
def Long_Turn(self, speed : int, angle : int):
"""Makes A Long Turn By Rotating One Wheel A Time"""
if angle > 0:
if speed > 0:
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < angle:
self.drive_Base.on(10, 0)
else:
self.drive_Base.stop(brake = True)
if speed < 0:
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < angle:
self.drive_Base.on(-10, 0)
else:
self.drive_Base.stop(brake = True)
if angle < 0:
if speed > 0:
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) > angle:
self.drive_Base.on(0,10)
else:
self.drive_Base.stop(brake = True)
if speed < 0:
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < angle:
self.drive_Base.on(-10, 0)
else:
self.drive_Base.stop(brake = True)
#A method that spins the robot 90 degrees to the right using the gyro sensor
def spin_right_90_degrees(self):
"""Spins 90 Degrees The Left Using The Gyro Sensor"""
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < 85:
self.drive_Base.on(10, -10)
else:
self.drive_Base.stop()
#A funtion that curve to the left when the robot start to search on the left side
def left_curve_to_wall_start(self,speed : int, curve_rate : int):
""" This function will
make the robot move left until it
crashes into the wall. """
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) > -10:
self.drive_Base.on(speed-(curve_rate*0.5), speed+curve_rate)
else:
self.drive_Base.stop(brake=True)
#A funtion that curve to the right when the robot start to search on the left side
def right_curve_to_wall_start(self,speed : int, curve_rate : int):
"""This function will
make the robot move right until it
crashes into the wall. """
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < 30:
self.drive_Base.on(speed+curve_rate,speed-(curve_rate*0.5))
else:
self.drive_Base.stop(brake=True)
#A function that moves the robot straight forward or backward
def move_straight(self,speed : int ,degrees : int,frvr : bool):
"""This function makes the robot move forward either forever or for a certain number of degrees. """
if frvr ==True:
self.drive_Base.on(speed, speed)
else:
self.drive_Base.on_for_degrees(speed,speed,degrees,True,True)
#A function that moves the robot 90 degrees to the right when the robot is crawling on the wall
def turn_90_degrees_right_to_wall(self):
"""This function makes the robot turn to the right by 90 degrees for the wall."""
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < 85:
self.drive_Base.on(20,5)
else:
self.drive_Base.stop(brake=True)
#A function that turnes the robot to a specific angle using the gyro
def turn_to_angle(self,target_angle : int, speed : int):
""" This function makes the robot turn to the right by a certain amount of degrees."""
current_angle = self.gyro.angle
if target_angle > 0:
while (self.gyro.angle - current_angle) < target_angle:
self.drive_Base.on(speed,-speed)
else:
self.drive_Base.stop(brake=True)
elif target_angle < 0:
while (self.gyro.angle - current_angle) > target_angle:
self.drive_Base.on(-speed,speed)
else:
self.drive_Base.stop(brake=True)
#A method that drives the robot straight using a pd follower with gyro sensor for a limited time
def Gyro_Straight_Move_Degs(self, speed : int, degrees : int):
"""Drives The Robot Very Straight Using A PD Follower With Gyro Sensor
(The Speed And Degrees Should Be Positive only)
"""
kp = 1.2
ki = 0
kd = 0.5
target_angle = 0
integral = 0
last_error = 0
max_speed = speed
self.l_Motor.reset()
self.gyro.reset()
while self.l_Motor.degrees < degrees:
error = target_angle - self.gyro.angle
proportional = kp * error
integral += error
integral_term = ki * integral
derivative = error - last_error
derivative_term = kd * derivative
turn_rate = proportional + integral_term + derivative_term
turn_rate = max(-max_speed, min(max_speed, turn_rate))
left_motor_speed = SpeedPercent(max_speed + turn_rate)
right_motor_speed = SpeedPercent(max_speed - turn_rate)
self.l_Motor.on(left_motor_speed)
self.r_Motor.on(right_motor_speed)
last_error = error
sleep(0.01)
else:
self.drive_Base.stop(brake=False)
#Same as "Gyro_Straight_Move_Degs" method but moves untill the robot is stalled
def Gyro_Straight_Move_Until_Stalled(self, speed : int):
"""Drives The Robot Very Straight Using A PD Follower With Gyro Sensor
(The Speed Should Be Positive only)
"""
kp = 1.2
ki = 0
kd = 0.5
target_angle = 0
integral = 0
last_error = 0
max_speed = speed
self.gyro.reset()
while self.drive_Base.is_stalled == False:
error = target_angle - self.gyro.angle
proportional = kp * error
integral += error
integral_term = ki * integral
derivative = error - last_error
derivative_term = kd * derivative
turn_rate = proportional + integral_term + derivative_term
turn_rate = max(-max_speed, min(max_speed, turn_rate))
left_motor_speed = SpeedPercent(max_speed + turn_rate)
right_motor_speed = SpeedPercent(max_speed - turn_rate)
self.l_Motor.on(left_motor_speed)
self.r_Motor.on(right_motor_speed)
last_error = error
sleep(0.01)
else:
self.drive_Base.stop(brake=False)
def spin_right(self):
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) < 85:
self.drive_Base.on(10, 0)
else:
self.drive_Base.stop()
def spin_left(self):
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) > -85:
self.drive_Base.on(-10,0)
else:
self.drive_Base.stop()
#turn 90 degrees when the robot is crawling on the wall by left side
def turn_90_degrees_left_to_wall(self):
"""This function makes the robot turn to the left by 90 degrees for the wall"""
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) > -85:
self.drive_Base.on(5,20)
else:
self.drive_Base.stop(brake=True)
def start_hiter(self):
""" This function puts the hiter in the starting position."""
while self.hiter_Motor.is_stalled == False:
self.hiter_Motor.on(100,True,True)
else:
self.hiter_Motor.stop()
#A method that moves the robot 90 degrees to the left using the gyro sensor
def spin_left_90_degrees(self):
"""This function makes the robot spin 90 degrees to the right"""
gyro_angle = self.gyro.angle
while (self.gyro.angle - gyro_angle) > -85:
self.drive_Base.on(-10,10)
else:
self.drive_Base.stop(brake=True)
def home(self):
"""this function will make the robot back to the start point"""
self.spin_left()
self.drive_to_wall(-30)
self.drive_Base.on_for_degrees(10,10,240,True,True)
self.spin_left_90_degrees()
self.drive_to_wall(-20)
def home_for_right(self):
"""this function will make the robot back from the right area to the start point"""
self.drive_Base.on_for_degrees(-30,-30,165,True,True)
self.turn_90_degrees_right_to_wall()
self.drive_to_wall(-30)
self.drive_Base.on_for_degrees(20,20,350,True,True)
self.spin_right_90_degrees()
self.drive_to_wall(-20)
def home_r(self):
"""this function will make the robot back to the green squre
after catch the ball from left or middle"""
self.drive_Base.on_for_degrees(-30,-30,165,True,True)
self.spin_left_90_degrees()
self.drive_to_wall(-30)
self.drive_Base.on_for_degrees(20,20,200,True,True)
self.spin_left_90_degrees()
self.drive_to_wall(-20)
def home_for_right_r(self):
"""this function will make the robot back to the green squre
after catch the ball from right"""
self.drive_Base.on_for_degrees(-30,-30,165,True,True)
self.turn_90_degrees_left_to_wall()
self.drive_to_wall(-30)
self.drive_Base.on_for_degrees(20,20,350,True,True)
self.spin_left_90_degrees()
self.drive_to_wall(-20)
#A method that drives the robot straight using a pd follower with gyro sensor for a limited time
def Gyro_Straight_Move_Degs(self, speed : int, degrees : int):
"""Drives The Robot Very Straight Using A PD Follower With Gyro Sensor
(The Speed And Degrees Should Be Positive only)
"""
self.r_Motor.reset()
gyro_angle = self.gyro.angle
while (self.r_Motor.degrees * -1) < degrees:
self.steerbase.on((0 - (self.gyro.angle - gyro_angle)) * 0.9, -speed)
else:
self.steerbase.stop(brake=True)
my_robot = Robot()
def search():
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 1)
if n_blocks == 1:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
my_robot.start_hiter()
my_robot.Gyro_Straight_Move_Until_Stalled(40)
my_robot.home()
break
# Definition pixy2 function
def ball_location2(block):
"""Determines the ball's location based on the x_center coordinate of each block."""
ball_locations = []
for bloc in block:
x_center = bloc.x_center
if 0<= x_center <= 118:
ball_locations.append(7)
elif 120 <= x_center <= 175:
ball_locations.append(9)
elif 180<= x_center <= 400:
ball_locations.append(8)
else:
ball_locations.append(-1)
return ball_locations
import scan
def side_chooser2(ball_locations):
"""Determines which direction the robot should go based on ball locations."""
for location in ball_locations:
if location == 8:
scan.r_l()
elif location == 9:
scan.r_m()
elif location == 7:
scan.r_r()
elif location == -1:
my_robot.start_hiter()
my_robot.Gyro_Straight_Move_Until_Stalled(40)
my_robot.home()
def r_m():
"""this function make the robot catch the ball from the middle home area"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.drive_to_wall(30)
my_robot.catch_ball()
my_robot.home_r()
my_robot.move_straight(30,200,False)
sleep(0.3)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.move_straight(30,-200,False)
def r_r():
"""this function make the robot catch the ball from the right home area"""
my_robot.start_hiter()
my_robot.Long_Turn(10,-25)
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.move_straight(30, 600,False)
my_robot.Long_Turn(10,10)
my_robot.Gyro_Straight_Move_Until_Stalled(30)
my_robot.catch_ball()
my_robot.home()
my_robot.move_straight(30,200,False)
sleep(0.3)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.move_straight(30,-200,False)
my_robot.start_hiter()
def r_l():
"""this function make the robot catch the ball from the left home area"""
my_robot.start_hiter()
my_robot.right_curve_to_wall_start(20,30)
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.drive_to_wall(30)
my_robot.catch_ball()
my_robot.home_r()
my_robot.move_straight(30,200,False)
sleep(0.3)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.move_straight(30,-200,False)
my_robot.start_hiter()
def search_in_left_side_game():
"""this function will search in the left side for a ball"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.left_curve_to_wall_start(30, 40)
my_robot.drive_to_wall(50)
my_robot.catch_ball()
my_robot.steerbase.on_for_degrees(0,20,-340,True,True)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.turn_90_degrees_right_to_wall()
my_robot.drive_to_wall(-10)
my_robot.move_straight(20,230,False)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-20)
my_robot.Gyro_Straight_Move_Until_Stalled(40)
my_robot.home()
# while True:
# n_blocks, block = pixy2.get_blocks(signtaure, 1)
# if n_blocks == 1:
# sleep(2)
# ball_lo = ball_location2(block)
# print(ball_lo)
# side_chooser2(ball_lo)
# break
# sleep(0.1) # Adjust sleep time as needed
# if(n_blocks ==0):
# my_robot.Gyro_Straight_Move_Until_Stalled(-40)
# my_robot.home()
# break
def search_in_the_middle_game():
"""this function will make a liner search in the middle side"""
my_robot.start_hiter()
my_robot.Long_Turn(10, 50)
my_robot.Long_Turn(10, -40)
my_robot.Gyro_Straight_Move_Until_Stalled(60)
my_robot.catch_ball()
my_robot.move_straight(-30, 340,frvr=False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
sleep(0.5)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-30)
my_robot.drive_Base.on_for_degrees(20, 20, 230, True, True)
my_robot.spin_right_90_degrees()
sleep(0.5)
my_robot.drive_to_wall(-20)
my_robot.Gyro_Straight_Move_Until_Stalled(40)
my_robot.home()
# while True:
# n_blocks, block = pixy2.get_blocks(signtaure, 1)
# if n_blocks == 1:
# sleep(2)
# ball_lo = ball_location2(block)
# print(ball_lo)
# side_chooser2(ball_lo)
# break
# sleep(0.1) # Adjust sleep time as needed
# if(n_blocks ==0):
# sleep(2)
# my_robot.Gyro_Straight_Move_Until_Stalled(-40)
# my_robot.home()
# break
#A function that scan the right side of the robot half to check if there is any ball there
def search_in_right_side_game():
"""this function will make a liner search in the right side"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.right_curve_to_wall_start(20, 8)
my_robot.drive_to_wall(50)
my_robot.catch_ball()
my_robot.drive_Base.on_for_degrees(20,20,-340,True,True)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.turn_90_degrees_left_to_wall()
my_robot.drive_to_wall(-10)
my_robot.drive_Base.on_for_degrees(20,20,360,True,True)
my_robot.spin_left_90_degrees()
my_robot.drive_to_wall(-10)
my_robot.Gyro_Straight_Move_Until_Stalled(40)
my_robot.home()
# while True:
# n_blocks, block = pixy2.get_blocks(signtaure, 1)
# if n_blocks == 1:
# sleep(2)
# ball_lo = ball_location2(block)
# print(ball_lo)
# side_chooser2(ball_lo)
# break
# sleep(0.1) # Adjust sleep time as needed
# if(n_blocks ==0):
# sleep(2)
# my_robot.Gyro_Straight_Move_Until_Stalled(-40)
# my_robot.home()
# break
def search_in_middle_of_middle_side_game():
"""this function will make a liner search in the middle of middle side"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.Long_Turn(50)
my_robot.Long_Turn(-50)
my_robot.steerbase.on_for_degrees(0,20,600,True,True)
my_robot.catch_ball()
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.turn_90_degrees_right_to_wall()
my_robot.drive_to_wall(-30)
my_robot.move_straight(20,220,False)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-30)
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 4)
if n_blocks >0:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
sleep(2)
my_robot.Gyro_Straight_Move_Until_Stalled(-40)
my_robot.home()
break
def search_in_middle_of_right_side_game():
"""this function will make a liner search in the middle of right side"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.right_curve_to_wall_start(20,10)
my_robot.steerbase.on_for_degrees(0,20,600,True, True)
my_robot.catch_ball()
my_robot.drive_Base.on_for_degrees(-10, -10, 100, True, True)
my_robot.throw_ball()
my_robot.turn_90_degrees_left_to_wall()
my_robot.drive_to_wall(-20)
my_robot.drive_Base.on_for_degrees(20,20,350,True,True)
my_robot.spin_left_90_degrees()
my_robot.drive_to_wall(-20)
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 1)
if n_blocks == 1:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
sleep(2)
my_robot.Gyro_Straight_Move_Until_Stalled(-40)
my_robot.home()
break
def search_in_middle_of_left_side_game():
"""this function will make a liner search in the middle of lift side"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.turn_to_angle(-15,30)
my_robot.steerbase.on_for_degrees(0,20,600,True,True)
my_robot.catch_ball()
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.turn_90_degrees_right_to_wall()
my_robot.drive_to_wall(-10)
my_robot.move_straight(20,230,False)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-20)
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 1)
if n_blocks == 1:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
sleep(2)
my_robot.Gyro_Straight_Move_Until_Stalled(-40)
my_robot.home()
break
def middle_thin_left():
"""this function will make the robot throw the ball in middle thin left"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.steerbase.on_for_degrees(0,20,700,True,True)
my_robot.catch_ball()
my_robot.move_straight(20,-50,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(100,-140,True,True)
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.left_curve_to_wall_start(30,40)
my_robot.drive_to_wall(30)
my_robot.catch_ball()
my_robot.move_straight(30,-300,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.turn_90_degrees_right_to_wall()
my_robot.drive_to_wall(-10)
my_robot.move_straight(20,230,False)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-20)
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 1)
if n_blocks == 1:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
sleep(2)
my_robot.Gyro_Straight_Move_Until_Stalled(-40)
my_robot.home()
break
def middle_thin_right():
"""this function will make the robot throw the ball in middle thin left"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.steerbase.on_for_degrees(0,20,700,True,True)
my_robot.catch_ball()
my_robot.move_straight(30,-100,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
sleep(0.5)
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.right_curve_to_wall_start(30,40)
my_robot.drive_to_wall(30)
my_robot.catch_ball()
my_robot.move_straight(30,-300,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.turn_90_degrees_left_to_wall()
my_robot.drive_to_wall(-30)
my_robot.drive_Base.on_for_degrees(20,20,350,True,True)
my_robot.spin_left_90_degrees()
my_robot.drive_to_wall(-30)
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 1)
if n_blocks == 1:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
sleep(2)
my_robot.Gyro_Straight_Move_Until_Stalled(-40)
my_robot.home()
break
def left_thin_middle():
"""this function will make the robot throw the ball in left thin middle"""
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,150,True,True)
my_robot.left_curve_to_wall_start(30,40)
my_robot.steerbase.on_for_degrees(0,20,700,True,True)
my_robot.catch_ball()
my_robot.move_straight(30,-100,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.Long_Turn(20,50)
my_robot.start_hiter()
my_robot.hiter_Motor.on_for_degrees(100,200,True,True)
my_robot.move_straight(20,200,False)
my_robot.Long_Turn(-50)
my_robot.Gyro_Straight_Move_Until_Stalled(-30)
my_robot.catch_ball()
my_robot.move_straight(30,-300,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(-100,140,True,True)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-10)
my_robot.move_straight(20,230,False)
my_robot.spin_right_90_degrees()
my_robot.drive_to_wall(-20)
while True:
n_blocks, block = pixy2.get_blocks(signtaure, 1)
if n_blocks == 1:
sleep(2)
ball_lo = ball_location2(block)
print(ball_lo)
side_chooser2(ball_lo)
break
sleep(0.1) # Adjust sleep time as needed
if(n_blocks ==0):
sleep(2)
my_robot.Gyro_Straight_Move_Until_Stalled(-40)
my_robot.home()
break
def mission():
my_robot.gyro.reset()
my_robot.move_straight(20,800,False)
my_robot.catch_ball()
my_robot.move_straight(-10,150,False)
my_robot.throw_ball()
my_robot.hiter_Motor.on_for_degrees(100,-140,True,True)
my_robot.turn_to_angle(195, 10)
my_robot.move_straight(30,800,False)
my_robot.home()