My bad, I removed some comments at the start of the code: Here is the full thing:
#region VEXcode Generated Robot Configuration
import math
import random
from vexcode_vrc import *
from vexcode_vrc.events import get_Task_func
# Brain should be defined by default
brain=Brain()
drivetrain = Drivetrain("drivetrain", 0)
arm_motor = Motor("ArmMotor", 3)
rotation = Rotation("Rotation", 7)
intake_motor = Motor("IntakeMotor", 8)
optical = Optical("Optical", 11)
gps = GPS("GPS", 20)
#endregion VEXcode Generated Robot Configuration
# ------------------------------------------
#
# Project: VEXcode Inital Draft 1
# Author: Lucian and Epsilon
# Created:
# Description: VEXcode Python Project
#
# ------------------------------------------
# Add project code in "main"
def main():
def priority_key_length(nums):
return math.isqrt((nums[0]-gps.x_position(MM))**2+(nums[1]-gps.y_position(MM)**2))
def priority_key_angle(nums):
return int(math.degrees(math.atan(nums[1]/nums[0])))
def pick_up_triball():
intake_motor.spin_for(FORWARD, 360, DEGREES)
def release_triball():
intake_motor.spin_for(REVERSE, 360, DEGREES)
def rotate_to_target_triball():
#rotate until the following returns True
#assume unidirectional and points in the same direction as intake, but might need changing later
while optical.is_near_object == False:
drivetrain.turn(RIGHT)
#can change between left and right, shouldn't matter but we can verify in testing which gives more points
drivetrain.set_rotation(0, DEGREES)
triball_locations=[[-1600,1600], [1600,1600],[0,1500],[-125,1075],[-125,600],[-300,300],[-600,0],[-100,0],[-100,-600],[-100,-1100],[-1600,-1600],[1600,-1600]]
i=0
pickup_toggle_times=i
# goal_front==(1200,600) - (1200, -600)
## goal front is anywhere between
while True:
length_order=triball_locations.sort(reverse=True, key=priority_key_length)
priority_length=list(map(priority_key_length,length_order))
priority_angle=list(map(priority_key_angle, priority_length))
if i>=28: # pick up 14 and drop 14
break
#incomplete - adjust based off current angle and position
#somehow broken code that i may not need now but might need int he future:
#length_to_origin=math.isqrt((gps.x_position(MM)**2+gps.y_position(MM)**2)
#angle_to_origin=int(math.atan(gps.y_position(MM)/gps.x_position(MM)))
#incomplete - adjust based off current angle and position
elif pick_toggle_times % 2 == 0: #dont have a ball yet
curr_ball_len=priority_length.pop()
curr_ball_ang=priority_angle.pop()
drivetrain.turn_to_rotation(curr_ball_ang, DEGREES)
drivetrain.drive_for(FORWARD, curr_ball_len, MM)
#second check to make sure that triball is close by
if optical.is_near_object()==True:
pick_up_triball()
#update counter
i=i+1
else:
#just in case something went wrong, we'll go back to the start of the function
continue
elif pick_toggle_times % 2 == 1: # already have a ball
#rotate up/down
while gps.y_position(MM)!=0:
if gps.y_position(MM) >0:
drivetrain.turn_to_rotation(-90, DEGREES)
elif gps.y_position(MM) >0:
drivetrain.turn_to_rotation(90, DEGREES)
#go up/down until you hit y=0
drivetrain.drive(FORWARD)
drivetrain.turn_to_rotation(0, DEGREES)
while gps.x_position(MM)!=1200:
drivetrain.drive(FORWARD)
# rotate dropper until its in front of goal
# deposit
release_triball()
# update counter
i=i+1
total==i//2
vr_thread(main)
edit: code tags added by mods, please remember to use them.