-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvex2024.iqpython
1 lines (1 loc) · 7.9 KB
/
vex2024.iqpython
1
{"mode":"Text","textContent":"#region VEXcode Generated Robot Configuration\nfrom vex import *\nimport urandom\n\n# Brain should be defined by default\nbrain=Brain()\n\n# Robot configuration code\nbrain_inertial = Inertial()\ncontroller = Controller()\nleft_drive_smart = Motor(Ports.PORT1, 1.0, False)\nright_drive_smart = Motor(Ports.PORT6, 1.0, True)\ndrivetrain = DriveTrain(left_drive_smart, right_drive_smart, 200, 173, 76, MM, 1)\nmotor_group_2_motor_a = Motor(Ports.PORT2, False)\nmotor_group_2_motor_b = Motor(Ports.PORT5, True)\nmotor_group_2 = MotorGroup(motor_group_2_motor_a, motor_group_2_motor_b)\nmotor_group_3_motor_a = Motor(Ports.PORT3, False)\nmotor_group_3_motor_b = Motor(Ports.PORT4, True)\nmotor_group_3 = MotorGroup(motor_group_3_motor_a, motor_group_3_motor_b)\n\n\n\n# Make random actually random\ndef setRandomSeedUsingAccel():\n wait(100, MSEC)\n xaxis = brain_inertial.acceleration(XAXIS) * 1000\n yaxis = brain_inertial.acceleration(YAXIS) * 1000\n zaxis = brain_inertial.acceleration(ZAXIS) * 1000\n urandom.seed(int(xaxis + yaxis + zaxis))\n \n# Set random seed \nsetRandomSeedUsingAccel()\n\n\n\n# define variables used for controlling motors based on controller inputs\ncontroller_left_shoulder_control_motors_stopped = True\ncontroller_right_shoulder_control_motors_stopped = True\n\n# define a task that will handle monitoring inputs from controller\ndef rc_auto_loop_function_controller():\n global controller_left_shoulder_control_motors_stopped, controller_right_shoulder_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 # check the buttonLUp/buttonLDown status\n # to control motor_group_2\n if controller.buttonLUp.pressing():\n motor_group_2.spin(FORWARD)\n controller_left_shoulder_control_motors_stopped = False\n elif controller.buttonLDown.pressing():\n motor_group_2.spin(REVERSE)\n controller_left_shoulder_control_motors_stopped = False\n elif not controller_left_shoulder_control_motors_stopped:\n motor_group_2.stop()\n # set the toggle so that we don't constantly tell the motor to stop when\n # the buttons are released\n controller_left_shoulder_control_motors_stopped = True\n # check the buttonRUp/buttonRDown status\n # to control motor_group_3\n if controller.buttonRUp.pressing():\n motor_group_3.spin(FORWARD)\n controller_right_shoulder_control_motors_stopped = False\n elif controller.buttonRDown.pressing():\n motor_group_3.spin(REVERSE)\n controller_right_shoulder_control_motors_stopped = False\n elif not controller_right_shoulder_control_motors_stopped:\n motor_group_3.stop()\n # set the toggle so that we don't constantly tell the motor to stop when\n # the buttons are released\n controller_right_shoulder_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 = Thread(rc_auto_loop_function_controller)\n\n#endregion VEXcode Generated Robot Configuration\n# SOTL VEX IQ COMPETITION 2-2023\n# I9BET.COM TAI XIU 2024\n# TRAO NIEM TIN, NHAN TAI LOC\nfrom vex import *\n\n\n# Brain should be defined by default\nbrain=Brain()\n\n# Robot configuration code\nbrain_inertial = Inertial()\nleft_motor = Motor(Ports.PORT1, False)\nright_motor = Motor(Ports.PORT6, True)\nmang_1 = Motor(Ports.PORT3, False)\nmang_2 = Motor(Ports.PORT4, True)\n\nintake_2 = Motor(Ports.PORT5, False)\nintake_1 = Motor(Ports.PORT2, True)\ncontroller = Controller()\n#endregion VEXcode Generated Robot Configuration\n\n# ------------------------------------------------------------------------------\n#\n# Project: Controller Buttons\n# Description: This program shows two different ways of\n# controlling robot behavior using Controller buttons.\n# Brain Supported: 2nd generation\n# Configuration: Controller\n# Left Motor in Port 1\n# Right Motor in Port 6\n# Claw Motor in Port 4\n# Arm Motor in Port 10\n#\n# ------------------------------------------------------------------------------\n\n# Library imports\nfrom vex import *\n\ndeadBand = 3;\n\n# Begin project code\n# Callback function when Controller buttonLUp is pressed\n\n\n# add 15ms delay to make sure events are registered correctly.\nwait(5, MSEC)\n\n# Set default motor stopping behavior and velocity\n\n\nintake_2.set_stopping(BRAKE)\nintake_1.set_stopping(BRAKE)\nmang_1.set_stopping(HOLD)\nmang_2.set_stopping(HOLD)\n\nleft_motor.set_stopping(HOLD)\nright_motor.set_stopping(HOLD)\n\n\n\nleft_motor.set_velocity(100, PERCENT)\nright_motor.set_velocity(100, PERCENT)\nmang_1.set_velocity(100,PERCENT)\nmang_2.set_velocity(100,PERCENT)\n\nintake_2.set_velocity(100,PERCENT)\nintake_1.set_velocity(100,PERCENT)\n\n# Loop to keep checking for Controller R Up and R Down button presses\n\nwhile True:\n if controller.buttonEUp.pressing():\n intake_2.spin(FORWARD)\n intake_1.spin(FORWARD)\n elif controller.buttonEDown.pressing():\n intake_2.spin(REVERSE)\n intake_1.spin(REVERSE) \n# ------------------------------------------------------------------------------\n elif controller.buttonRUp.pressing():\n # Spinning the claw_motor in reverse opens the claw\n mang_1.spin(FORWARD)\n mang_2.spin(FORWARD)\n elif controller.buttonRDown.pressing():\n mang_1.spin(REVERSE)\n mang_2.spin(REVERSE)\n elif controller.buttonFDown.pressing() or controller.buttonFUp.pressing():\n intake_2.stop()\n intake_1.stop()\n else:\n # Stop the claw_motor if buttonRUp is not pressed\n mang_1.stop()\n mang_2.stop()\n \n axis_a_pos = controller.axisA.position()\n axis_d_pos = controller.axisD.position()\n\n if abs(axis_a_pos) > 0 or abs(axis_d_pos) > 0:\n left_motor.spin_for(FORWARD,(axis_a_pos ), DEGREES, wait=False)\n right_motor.spin_for(FORWARD,(axis_d_pos ), DEGREES, wait=False)\n else:\n left_motor.stop()\n right_motor.stop()\n #left_motor.spin(FORWa)\n #right_motor.spin(REVERSE)\n# wait(1, MSEC)\n \n","textLanguage":"python","rconfig":[{"port":[],"name":"controller","customName":false,"deviceType":"Controller","deviceClass":"controller","setting":{"left":"motor_group_2","leftDir":"false","right":"motor_group_3","rightDir":"false","e":"","eDir":"false","f":"","fDir":"false","l3r3":"","l3r3Dir":"false","drive":"none"},"triportSourcePort":22},{"port":[1,6,null],"name":"drivetrain","customName":false,"deviceType":"Drivetrain","deviceClass":"smartdrive","setting":{"type":"2-motor","wheelSize":"200mm","gearRatio":"1:1","direction":"fwd","gyroType":"none","width":"173","unit":"mm","wheelbase":"76","wheelbaseUnit":"mm","xOffset":"0","yOffset":"0","thetaOffset":"0"},"triportSourcePort":22},{"port":[2,5],"name":"motor_group_2","customName":false,"deviceType":"MotorGroup","deviceClass":"motor_group","setting":{"fwd":"forward","rev":"reverse","motor_a_reversed":"false","motor_b_reversed":"true"},"triportSourcePort":22},{"port":[3,4],"name":"motor_group_3","customName":false,"deviceType":"MotorGroup","deviceClass":"motor_group","setting":{"fwd":"forward","rev":"reverse","motor_a_reversed":"false","motor_b_reversed":"true"},"triportSourcePort":22}],"slot":0,"platform":"IQ","sdkVersion":"20230818.11.00.00","appVersion":"3.0.4","minVersion":"3.0.0","fileFormat":"1.2.0","icon":"","targetBrainGen":"Second","v5SoundsEnabled":false,"target":"Physical"}