-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVEXcode Project.v5pythonskills
More file actions
1 lines (1 loc) · 3.3 KB
/
VEXcode Project.v5pythonskills
File metadata and controls
1 lines (1 loc) · 3.3 KB
1
{"mode":"Text","textContent":"#region VEXcode Generated Robot Configuration\nimport math\nimport random\nfrom vexcode_vrc import *\nfrom vexcode_vrc.events import get_Task_func\n \n# constructors\n\ndrivetrain = Drivetrain()\nbrain = Brain()\nbottom_distance = Distance(\"BottomDistance\", 18)\nroller_optical = Optical(\"RollerOptical\", 2)\ngps = GPS(\"GPS\", 3)\nintake_motor_group = Motor(\"IntakeMotorGroup\", 10)\nbottom_line_tracker = LineTracker(\"BottomLineTracker\", 22)\nmiddle_line_tracker = LineTracker(\"MiddleLineTracker\", 23)\ntop_line_tracker = LineTracker(\"TopLineTracker\", 24)\n#endregion VEXcode Generated Robot Configuration\n\n# --------------------------------------------------\n# \n# \tProject: VEXcode Project\n#\tAuthor: VEX\n#\tCreated: \n#\tDescription: VEXcode V5 Python Project\n# Starting Position: \n# Preload: \n# \n# --------------------------------------------------\n\n# Library imports\nfrom vexcode_vrc import *\n\nglobal g\ng = -9.81\n\nglobal RAD_TO_DEG\nglobal DEG_TO_RAD\nRAD_TO_DEG = 180 / math.pi\nDEG_TO_RAD = math.pi / 180\n\nglobal r2o2\nr2o2 = math.sqrt(2) / 2\n\ndef get_heading_to_object(gameobject_1, gameobject_2):\n '''\n RETURNS IN DEGREES\n TODO: if someone doesn't pass a gameobject then this will break everything\n '''\n # Checks to see if both objects are of the GameObject class\n if gameobject_1.x_pos == gameobject_2.x_pos:\n return 180\n\n if gameobject_1.x_pos < gameobject_2.x_pos:\n ang = math.atan(((gameobject_2.y_pos - gameobject_1.y_pos)) /\n (gameobject_2.x_pos - gameobject_1.x_pos)) * RAD_TO_DEG\n else:\n ang = math.atan(((gameobject_2.y_pos - gameobject_1.y_pos)) /\n (gameobject_2.x_pos - gameobject_1.x_pos)) * RAD_TO_DEG + 180\n \n ang = 90 - ang\n if ang > 180:\n ang -= 360\n if ang < -180:\n ang += 360\n\n return ang\n\nclass GameObject:\n '''\n If we want to introduce game object (like say the goal or barriers), we have have to robot look up important information about the game object\n '''\n\n def __init__(self, x_pos, y_pos):\n self.x_pos = x_pos\n self.y_pos = y_pos\n\n# From 0,0 (which is the center of the field). Dimensions were got from page 89 on: https://content.vexrobotics.com/docs/2022-2023/vrc-spin-up/VRC-SpinUp-Game-Manual-2.2.pdf\nred_goal = GameObject((122.63 - 70.2) * 2.54, (122.63 - 70.2) * 2.54)\nblue_goal = GameObject(-(122.63 - 70.2) * 2.54, -(122.63 - 70.2) * 2.54)\n\ndef get_position_robot():\n return GameObject(gps.x_position(MM) / 10, gps.y_position(MM)/10)\n\nwhile True:\n\n drivetrain.turn_to_heading(270 + get_heading_to_object(get_position_robot(), red_goal), DEGREES)\n brain.screen.print(drivetrain.heading(DEGREES))\n brain.screen.print(get_heading_to_object(get_position_robot(), red_goal))\n brain.screen.next_row()\n wait(0.1, SECONDS)\n\n\n# Add project code in \"main\"\ndef main():\n drivetrain.drive_for(FORWARD, 200, MM)\n\n# VR threads — Do not delete\nvr_thread(main)\n","textLanguage":"python","rconfig":[],"slot":0,"platform":"V5","sdkVersion":"20220726.10.00.00","appVersion":"2.4.0","minVersion":"2.4.0","fileFormat":"1.2.0","icon":"","targetBrainGen":"First","target":"Virtual","virtualSkillsYear":"2023"}