Hello,
Currently, I am trying to make autonomous code for a 6 motor drivetain. I have noticed that after perfecting the distance the robot turns/moves. After a while, the distance it travels or some of the turns’ rotations changes, even though me or my team mates have done nothing to the robot. It is quite frustrating to see the auton change every time. Please help me out with some tips. Everything helps. ![]()
I am using an inertial sensor.
Here’s my code below. (It’s in Python.)
def turn(direction, heading): #turn using inertial sensor
wait(50, MSEC)
inertial.reset_rotation()
#inertial.set_rotation(0)
brain.screen.clear_screen()
if direction == 'r':
while inertial.rotation() < heading:
brain.screen.print(inertial.heading())
brain.screen.new_line()
lt.spin(REVERSE)
lm.spin(REVERSE)
lb.spin(REVERSE)
rt.spin(REVERSE)
rm.spin(REVERSE)
rb.spin(REVERSE)
wait(5, MSEC)
error = inertial.rotation() - heading
while inertial.rotation() > heading:
brain.screen.print("Correcting Error:" + str(error))
brain.screen.new_line()
lt.spin(FORWARD)
lm.spin(FORWARD)
lb.spin(FORWARD)
rt.spin(FORWARD)
rm.spin(FORWARD)
rb.spin(FORWARD)
wait(5, MSEC)
else:
while inertial.rotation() > heading * -1:
brain.screen.print("Inertial Heading:" + str(inertial.heading()))
brain.screen.new_line()
lt.spin(FORWARD)
lm.spin(FORWARD)
lb.spin(FORWARD)
rt.spin(FORWARD)
rm.spin(FORWARD)
rb.spin(FORWARD)
wait(5, MSEC)
error = inertial.rotation() - heading
while inertial.rotation() > heading:
brain.screen.print("Correcting Error:" + str(error))
brain.screen.new_line()
lt.spin(FORWARD)
lm.spin(FORWARD)
lb.spin(FORWARD)
rt.spin(FORWARD)
rm.spin(FORWARD)
rb.spin(FORWARD)
wait(5, MSEC)
brain.screen.print("Final Heading:" + str(inertial.rotation()))
lt.stop()
lm.stop()
lb.stop()
rt.stop()
rm.stop()
rb.stop()
wait(50, MSEC)
def moveY(direction="f", distancecm=0.0): #move forward or backward a certain distance
circum = 2 * 3.1415926 * 4.064
rotations = distancecm / circum #need to multiply gear ratio in
rm.reset_position()
while abs(rm.position(DEGREES)) < abs(rotations * 360):
# brain.screen.print(rm.position(DEGREES))
if direction == 'f':
lt.spin(REVERSE)
lm.spin(REVERSE)
lb.spin(REVERSE)
rt.spin(FORWARD)
rm.spin(FORWARD)
rb.spin(FORWARD)
wait(5, MSEC)
else:
#brain.screen.print(rm.position(DEGREES))
lt.spin(FORWARD)
lm.spin(FORWARD)
lb.spin(FORWARD)
rt.spin(REVERSE)
rm.spin(REVERSE)
rb.spin(REVERSE)
wait(5, MSEC)
brain.screen.print(rm.position(DEGREES))
#brain.screen.new_line()
lt.stop()
lm.stop()
lb.stop()
rt.stop()
rm.stop()
rb.stop()
wait(50, MSEC) #sys.sleep(0.05)
def autonomous(): #call autonomous functions here
global isAuton
isAuton = True
brain.screen.clear_screen()
brain.screen.print("autonomous code")
#set_velo(32,32,32,32,32,32) #try increasing speed to maybe 32-33 to complete faster.
intakeA.set_velocity(80, PERCENT)
intakeB.set_velocity(70, PERCENT)
intakeC.set_velocity(100, PERCENT)
#
inertial.calibrate()
while inertial.is_calibrating():
wait(100, MSEC)
#Autonomous code here
#score middle goal - 3 balls
moveY("f", 27)
turn("l", 70)
autonIntake("in")
autonexitIntake("u") #don't place prelaod on top of the flex wheels
stopperAndDescore.set(False)
timedStopIntake(3)