0% found this document useful (0 votes)
10 views5 pages

Basic

Uploaded by

shane.vahlsing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Basic

Uploaded by

shane.vahlsing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Student Name:

Assignment:

Notes:

Project Name: Basic

Project Type: Python

Date: Fri Jan 23 2026

Page 1 of 5
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 controller_1 = Controller(PRIMARY)
10 left_motor_a = Motor(Ports.PORT11, GearSetting.RATIO_18_1, False)
11 left_motor_b = Motor(Ports.PORT12, GearSetting.RATIO_18_1, False)
12 left_drive_smart = MotorGroup(left_motor_a, left_motor_b)
13 right_motor_a = Motor(Ports.PORT13, GearSetting.RATIO_18_1, True)
14 right_motor_b = Motor(Ports.PORT4, GearSetting.RATIO_18_1, True)
15 right_drive_smart = MotorGroup(right_motor_a, right_motor_b)
16 drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 299.24, 294.89399999999
995, 40, MM, 1)
17 TopBack = Motor(Ports.PORT16, GearSetting.RATIO_18_1, False)
18 MidBack = Motor(Ports.PORT17, GearSetting.RATIO_18_1, False)
19 BottomBack = Motor(Ports.PORT18, GearSetting.RATIO_18_1, True)
20 BottomFront = Motor(Ports.PORT19, GearSetting.RATIO_18_1, False)
21 TopFront = Motor(Ports.PORT20, GearSetting.RATIO_18_1, False)
22 Tower_Extractor = Motor(Ports.PORT15, GearSetting.RATIO_18_1, False)
23 gps_5 = Gps(Ports.PORT5, 0.00, 0.00, MM, 180)
24
25
26 # wait for rotation sensor to fully initialize
27 wait(30, MSEC)
28
29
30 def play_vexcode_sound(sound_name):
31 # Helper to make playing sounds from the V5 in VEXcode easier and
32 # keeps the code cleaner by making it clear what is happening.
33 print("VEXPlaySound:" + sound_name)
34 wait(5, MSEC)
35
36 # add a small delay to make sure we don't print in the middle of the REPL header
37 wait(200, MSEC)
38 # clear the console to make sure we don't have the REPL in the console
39 print("\033[2J")
40
41
42
43 # define variables used for controlling motors based on controller inputs
44 controller_1_x_b_buttons_control_motors_stopped = True
45 drivetrain_l_needs_to_be_stopped_controller_1 = False
46 drivetrain_r_needs_to_be_stopped_controller_1 = False
47
48 # define a task that will handle monitoring inputs from controller_1
49 def rc_auto_loop_function_controller_1():
50 global drivetrain_l_needs_to_be_stopped_controller_1, drivetrain_r_needs_to_be_stopp
ed_controller_1, controller_1_x_b_buttons_control_motors_stopped, remote_control_code_e
nabled
51 # process the controller input every 20 milliseconds
52 # update the motors based on the input values

