What’s the correct/best way to fire one ball with the shooter bot?
The lego software has a “one rotation” piece.
I see all sorts of speed and position commands, but I’m not sure how to do
"one rotation"
Use these three commands to reset the motor encoder, set the motor power and/or speed limit (which is optional, and will default to no limit), and set the motor’s target position. When you set the target to 360 (1 rotation from where it was reset) the motor will run to and hold the position specified. To rotate another time, set the target to 360 higher (i.e. 720 degrees). You can keep adding 360 to the target every time you want the motor to make another full rotation.
# set the current position to zero, i.e. reset the encoder. Do this once at the beginning.
BP.offset_motor_encoder(BP.PORT_A, BP.get_motor_encoder(BP.PORT_A))
# optionally set a power limit (in percent) and a speed limit (in Degrees Per Second)
BP.set_motor_limits(BP.PORT_A, 50, 200) # no more than 50% power, and no more than 200 DPS
# tell the motor to run to position 360 (360 degrees, i.e. 1 rotation)
BP.set_motor_position(BP.PORT_A, 360) # the motor will run to and hold at 360 degrees
Awesome, I’ll try this when I get home.
I was figuring that setting the position to 360 would just make it sit there as it already was there.
Question, how does that first statement set the position to “zero”.
It looks like it would read the current position, and set it to that, whatever that was.
Unless, what it really does is do a modules 360, so that its new value is between 0 and 360.
offset_motor_encoder
will offset the motor encoder value by the value you pass the method. If you pass offset_motor_encoder
the current encoder position, i.e. get_motor_encoder
, it will offset the encoder by the current encoder value, thus effectively resetting the encoder to 0.
The motor encoders have 1 degree precision, with practically limitless bounds. If you rotate the motor forward 1000 rotations, the encoder count will be at 360,000 (degrees), and then if you turn it back 1500 rotations, it will be at -180,000 (degrees).
If you set the target to 360 using set_motor_position
, it will run the motor to the 360 degree position and hold. If you keep setting the motor target to 360, it won’t accumulate i.e. the motor will stay at the target of 360 degrees. In order to get it to make another rotation, you would need to change the target to 720 degrees.
Woot, that worked.
Nifty.
Is there documentation somewhere?
I see the source code, and the examples, but actual documentation would be great.
Like, what does the Infrared Remote Broadcast button do?