We are doing a competition for our robotics class. We need to have autonomous and driver control. I can have the joystick control during the user control period. I use the programming example that uses individual left and right motor commands to match the position of the joysticks to the motor speed. However, I can’t turn accurately in autonomous without the Drivetrain command. So is there a way to have tank joystick control and be able to do autonomous?
As for any programming question, please post the code that you already have.
def pre_autonomous():
# actions to do when the program starts
arm.set_timeout(2, SECONDS)
arm.set_stopping(HOLD)
claw.set_timeout(2, SECONDS)
claw.set_stopping(HOLD)
arm.set_velocity(30, PERCENT)
claw.set_velocity(30, PERCENT)
def autonomous():
#actions to do when the autonomous starts
left_motor.spin_for(REVERSE, 2, TURNS)
right_motor.spin_for(FORWARD, 2, TURNS)
def user_control():
#actions to do when the user_control starts
while True:
left_motor.set_velocity(controller_1.axis3.position(), PERCENT)
right_motor.set_velocity(controller_1.axis2.position(), PERCENT)
left_motor.spin(FORWARD)
right_motor.spin(FORWARD)
wait(5, MSEC)
if controller_1.buttonL1.pressing():
arm.spin(FORWARD)
else:
arm.stop()
if controller_1.buttonL2.pressing():
arm.spin(REVERSE)
else:
arm.stop()
if controller_1.buttonR1.pressing():
claw.spin(FORWARD)
else:
claw.stop()
if controller_1.buttonR2.pressing():
claw.spin(REVERSE)
else:
claw.stop()
wait(5, MSEC)
wait(5, MSEC)
# create competition instance
comp = Competition(user_control, autonomous)
pre_autonomous()
autonomous()
user_control()
For the turn functions, just type in the parameter: wait=false.
For example, using your program:
left_motor.spin_for(REVERSE, 2, TURNS, wait=false)
I would recommend you do that for only the first turn command in a row of functions. Hope this helps.
2 Likes
okay thanks!
20 characters
1 Like