Python speed control

I am wondering about the step motors used for the GoPiGo3 and slew rates. I want to start and stop the GoPiGo3 gently, so I naturally thought about ramping the wheel speed up from some small value to high speed and from some high speed back down to a small value before stopping. It would seem that set_speed() is the function to use, but I am not sure that the speed set during an actuation of the drive command is in progress. I know that there is a mutes that allows some interaction with the motor command after it has been issued. I just want to know if it is possible to modify the speed that gets set with set_speed() during a drive command and that the command honors the new speed on the fly. If not, can the same thing be accomplished by sending small motion segments with the purpose of gradually increasing or decreasing motor speed?

1 Like

what have you tried?

I tried egpg3.set_motor_dps(egpg3.MOTOR_RIGHT,100) during an egpg3.forward() and indeed the right wheel slowed down. (forward() also uses set_motor_dps())

The ramp up, down to target speed is classic motor control. (implementing it asynchronously to allow emergency stops and obstacle avoidance steering and stall detection is a great multi-threading learning opportunity that is beyond simple, so an easy way to avoid your bot falling over is to set speed limit around 130-150, and not worry abount ramping.)

BTW, one of the more complex examples ( ) uses the same set_motor_dps() method I mentioned:

          gpg.set_motor_dps(gpg.MOTOR_LEFT, dps=leftMotorSpeed)
          gpg.set_motor_dps(gpg.MOTOR_RIGHT, dps=rightMotorSpeed)
1 Like

set_speed() will not change the motor speed right away. You would have to issue another forward() command.
And indeed for this kind of application, you’re better off with the lower level methods found in like set_motor_dps.


1 Like

Now I’m going to ask rather than try to figure out what is going on inside the (blackbox) GoPiGo3 controller.

Q) Is this the correct data flow?

  1. set_speed(new_value) is setting the instance speed variable and a GoPiGo3 internal motor_limit to new_value DPS,
  2. the next forward sets the internal GoPiGo3 speed to NO_LIMIT_SPEED DPS (1000)
  3. but the GoPiGo3 controller will set the internal target speed to be the lower value motor_limit DPS?

Q) get_motor_status() returns the last measured speed or the internal target speed or the internal set_speed (NO_LIMIT_SPEED) or ?