[c++] BrickPi Encoder


#1

I want to know BrickPi’s current position.
with Encoder values, how to get brickpi’s current position?

plus, when I set BrickPi Encoder offset like below,

BrickPi.EncoderOffset[PORT_A] = BrickPi.Encoder[PORT_A]

BrickPi didn’t set Encoder to zero.
I have BrickPi+ and raspberry2.


#2

To get the encoder value, BrickPiUpdateValues() will update the value that’s stored in BrickPi.Encoder[PORT_A]. For example:

BrickPiUpdateValues() # update the value
Encoder_A_Value = BrickPi.Encoder[PORT_A] # use the encoder value

To reset the encoder value, after BrickPiSetup() you’ll need to call BrickPiUpdateValues() (get the current position), then BrickPi.EncoderOffset[PORT_A] = BrickPi.Encoder[PORT_A] (set the offset value), then BrickPiUpdateValues() again (make the offset take effect). It would look something like this:

BrickPiUpdateValues() # get the current encoder position
BrickPi.EncoderOffset[PORT_A] = BrickPi.Encoder[PORT_A] # assign the current encoder position as the offset
BrickPiUpdateValues() # make the offset take effect