Hi,
I have some issues with the encoder values of the motors. When I run the next script:
from BrickPi import * #import BrickPi.py file to use BrickPi operations
BrickPiSetup() # setup the serial port for communication
BrickPi.MotorEnable[PORT_C] = 1 #Enable the Motor A
BrickPi.MotorEnable[PORT_B] = 1
BrickPi.MotorSpeed[PORT_C] = 200 #Set the speed of MotorA (-255 to 255)
BrickPi.MotorSpeed[PORT_B] = 200
BrickPiSetupSensors() #Send the properties of sensors to BrickPi
result = BrickPiUpdateValues()
referenceB = BrickPi.Encoder[PORT_B]
referenceC = BrickPi.Encoder[PORT_C]
i = 0
while True:
result = BrickPiUpdateValues() # Ask BrickPi to update values for sensors/motors
if not result : # if updating values succeeded
A = ( BrickPi.Encoder[PORT_A])
B = ( BrickPi.Encoder[PORT_B])
C = ( BrickPi.Encoder[PORT_C]) # print the encoder degrees
D = ( BrickPi.Encoder[PORT_D])
print "%d, %d , %d, %d" %(A,B,C,D)
i = i +1
time.sleep(.05) #sleep for 100 ms
I get the following output:
A B C D
…
0, 59387 , 62838, 0
0, 59427 , 62882, 0
0, 59468 , 0, 59469
62928, 0 , 0, 59508
62971, 0 , 0, 59548
…
90080, 0 , 0, 84153
90124, 0 , 0, 84192
90167, 0 , 0, 84232
90210, 0 , 90255, 0
0, 84312 , 90299, 0
0, 84352 , 90344, 0
…
as you can see the encoder values can switch randomly from port.