Our coder has been experiencing issues while coding that I have yet to see in all of my years of doing Vex. Instead of turning during the autonomous, the robot drives straight forwards. This happens when we try to turn in either direction. Once in driver control, the robot turns completely fine with no issues. Although this is our coder’s first year coding, I see no issues with the code. I have it posted below in case I missed something. It’s not an issue with the build as it works in driver control. Any help would be greatly appreciated!
-Team 11865A
#region VEXcode Generated Robot Configuration
from vex import *
import urandom
import math
# Brain should be defined by default
brain=Brain()
# Robot configuration code
# wait for rotation sensor to fully initialize
wait(30, MSEC)
# Make random actually random
def initializeRandomSeed():
wait(100, MSEC)
random = brain.battery.voltage(MV) + brain.battery.current(CurrentUnits.AMP) * 100 + brain.timer.system_high_res()
urandom.seed(int(random))
# Set random seed
initializeRandomSeed()
def play_vexcode_sound(sound_name):
# Helper to make playing sounds from the V5 in VEXcode easier and
# keeps the code cleaner by making it clear what is happening.
print("VEXPlaySound:" + sound_name)
wait(5, MSEC)
# add a small delay to make sure we don't print in the middle of the REPL header
wait(200, MSEC)
# clear the console to make sure we don't have the REPL in the console
print("\033[2J")
#endregion VEXcode Generated Robot Configuration
#endregion VEXcode Generated Robot Configuration
#Robot Config.
from vex import *
import urandom
import math
# Brain should be defined by default
brain=Brain()
#DEFINE
controller_1 = Controller(PRIMARY)
left_motor_a = Motor(Ports.PORT1, GearSetting.RATIO_6_1, True)
left_motor_b = Motor(Ports.PORT11, GearSetting.RATIO_6_1, False)
left_drive_smart = MotorGroup(left_motor_a, left_motor_b)
right_motor_a = Motor(Ports.PORT3, GearSetting.RATIO_6_1, False)
right_motor_b = Motor(Ports.PORT2, GearSetting.RATIO_6_1, True)
right_drive_smart = MotorGroup(right_motor_a, right_motor_b)
drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 219.44, 295, 40, MM, 3)
OuterMiddle = Motor(Ports.PORT15, GearSetting.RATIO_18_1, False)
InnerBottom = Motor(Ports.PORT19, GearSetting.RATIO_18_1, False)
OuterUpper = Motor(Ports.PORT9, GearSetting.RATIO_18_1, False)
InnerMiddle = Motor(Ports.PORT20, GearSetting.RATIO_18_1, False)
Agitator = Motor(Ports.PORT10, GearSetting.RATIO_18_1, False)
MatchLoad = DigitalOut(brain.three_wire_port.h)
# wait for rotation sensor to fully initialize
wait(30, MSEC)
# define variables used for controlling motors based on controller inputs
controller_1_left_shoulder_control_motors_stopped = True
controller_1_right_shoulder_control_motors_stopped = True
controller_1_up_down_buttons_control_motors_stopped = True
controller_1_x_b_buttons_control_motors_stopped = True
drivetrain_l_needs_to_be_stopped_controller_1 = False
drivetrain_r_needs_to_be_stopped_controller_1 = False
# define a task that will handle monitoring inputs from controller_1
def rc_auto_loop_function_controller_1():
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, controller_1_x_b_buttons_control_motors_stopped, remote_control_code_enabled
# process the controller input every 20 milliseconds
# update the motors based on the input values
while True:
if remote_control_code_enabled:
# calculate the drivetrain motor velocities from the controller joystick axies
# left = axis3 + axis1
# right = axis3 - axis1
drivetrain_left_side_speed = controller_1.axis3.position() + controller_1.axis1.position()
drivetrain_right_side_speed = controller_1.axis3.position() - controller_1.axis1.position()
# check if the value is inside of the deadband range
if drivetrain_left_side_speed < 5 and drivetrain_left_side_speed > -5:
# check if the left motor has already been stopped
if drivetrain_l_needs_to_be_stopped_controller_1:
# stop the left drive motor
left_drive_smart.stop()
# tell the code that the left motor has been stopped
drivetrain_l_needs_to_be_stopped_controller_1 = False
else:
# reset the toggle so that the deadband code knows to stop the left motor next
# time the input is in the deadband range
drivetrain_l_needs_to_be_stopped_controller_1 = True
# check if the value is inside of the deadband range
if drivetrain_right_side_speed < 5 and drivetrain_right_side_speed > -5:
# check if the right motor has already been stopped
if drivetrain_r_needs_to_be_stopped_controller_1:
# stop the right drive motor
right_drive_smart.stop()
# tell the code that the right motor has been stopped
drivetrain_r_needs_to_be_stopped_controller_1 = False
else:
# reset the toggle so that the deadband code knows to stop the right motor next
# time the input is in the deadband range
drivetrain_r_needs_to_be_stopped_controller_1 = True
# only tell the left drive motor to spin if the values are not in the deadband range
if drivetrain_l_needs_to_be_stopped_controller_1:
left_drive_smart.set_velocity(drivetrain_left_side_speed, PERCENT)
left_drive_smart.spin(FORWARD)
# only tell the right drive motor to spin if the values are not in the deadband range
if drivetrain_r_needs_to_be_stopped_controller_1:
right_drive_smart.set_velocity(drivetrain_right_side_speed, PERCENT)
right_drive_smart.spin(FORWARD)
# check the buttonL1/buttonL2 status
# Basket
if controller_1.buttonL1.pressing():
InnerBottom.spin(FORWARD)
OuterMiddle.spin(REVERSE)
InnerMiddle.spin(REVERSE)
controller_1_left_shoulder_control_motors_stopped = False
# Mathc
elif controller_1.buttonL2.pressing():
MatchLoad.set(True)
wait(20, MSEC)
controller_1_left_shoulder_control_motors_stopped = False
elif not controller_1_left_shoulder_control_motors_stopped:
Agitator.stop()
InnerBottom.stop()
OuterMiddle.stop()
InnerMiddle.stop()
# set the toggle so that we don't constantly tell the motor to stop when
# the buttons are released
controller_1_left_shoulder_control_motors_stopped = True
# check the buttonR1/buttonR2 status
# to control motor_15
if controller_1.buttonR1.pressing():
OuterMiddle.spin(REVERSE)
OuterUpper.spin(REVERSE)
InnerBottom.spin(FORWARD)
InnerMiddle.spin(FORWARD)
controller_1_right_shoulder_control_motors_stopped = False
elif controller_1.buttonR2.pressing():
OuterMiddle.spin(REVERSE)
OuterUpper.spin(FORWARD)
InnerMiddle.spin(FORWARD)
InnerBottom.spin(FORWARD)
controller_1_right_shoulder_control_motors_stopped = False
elif not controller_1_right_shoulder_control_motors_stopped:
OuterMiddle.stop()
OuterUpper.stop()
InnerBottom.stop()
InnerMiddle.stop()
# set the toggle so that we don't constantly tell the motor to stop when
# the buttons are released
controller_1_right_shoulder_control_motors_stopped = True
# check the buttonUp/buttonDown status
# to control motor_4
# set the toggle so that we don't constantly tell the motor to stop when
# the buttons are released
controller_1_up_down_buttons_control_motors_stopped = True
# Agitator Code
if controller_1.buttonA.pressing():
Agitator.spin(FORWARD)
controller_1_x_b_buttons_control_motors_stopped = False
elif controller_1.buttonB.pressing():
while controller_1.buttonB.pressing():
Agitator.spin(FORWARD)
wait(0.7, SECONDS)
Agitator.spin(REVERSE)
wait(0.7, SECONDS)
controller_1_x_b_buttons_control_motors_stopped = False
elif not controller_1_x_b_buttons_control_motors_stopped:
Agitator.stop()
if controller_1.buttonX.pressing():
MatchLoad.set(False)
wait(20, MSEC)
elif controller_1.buttonDown.pressing():
while controller_1.buttonDown.pressing():
InnerBottom.spin(FORWARD)
OuterMiddle.spin(FORWARD)
# set the toggle so that we don't constantly tell the motor to stop when
# the buttons are released
controller_1_x_b_buttons_control_motors_stopped = True
# wait before repeating the process
wait(20, MSEC)
# define variable for remote controller enable/disable
remote_control_code_enabled = True
rc_auto_loop_thread_controller_1 = Thread(rc_auto_loop_function_controller_1)
#endregion VEXcode Generated Robot Configuration
# ------------------------------------------
#
# Project: Testing Version 1.62
# Author: (name removed for privacy)
# Created: XXX
# Description: Auto Test
#
# ------------------------------------------
# Library imports
from vex import *
# Begin project code
def pre_autonomous():
# actions to do when the program starts
OuterMiddle.set_velocity(100, PERCENT)
InnerBottom.set_velocity(100, PERCENT)
OuterUpper.set_velocity(100, PERCENT)
InnerMiddle.set_velocity(100, PERCENT)
Agitator.set_velocity(100, PERCENT)
drivetrain.set_drive_velocity(100, PERCENT)
def autonomous():
# place automonous code here
OuterMiddle.set_velocity(100, PERCENT)
InnerBottom.set_velocity(100, PERCENT)
OuterUpper.set_velocity(100, PERCENT)
InnerMiddle.set_velocity(100, PERCENT)
Agitator.set_velocity(100, PERCENT)
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive_for(FORWARD, 1000, INCHES)
drivetrain.turn_for(RIGHT, 234, DEGREES)
drivetrain.set_turn_velocity(100, PERCENT)
wait(5, SECONDS)
InnerBottom.spin(REVERSE)
InnerMiddle.spin(FORWARD)
OuterMiddle.spin(REVERSE)
Agitator.spin(REVERSE)
#drivetrain.drive_for(FORWARD, 12, INCHES)
def user_control():
#place driver control here
OuterMiddle.set_velocity(100, PERCENT)
InnerBottom.set_velocity(100, PERCENT)
OuterUpper.set_velocity(100, PERCENT)
InnerMiddle.set_velocity(100, PERCENT)
Agitator.set_velocity(100, PERCENT)
drivetrain.set_drive_velocity(100, PERCENT)
# create the competition variables
comp = Competition(user_control, autonomous)
#pre_autonomous()