Urgent help needed
My team procrastinated very badly and we need a code written in the next week, we have one we tried to make but the bot won’t run it, if anyone can look over our code or even make a block code for us it would be so so so appreciated
Please comment or contact me for details on code
We can’t write code for you, but if you send your code (as well as a description of what it’s supposed to do) I can help you.
Ofc ill send the python code in a minute
1 #region VEXcode Generated Robot Configuration
2 from vex import *
3 import urandom
4
5 # Brain should be defined by default
6 brain = Brain()
7
8 # Robot configuration code
9 brain
inertial = Inertial()
_
10
11
12 14
13 wait(100, MSEC)
15 # generating and setting random seed
16 def initializeRandomSeed():
17 wait(100, MSEC)
18 xaxis = brain
inertial.acceleration(XAXIS) * 1000
_
19 yaxis = brain
inertial.acceleration(YAXIS) * 1000
_
20 zaxis = brain
inertial.acceleration(ZAXIS) * 1000
_
21 22 23
systemTime = brain.timer.system() * 100
urandom.seed(int(xaxis + yaxis + zaxis + systemTime))
24 # Initialize random seed
25 initializeRandomSeed()
26
27 #endregion VEXcode Generated Robot Configuration
28 # ------------------------------------------
29 #
30 # Project: VEXcode Project
31 # Author: VEX
32 # Created:
33 # Description: VEXcode EXP Python Project
34 #
35 # ------------------------------------------
36
37 # Library imports
38 from vex import *
39
40 # Begin project code
41 from vex import *
42
43 # Initialize motors
44 drive
motor
_
_
45 drive
motor
left = Motor(6)
right = Motor(8)
46 arm
47 claw
_
_
motor = Motor(7)
_
motor = Motor(10)
_
48
49 # Initialize sensors
50 optical
_
51 distance
sensor = Optical(3)
sensor = Distance(4)
_
52
53 # Function to drive forward
vex code - Page 2 of 4
54 def drive
forward(distance):
_
55 drive
motor
left.spin(FORWARD)
_
_
56 drive
motor
right.spin(FORWARD)
_
_
57 wait(distance, SECONDS)
58 drive
motor
_
_
59 drive
motor
left.stop()
right.stop()
_
_
60
61 # Function to clamp the claw
62 def clamp_
claw():
63 claw
motor.spin(FORWARD)
_
64 wait(1, SECONDS)
65 claw
motor.stop()
_
66
67 # Function to release the claw
68 def release
claw():
_
69 claw
motor.spin(REVERSE)
_
70 wait(1, SECONDS)
71 claw
motor.stop()
_
72
73 # Function to turn 180 degrees
74 def turn
180():
_
75 drive
76 drive
77 motor
left.spin(REVERSE)
_
_
motor
right.spin(FORWARD)
_
_
wait(1.5, SECONDS) # Adjust time for 180-degree turn
78 drive
motor
_
_
79 drive
motor
left.stop()
right.stop()
_
_
80
81 # Function to turn 90 degrees left
82 def turn
90
left():
_
_
83 drive
84 drive
85 motor
left.spin(REVERSE)
_
_
motor
right.spin(FORWARD)
_
_
wait(0.75, SECONDS) # Adjust time for 90-degree turn
86 drive
motor
_
_
87 drive
motor
left.stop()
right.stop()
_
_
88
89 # Main program
90 drive
forward(3) # Drive forward 3 feet
_
91 clamp_
claw() # Clamp onto yellow rings
92 turn
180() # Turn 180 degrees
_
93
94 # Look for stick
95 while True:
96 if distance
sensor.is
object
detected()< 3 * 12: # Less than 3 feet
_
_
_
97 break
98
99 drive
100 release
101 turn
forward(1) # Move above the stick
_
claw() # Release rings to stack onto the stick
_
90
left() # Turn 90 degrees to the left
_
_
102
103 # Drive until color detected
104 while True:
105 color = optical
sensor.color()
_
106 if color in [Color.BLUE, Color.YELLOW, Color.RED]:
vex code - Page 3 of 4
107 drive
motor
left.stop()
_
_
108 drive
motor
right.stop()
_
_
109 wait(3, SECONDS) # Stop for 3 seconds
110 brain.play_
sound(SoundType.SIREN) # Make a noise
111 break
112 drive
113 drive
motor
left.spin(FORWARD)
_
_
motor
right.spin(FORWARD)
It’s meant to so straight until it detects a ring, then clamp onto it via claw (the ring is just a plain ring, no middle piece) then rotate 180 degrees to face the opposite direction, go straight to find the stick/stand, drop the ring on to the stand, and repeat 4 times, all 4 rings are the same and are lined up in a straight line in front of the bot when starting, then when the final ring is placed it needs to turn 90 degrees to face the left, go forward and detect a color placed on the ground (red blue or green) then stop for 3 seconds and make a noise
Ok, I’m competing today so I’ll be busy but I can take a look sometime over the weekend for sure.
1 Like
Not sure if this is the only issue, but on line 96, you are comparing the result of is_object_detected()
(a boolean) with a numerical value. Perhaps you meant to use distanceSensor.object_distance(INCHES)
instead?
If you could describe what your robot does when you currently run the code, that would be helpful.