So I’m trying to get some more precise movements with my BrickPi but I cant seem to get the motors to move and the encoders to spit out data at the same time. I can get the encoders to work by themselves, measuring simply how much I turn the wheel. But I cant get the motor to turn and the encoder to measure them at the same time.
If I try to run the motor at say a speed (power = 100) and tell the motor encoders to print every second or so, the motors don’t turn.
But if I try to run the motors without the encoders on, the motors work.
from BrickPi import * BrickPiSetup() BrickPi.MotorEnable[PORT_A] = 1 #Enable the Motor A BrickPi.MotorEnable[PORT_B] = 1 #Enable the Motor B BrickPi.MotorEnable[PORT_C] = 1 #Enable the Motor A BrickPi.MotorEnable[PORT_D] = 1 #Enable the Motor B BrickPiSetupSensors() #Send the properties of sensors to BrickPi BrickPi.Timeout=10000 #Set timeout value for the time till which to run the motors after the last command is pressed BrickPiSetTimeout() #Set the timeout print "Note: One encoder value counts for 0.5 degrees. So 360 degrees = 720 enc. Hence, to get degress = (enc%720)/2 " power = 100 BrickPi.MotorSpeed[PORT_A] = power BrickPi.MotorSpeed[PORT_B] = power BrickPiUpdateValues() time.sleep(0.1) while True: result = BrickPiUpdateValues() Encoder_A_2 = BrickPi.Encoder[PORT_A] Encoder_B_2 = BrickPi.Encoder[PORT_B] Encoder_C_2 = BrickPi.Encoder[PORT_C] Encoder_D_2 = BrickPi.Encoder[PORT_D] print "Encoder A: " + str(Encoder_A_2) print "Encoder B: " + str(Encoder_B_2) print "Encoder C: " + str(Encoder_C_2) print "Encoder D: " + str(Encoder_D_2) print "___________________"