Page 2 of 5
53 while True:
54 if remote_control_code_enabled:
55
56 # calculate the drivetrain motor velocities from the controller joystick axies
57 # left = axis3
58 # right = axis2
59 drivetrain_left_side_speed = controller_1.[Link]()
60 drivetrain_right_side_speed = controller_1.[Link]()
61
62 # check if the value is inside of the deadband range
63 if drivetrain_left_side_speed < 5 and drivetrain_left_side_speed > -5:
64 # check if the left motor has already been stopped
65 if drivetrain_l_needs_to_be_stopped_controller_1:
66 # stop the left drive motor
67 left_drive_smart.stop()
68 # tell the code that the left motor has been stopped
69 drivetrain_l_needs_to_be_stopped_controller_1 = False
70 else:
71 # reset the toggle so that the deadband code knows to stop the left motor next
72 # time the input is in the deadband range
73 drivetrain_l_needs_to_be_stopped_controller_1 = True
74 # check if the value is inside of the deadband range
75 if drivetrain_right_side_speed < 5 and drivetrain_right_side_speed > -5:
76 # check if the right motor has already been stopped
77 if drivetrain_r_needs_to_be_stopped_controller_1:
78 # stop the right drive motor
79 right_drive_smart.stop()
80 # tell the code that the right motor has been stopped
81 drivetrain_r_needs_to_be_stopped_controller_1 = False
82 else:
83 # reset the toggle so that the deadband code knows to stop the right motor next
84 # time the input is in the deadband range
85 drivetrain_r_needs_to_be_stopped_controller_1 = True
86
87 # only tell the left drive motor to spin if the values are not in the deadband range
88 if drivetrain_l_needs_to_be_stopped_controller_1:
89 left_drive_smart.set_velocity(drivetrain_left_side_speed, PERCENT)
90 left_drive_smart.spin(FORWARD)
91 # only tell the right drive motor to spin if the values are not in the deadband rang
e
92 if drivetrain_r_needs_to_be_stopped_controller_1:
93 right_drive_smart.set_velocity(drivetrain_right_side_speed, PERCENT)
94 right_drive_smart.spin(FORWARD)
95 # check the buttonX/buttonB status
96 # to control Tower_Extractor
97 if controller_1.[Link]():
98 Tower_Extractor.spin(REVERSE)
99 controller_1_x_b_buttons_control_motors_stopped = False
100 elif controller_1.[Link]():
101 Tower_Extractor.spin(FORWARD)
102 controller_1_x_b_buttons_control_motors_stopped = False
103 elif not controller_1_x_b_buttons_control_motors_stopped:
104 Tower_Extractor.stop()
105 # set the toggle so that we don't constantly tell the motor to stop when
106 # the buttons are released
107 controller_1_x_b_buttons_control_motors_stopped = True
108 # wait before repeating the process
109 wait(20, MSEC)
110
111 # define variable for remote controller enable/disable
112 remote_control_code_enabled = True
113
114 rc_auto_loop_thread_controller_1 = Thread(rc_auto_loop_function_controller_1)
115
116 #endregion VEXcode Generated Robot Configuration
117
118 GROUND = 1
119 STORAGE = 2
120 CENTERHIGH = 3
121 SIDEGOAL = 4
122 STOP = 5
123
124 def onStart():
125 Tower_Extractor.set_stopping(HOLD)
126
127 Tower_Extractor.set_velocity(100, PERCENT)
128 TopBack.set_velocity(100, PERCENT)
129 MidBack.set_velocity(50, PERCENT)
130 BottomBack.set_velocity(75, PERCENT)
131 BottomFront.set_velocity(100, PERCENT)
132 TopFront.set_velocity(100, PERCENT)
133
134 drivetrain.set_stopping(BRAKE)
135 drivetrain.set_drive_velocity(100, PERCENT)
136
137 # NOTE: spin FORWARD = spin CLOCKWISE
138 # Spins lift to drop balls to specified location
139 def spinLift(mode, duration=0):
140 if duration > 0:
141 TopBack.set_timeout(duration, SECONDS)
142 MidBack.set_timeout(duration, SECONDS)
143 BottomBack.set_timeout(duration, SECONDS)
144 TopFront.set_timeout(duration, SECONDS)
145 BottomFront.set_timeout(duration, SECONDS)
146
147 if mode == 1 :
148 [Link](FORWARD)
149 [Link](REVERSE)
150 [Link](FORWARD)
151 elif mode == 2:
152 [Link](REVERSE)
153 [Link](FORWARD)
154 [Link](FORWARD)
155 [Link](REVERSE)
156 [Link](REVERSE)
157 elif mode == 3:
158 [Link](FORWARD)
159 [Link](REVERSE)
160 [Link](FORWARD)
161 [Link](REVERSE)
162 elif mode == 4:
163 [Link](FORWARD)
164 [Link](FORWARD)
165 [Link](REVERSE)
166 [Link](REVERSE)
167 [Link](REVERSE)
168 elif mode == 5:
169 [Link]()
170 [Link]()
171 [Link]()
172 [Link]()
173 [Link]()
174
175 def autonomous():
176 drivetrain.drive_for(FORWARD, 38, INCHES) # Go to the front of the tower
177 drivetrain.set_timeout(1, SECONDS)
178 drivetrain.turn_for(RIGHT, 90, DEGREES) # Face tower
179 Tower_Extractor.spin_for(FORWARD, 100, DEGREES)
180
181 def alignWithGoal(goal)
182 def checkInput():
183 if controller_1.[Link](): spinLift(GROUND)
184 elif controller_1.[Link](): spinLift(STORAGE)
185 elif controller_1.[Link](): spinLift(CENTERHIGH)
186 elif controller_1.[Link](): spinLift(SIDEGOAL)
187 elif controller_1.[Link](): autonomous()
188 else: spinLift(STOP)
189
190 def driver():
191 while True:
192 checkInput()
193
194 competition = Competition(driver, autonomous)
195
196 onStart()
197 driver()
198
199
200
201

You might also like