BrickPi3 set_motor_position speed?

Hey there, just a quick question:
Can I set the speed while setting a position?

BP.set_motor_position(BP.PORT_A, 1000 [degrees])

Where would the speed fit in there? I currently am programming the arm of my Bobcat and can’t have it going up and down with speed set to 100.

I don’t have a BrickPi3 but from examining the code I would try inserting a call to:

BP.set_motor_dps(BP.PORT_A, target)     # set the target speed for motor A in Degrees Per Second

before your call to:

BP.set_motor_position(BP.PORT_A, 1000 [degrees])



more useful info on this topic here:

Hmm, interesting. Putting the BP.set_motor_dps... in front of the position command makes it very weird, running very slowly when not called and when called it doesn’t do what you said above. But thanks anyway for the help.

Sorry for the bad info.

Try this code:

# turn degrees
TargetDegrees = 180

# seconds to reach target
TimeToTarget = 6

# degrees per second
DegreesPerSecond = TargetDegrees / TimeToTarget

# read the starting position
StartingPosition = BP.get_motor_encoder(BP.PORT_A)

# add target rotation to starting position to get absolute target
FinalPosition = StartingPosition + TargetDegrees

# set the DPS limit
BP.set_motor_limits(BP.PORT_A, dps = DegreesPerSecond)

# set the absolute target
BP.set_motor_position(BP.PORT_A, FinalPosition)

From @Matt (Dexter Industries Engineer) in this post:



Thank you so much. It works! :smile:

1 Like