I have been trying to find a decent exponential function for my drive code, and I have found one that suits my needs. However, I get an error occasionaly when accessing my drive vaue. (I can’t remember exactly what it was, but I think it said something about not being able to convert to a float). I belive this should only happen if my drive speed is not returning a number, but a NaN, imaginary number or String. But the function should only return a real number value.
drivetrain_left_side_speed = (pow((left / 127), 1.7) * 100)
Is there something I am missing?
Full code
# ---------------------------------------------------------------------------- #
# #
# Module: main.py #
# Author: deshe #
# Created: 5/29/2025, 12:17:02 PM #
# Description: V5 project #
# #
# ---------------------------------------------------------------------------- #
# Library imports
from vex import *
# Brain should be defined by default
brain=Brain()
controller = Controller(PRIMARY)
l1 = Motor(Ports.PORT17, True)
l2 = Motor(Ports.PORT1, True)
l3 = Motor(Ports.PORT18, True)
r1 = Motor(Ports.PORT11, False)
r2 = Motor(Ports.PORT16, False)
r3 = Motor(Ports.PORT2, False)
intakeM2 = Motor(Ports.PORT10, True)
intakeM1 = Motor(Ports.PORT12, True)
rDriveA = MotorGroup(r1, r2)
rDrive = MotorGroup(rDriveA, r3)
lDriveA = MotorGroup(l1, l2)
lDrive = MotorGroup(lDriveA, l3)
link = MessageLink(Ports.PORT1, 'james', VexlinkType.MANAGER)
drivetrain = DriveTrain(rDrive, lDrive, 1, 1, 1, INCHES)
brain.screen.print("Hello V5")
# define variables used for controlling motors based on controller inputs
drivetrain_l_needs_to_be_stopped_controller = False
drivetrain_r_needs_to_be_stopped_controller = False
intake_motors_stopped = True
controller_button_L_motors_stopped = True
# define a task that will handle monitoring inputs from controller
def rc_auto_loop_function_controller():
global drivetrain_l_needs_to_be_stopped_controller, drivetrain_r_needs_to_be_stopped_controller, intake_motors_stopped, controller_button_L_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 = axisA + axisC
# right = axisA - axisC
left = controller.axis3.position()
right = controller.axis2.position()
if controller.axis3.position() <= 0:
drivetrain_left_side_speed = -(pow((left / 127), 1.7) * 100)
else:
drivetrain_left_side_speed = (pow((left / 127), 1.7) * 100)
if controller.axis2.position() <= 0:
drivetrain_right_side_speed = -(pow((right / 127), 1.7) * 100)
else:
drivetrain_right_side_speed = (pow((right / 127), 1.7) * 100)
# drivetrain_left_side_speed = pow((left / 127), 2) * 100
# drivetrain_right_side_speed = pow((right / 127), 2) * 100
# drivetrain_left_side_speed = ((left / 127) ** 1.8) * 100
# drivetrain_right_side_speed = ((right / 127) ** 1.8) * 100
# check if the value is inside of the deadband range
if controller.axis3.position() < 5 and controller.axis3.position() > -5:
# check if the left motor has already been stopped
if drivetrain_l_needs_to_be_stopped_controller:
# stop the left drive motor
l1.stop()
l2.stop()
l3.stop()
# tell the code that the left motor has been stopped
drivetrain_l_needs_to_be_stopped_controller = 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 = True
# check if the value is inside of the deadband range
if controller.axis2.position() < 5 and controller.axis2.position() > -5:
# check if the right motor has already been stopped
if drivetrain_r_needs_to_be_stopped_controller:
# stop the right drive motor
r1.stop()
r2.stop()
r3.stop()
# tell the code that the right motor has been stopped
drivetrain_r_needs_to_be_stopped_controller = 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 = 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:
l1.set_velocity(drivetrain_left_side_speed, PERCENT)
l2.set_velocity(drivetrain_left_side_speed, PERCENT)
l3.set_velocity(drivetrain_left_side_speed, PERCENT)
l1.spin(FORWARD)
l2.spin(FORWARD)
l3.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:
r1.set_velocity(drivetrain_right_side_speed, PERCENT)
r2.set_velocity(drivetrain_right_side_speed, PERCENT)
r3.set_velocity(drivetrain_right_side_speed, PERCENT)
r1.spin(FORWARD)
r2.spin(FORWARD)
r3.spin(FORWARD)
if controller.buttonR1.pressing():
if intake_motors_stopped:
intakeM1.spin(FORWARD, 100, PERCENT)
intakeM2.spin(FORWARD, 100, PERCENT)
intake_motors_stopped = False
if controller.buttonR2.pressing():
if intake_motors_stopped:
intakeM2.spin(FORWARD, 100, PERCENT)
intake_motors_stopped = False
if controller.buttonL1.pressing():
if intake_motors_stopped:
intakeM1.spin(FORWARD, 100, PERCENT)
intakeM2.spin(REVERSE, 100, PERCENT)
intake_motors_stopped = False
if controller.buttonL2.pressing():
if intake_motors_stopped:
intakeM1.spin(REVERSE, 100, PERCENT)
intakeM2.spin(REVERSE, 100, PERCENT)
intake_motors_stopped = False
if not intake_motors_stopped and not controller.buttonR1.pressing() and not controller.buttonR2.pressing() and not controller.buttonL1.pressing() and not controller.buttonL2.pressing():
intake_motors_stopped = True
intakeM1.stop()
intakeM2.stop()
# wait before repeating the process
wait(10, MSEC)
# define variable for remote controller enable/disable
remote_control_code_enabled = True
rc_auto_loop_thread_controller = Thread(rc_auto_loop_function_controller)