Running 2 motors with motorRoateDegree()

Hello, I am having a problem with the motorRotateDegree function. When I run the Multi_Motor_Encoder_Test.py file, It runs the first portion with just the motor of Port A alright, but when it runs the part of the code where both motors should be running, only the motor in port B runs.

time.sleep(1)
power=[255,30]
deg=[360,-180]
port=[PORT_A,PORT_B]
motorRotateDegree(power,deg,port)

Why would Port A not be working.

I’m guessing the issue is that the code never resets the encoders.

Try this code:
from BrickPi import *
BrickPiSetup()
BrickPiSetupSensors()
BrickPiUpdateValues()
power=[255,30]
deg=[360,-180]
port=[PORT_A,PORT_B]
BrickPi.offset_motor_encoder = BrickPi.encoder[PORT_A]
BrickPi.offset_motor_encoder = BrickPi.encoder[PORT_B]
motorRotateDegree(power,deg,port)

That should run both motors.

Thanks… I have not had a chance to try it I will try it asap.

What exactly does the encoder do?

The encoder is a sensor built into the Lego Mindstorms NXT and EV3 motors. It provides position/speed feedback so the motor can be precisely and accurately controlled.

1 Like