Motor encoders on wrong port

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.

Do these values change if you open up the sleep time between polling?

time.sleep(.05) #sleep for 100 ms

changed to

time.sleep(.1) #sleep for 100 ms

Hello,

I tries this and it still occurs:

0, 974955 , 964889, 0
0, 975074 , 965006, 0
965015, 0 , 0, 975201
965132, 0 , 0, 975318

999154, 0 , 0, 1009684
999270, 0 , 0, 1009800
0, 1009919 , 999503, 0
0, 1010037 , 999620, 0