Rotating Motor Certain Angle in a Certain Amount of Time


#1

Hi. Is there a function or way to rotate a motor 180 degrees in 6 seconds?

Thanks for your help!


#2

In Python, set the motor DPS limit using set_motor_limits, and then set the target position using set_motor_position.

Something like this:

# 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)