-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVEXcode.v5python
More file actions
1 lines (1 loc) · 9.48 KB
/
Copy pathVEXcode.v5python
File metadata and controls
1 lines (1 loc) · 9.48 KB
1
{"mode":"Text","hardwareTarget":"brain","textContent":"#region VEXcode Generated Robot Configuration\nfrom vex import *\nimport urandom\nimport math\n\n# Brain should be defined by default\nbrain=Brain()\n\n# Robot configuration code\ncontroller_1 = Controller(PRIMARY)\nleft_motor_a = Motor(Ports.PORT11, GearSetting.RATIO_18_1, False)\nleft_motor_b = Motor(Ports.PORT17, GearSetting.RATIO_18_1, False)\nleft_drive_smart = MotorGroup(left_motor_a, left_motor_b)\nright_motor_a = Motor(Ports.PORT14, GearSetting.RATIO_18_1, True)\nright_motor_b = Motor(Ports.PORT20, GearSetting.RATIO_18_1, True)\nright_drive_smart = MotorGroup(right_motor_a, right_motor_b)\ndrivetrain = DriveTrain(left_drive_smart, right_drive_smart, 319.19, 295, 40, MM, 1)\nfrontlm = Motor(Ports.PORT1, GearSetting.RATIO_18_1, True)\nmiddlelm = Motor(Ports.PORT4, GearSetting.RATIO_18_1, False)\nfront2lm = Motor(Ports.PORT7, GearSetting.RATIO_18_1, False)\n\n\n# wait for rotation sensor to fully initialize\nwait(30, MSEC)\n\n\n# Make random actually random\ndef initializeRandomSeed():\n wait(100, MSEC)\n random = brain.battery.voltage(MV) + brain.battery.current(CurrentUnits.AMP) * 100 + brain.timer.system_high_res()\n urandom.seed(int(random))\n \n# Set random seed \ninitializeRandomSeed()\n\n\ndef play_vexcode_sound(sound_name):\n # Helper to make playing sounds from the V5 in VEXcode easier and\n # keeps the code cleaner by making it clear what is happening.\n print(\"VEXPlaySound:\" + sound_name)\n wait(5, MSEC)\n\n# add a small delay to make sure we don't print in the middle of the REPL header\nwait(200, MSEC)\n# clear the console to make sure we don't have the REPL in the console\nprint(\"\\033[2J\")\n\n\n\n# define variables used for controlling motors based on controller inputs\ncontroller_1_left_shoulder_control_motors_stopped = True\ncontroller_1_right_shoulder_control_motors_stopped = True\ncontroller_1_up_down_buttons_control_motors_stopped = True\ndrivetrain_l_needs_to_be_stopped_controller_1 = False\ndrivetrain_r_needs_to_be_stopped_controller_1 = False\n\n# define a task that will handle monitoring inputs from controller_1\ndef rc_auto_loop_function_controller_1():\n global drivetrain_l_needs_to_be_stopped_controller_1, drivetrain_r_needs_to_be_stopped_controller_1, controller_1_left_shoulder_control_motors_stopped, controller_1_right_shoulder_control_motors_stopped, controller_1_up_down_buttons_control_motors_stopped, remote_control_code_enabled\n # process the controller input every 20 milliseconds\n # update the motors based on the input values\n while True:\n if remote_control_code_enabled:\n \n # calculate the drivetrain motor velocities from the controller joystick axies\n # left = axis3 + axis1\n # right = axis3 - axis1\n drivetrain_left_side_speed = controller_1.axis3.position() + controller_1.axis1.position()\n drivetrain_right_side_speed = controller_1.axis3.position() - controller_1.axis1.position()\n \n # check if the value is inside of the deadband range\n if drivetrain_left_side_speed < 5 and drivetrain_left_side_speed > -5:\n # check if the left motor has already been stopped\n if drivetrain_l_needs_to_be_stopped_controller_1:\n # stop the left drive motor\n left_drive_smart.stop()\n # tell the code that the left motor has been stopped\n drivetrain_l_needs_to_be_stopped_controller_1 = False\n else:\n # reset the toggle so that the deadband code knows to stop the left motor next\n # time the input is in the deadband range\n drivetrain_l_needs_to_be_stopped_controller_1 = True\n # check if the value is inside of the deadband range\n if drivetrain_right_side_speed < 5 and drivetrain_right_side_speed > -5:\n # check if the right motor has already been stopped\n if drivetrain_r_needs_to_be_stopped_controller_1:\n # stop the right drive motor\n right_drive_smart.stop()\n # tell the code that the right motor has been stopped\n drivetrain_r_needs_to_be_stopped_controller_1 = False\n else:\n # reset the toggle so that the deadband code knows to stop the right motor next\n # time the input is in the deadband range\n drivetrain_r_needs_to_be_stopped_controller_1 = True\n \n # only tell the left drive motor to spin if the values are not in the deadband range\n if drivetrain_l_needs_to_be_stopped_controller_1:\n left_drive_smart.set_velocity(drivetrain_left_side_speed, PERCENT)\n left_drive_smart.spin(FORWARD)\n # only tell the right drive motor to spin if the values are not in the deadband range\n if drivetrain_r_needs_to_be_stopped_controller_1:\n right_drive_smart.set_velocity(drivetrain_right_side_speed, PERCENT)\n right_drive_smart.spin(FORWARD)\n # check the buttonL1/buttonL2 status\n # to control frontlm\n if controller_1.buttonL1.pressing():\n frontlm.spin(REVERSE)\n controller_1_left_shoulder_control_motors_stopped = False\n elif controller_1.buttonL2.pressing():\n frontlm.spin(FORWARD)\n controller_1_left_shoulder_control_motors_stopped = False\n elif not controller_1_left_shoulder_control_motors_stopped:\n frontlm.stop()\n # set the toggle so that we don't constantly tell the motor to stop when\n # the buttons are released\n controller_1_left_shoulder_control_motors_stopped = True\n # check the buttonR1/buttonR2 status\n # to control middlelm\n if controller_1.buttonR1.pressing():\n middlelm.spin(REVERSE)\n controller_1_right_shoulder_control_motors_stopped = False\n elif controller_1.buttonR2.pressing():\n middlelm.spin(FORWARD)\n controller_1_right_shoulder_control_motors_stopped = False\n elif not controller_1_right_shoulder_control_motors_stopped:\n middlelm.stop()\n # set the toggle so that we don't constantly tell the motor to stop when\n # the buttons are released\n controller_1_right_shoulder_control_motors_stopped = True\n # check the buttonUp/buttonDown status\n # to control front2lm\n if controller_1.buttonUp.pressing():\n front2lm.spin(FORWARD)\n controller_1_up_down_buttons_control_motors_stopped = False\n elif controller_1.buttonDown.pressing():\n front2lm.spin(REVERSE)\n controller_1_up_down_buttons_control_motors_stopped = False\n elif not controller_1_up_down_buttons_control_motors_stopped:\n front2lm.stop()\n # set the toggle so that we don't constantly tell the motor to stop when\n # the buttons are released\n controller_1_up_down_buttons_control_motors_stopped = True\n # wait before repeating the process\n wait(20, MSEC)\n\n# define variable for remote controller enable/disable\nremote_control_code_enabled = True\n\nrc_auto_loop_thread_controller_1 = Thread(rc_auto_loop_function_controller_1)\n\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# \n# ------------------------------------------\n\n# Library imports\nfrom vex import *\n\n# Begin project code\n\n\n\n\n","textLanguage":"python","robotConfig":[{"port":[],"name":"controller_1","customName":false,"deviceType":"Controller","deviceClass":"controller","setting":{"left":"frontlm","leftDir":"true","right":"middlelm","rightDir":"true","upDown":"front2lm","upDownDir":"false","xB":"","xBDir":"false","drive":"split","id":"primary"},"triportSourcePort":22},{"port":[11,17,14,20,null],"name":"drivetrain","customName":false,"deviceType":"Drivetrain","deviceClass":"smartdrive","setting":{"type":"4-motor","wheelSize":"wheel4in","gear":"ratio18_1","gearRatio":"1:1","direction":"fwd","gyroType":"none","width":"295","unit":"mm","wheelbase":"40","wheelbaseUnit":"mm","xOffset":"0","xOffsetUnit":"mm","yOffset":"0","yOffsetUnit":"mm","thetaOffset":"180","id":"partner"},"triportSourcePort":null},{"port":[1],"name":"frontlm","customName":true,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"true","fwd":"forward","rev":"reverse","gear":"ratio18_1"}},{"port":[4],"name":"middlelm","customName":true,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"}},{"port":[7],"name":"front2lm","customName":true,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"}}],"slot":0,"platform":"V5","sdkVersion":"20240802.15.00.00","appVersion":"4.61.0","fileFormat":"2.0.0","targetBrainGen":"First","v5Sounds":[{"name":"game over","url":"static/sounds/mixkit-arcade-retro-game-over-213.wav"}],"v5SoundsEnabled":false,"aiVisionSettings":{"colors":[],"codes":[],"tags":true,"AIObjects":true,"AIObjectModel":[],"aiModelDropDownValue":null}}