Reset encoders


#1

Hello!We are modifying the wificar script and im having noob problems with the encoders.

We want to save a log register with the movements of the car, but we cant reset the encoders to 0 when we reset the program. There is some command to do this? We are working with python by the way.

And sorry if its a novice question.

This is the line we are doing.

while True:
    try:
        c = raw_input("Enter direction: ")
        if c == '8' :
            BrickPiUpdateValues()
            print(BrickPi.Encoder[PORT_A])
            f.write("%s  " % BrickPi.Encoder[PORT_A])
            f.write("%s  " % BrickPi.Encoder[PORT_D])
            f.write("%sn" % BrickPi.SensorType[PORT_4])
            print "Running Forward"
            BrickPi.MotorSpeed[PORT_A] = -200 #Set the speed of MotorA (-255 to 255)
            BrickPi.MotorSpeed[PORT_D] = -200 #Set the speed of MotorD (-255 to 255)

#2

It doesn’t appear that the Python drivers support offsetting the encoders.

In C, you can add to or subtract from the encoder value using the variable BrickPi.EncoderOffset[port]. If you want to reset the encoder value to 0, you can use something like this BrickPi.EncoderOffset[port] = BrickPi.Encoder[port]; where the port is PORT_<A, B, C, D>.


#3

I tried to do what you said in C, but it doesnt work. I am doing something bad in the script? its just a simple speed test for my motors. But need reset my encoders to 0 each time my program runs.

Thank you.

http://pastebin.com/1SdB98ux


#4

Ok, im stupid. Forgot to write a BrickPiUpdateValues(); before the EncoderOffset. This work now and reset my encoders to 0. Thank you very much.