Two motors running at different speed, set to same speed in V5 Python

#1

My team is having trouble with a weird motor speed issue. We have a DR4B lift with one motor on each side (labeled Lift_Left and Lift_Right in the code). When we run the code, the left side of the lift is running much faster than the right. I disengaged the motors from the lift and used the on-board diagnostics in the brain and got the following results:

  • Motors wired as shown, lift set full up:
  • Left motor: 50 RPM
  • Right motor: 10 RPM
  • Motors reversed at brain, lift set full up:
  • Left motor: 10 RPM
  • Right motor: 50 RPM

Based on this, I don’t think it can be the motor, as the problem switches sides when I switch cables. I have also tried moving the right motor from port 18 to port 17, with no resolution.

I am attaching the relevant function below (code formatting seems to be really weird).

Any suggesions?

Thanks!
Wayne

Motor definitions:

Lift_Left = vex.Motor(vex.Ports.PORT13, vex.GearSetting.RATIO36_1, True)
Lift_Right = vex.Motor(vex.Ports.PORT18, vex.GearSetting.RATIO36_1, False)

Function:

def Lift(LiftSpeed):
#Lift function
if LiftSpeed > 5 or LiftSpeed < -5:
Lift_Right.spin(vex.DirectionType.FWD, LiftSpeed, vex.VelocityUnits.PCT)
Lift_Left.spin(vex.DirectionType.FWD, LiftSpeed, vex.VelocityUnits.PCT)
else:
Lift_Left.stop(vex.BrakeType.HOLD)
#Lift equalization function
if Lift_Left.rotation(vex.RotationUnits.DEG) > Lift_Right.rotation(vex.RotationUnits.DEG) + 2:
Lift_Right.spin(vex.DirectionType.FWD, 10, vex.VelocityUnits.PCT)
elif Lift_Left.rotation(vex.RotationUnits.DEG) < Lift_Right.rotation(vex.RotationUnits.DEG) - 2:
Lift_Right.spin(vex.DirectionType.REV, 10, vex.VelocityUnits.PCT)
else:
Lift_Right.stop(vex.BrakeType.HOLD)

#2

This is Python, so the formatting is very important. You can copy your code into your post, highlight it, then hit the code button, </>:

def a_formatted_function:
    print "Oooo so pretty"

Or, since RMS is online, you can set your project to public with the Options gear at the top right of the project editor, then just post the link to the project here.

#3

I put it public, so it can be found at https://www.robotmesh.com/studio/5dc47b285169f324c1aadea8

Thanks!
Wayne

#4

Ah, it is as I suspected. Because the second if...elif...else is on its own and not part of the else clause of the first if...else, it will always do some part of the if...elif...else. And that block will set Lift_Right to spin at -10%, 10%, or stop, meaning that Lift_Right will only ever spin at LiftSpeed if the motor update happens between the first if and the second if (which is unlikely, and would be largely unnoticeable given that the motors get new commands 100 times a second).

To correct this, you need to make sure that you are only setting each motor once. There are a couple of ways to go about that, so I’ll let you play around with finding some of them now that you know what to avoid.

#5

Oops. Can’t believe I didn’t see that.

Thanks!
Wayne

1 Like