Speed Ramping

Rich

United Kingdom

Speed ramping is something that comes up often and while it's not (yet) a built in function in ARC's movement panels it's not too difficult to achieve.

Before anything you will need an init script to set the variables so as not to cause errors in the ramping script. These can't be set in the ramping script as it would stop it working correctly.

Two variables need defining, $motor1speed and $motor2speed.


# Define variables
$motor1speed = 1
$motor2speed = 1

These can be set to anything as other scripts will change them before ramping begins.

Then you need the ramping script which will gradually increase the speed of the motors, uncomment the required control method where indicated within the script. H-Bridges work a little differently and therefore another script will be posted to cover the H-Bridge version.

The ramping script would be as follows, I have commented it to explain each part where necessary.


# Script commands for gradual ramping to desired speeds.

# Author: Rich
# Version: 2015.01.08.00

# Desired speeds set elsewhere. This script is called with ControlCommands.
# Note: An init script must have previously run to set the variables.

$rampdelay = 50 # Adjust to suit speed increase

# Do not modify beyond this point unless you know what you are doing
# Any changes may cause the script to run incorrectly.

# Check the direction of ramping up or down and set the steps to suit
IF ($motor1speed > $motor1speed_end)
  # If true motor speed needs to increase therefore +1
  $motor1steps = 1
ELSE 
  # Otherwise it needs to decrease therefore -1
  $motor1steps = -1
ENDIF 
  
IF ($motor2speed > $motor2speed_end)
  # If true motor speed needs to increase therefore +1
  $motor2steps = 1
ELSE 
  # Otherwise it needs to decrease therefore -1
  $motor2steps = -1
ENDIF 
  
REPEATUNTIL($motor1speed = $motor1speed_end AND $motor2speed = $motor2speed_end)
# This section will now loop from the above REPEATUNTL down to ENDREPEATUNTIL until the above statement is true (until motor speeds match those required).

# Movement commands - uncomment required control method.

  # Serial Control Method (Sabertooth etc)
  # SendSerial(D7,38400,$motor1speed)
  # SendSerial(D7,38400,$motor2speed)

  # Modified servo Method
  # Servo(D7, $motor1speed)
  # Servo(D8, $motor2speed)

  IF ($motor1speed = $motor1speed_end)
    # Avoid increasing speed when not needed - in the case of uneven steps between motors. Also state motor up to speed for info.
    Print("Motor1 Up To Speed")
  ELSE 
    # Otherwise increase or decrease the motor speed
    $motor1speed = $motor1speed + $motor1steps
  ENDIF 
    # Increase motor 2's speed if required
  IF ($motor2speed = $motor2speed_end)
    # Avoid increasing speed when not needed - in the case of uneven steps between motors. Also state motor up to speed for info.
    Print("Motor2 Up To Speed")
  ELSE 
    # Otherwise increase or decrease the motor speed
    $motor2speed = $motor2speed + $motor2steps
  ENDIF 
    
  # Add a slight delay as required (increase/decrease the delay in the variable at the top of the script)
  SLEEP($rampdelay)
ENDREPEATUNTIL

Now we are in business to start ramping...

You need the Custom Movement Panel for this and each direction requires a very similar script.

For forward movement the script needs to be something like this (again commented for guidance);


# Set the required end speed for motor 1
$motor1speed_end = 1

# Set the required end speed for motor 2
$motor2speed_end = 180

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

For reverse


# Set the required end speed for motor 1
$motor1speed_end = 180

# Set the required end speed for motor 2
$motor2speed_end = 1

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Turn Right


# Set the required end speed for motor 1
$motor1speed_end = 180

# Set the required end speed for motor 2
$motor2speed_end = 180

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Turn Left


# Set the required end speed for motor 1
$motor1speed_end = 1

# Set the required end speed for motor 2
$motor2speed_end = 1

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Stop


# Set the required end speed for motor 1
$motor1speed_end = 90

# Set the required end speed for motor 2
$motor2speed_end = 90

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Note: You will more than likely need to change the values in the above depending on your servos or serial device.

And that's pretty much it for Modified Servos or Serial. PWM/H-Bridge is different and that will be in post 2 when I get the chance.

I will update as and when time permits and also post an Example Project when I get chance to make it. Enjoy:)

By — Last update
Jump to end

ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

#17  

Well it worked. I don't know why making ServoSpeed(D0, 2) and ServoSpeed(D1, 2) made it work but it did perfectly. This speed made it ramp beautifully.

:D

Thanks DJ on the short fix and thanks Rich on helping me understand code better.

Ellis

#18  

Can I start this Sabertooth ramping script with a simple call script and without installing or useing a custom movement panel? Seems that I would have to insert into the call script everything shown in the custom Movement Panel script above and set the proper $motor1speed variable speed I what to achieve.

I looks like the ramping script needs to know the final top spèed and the $motor1speed variable sets that. Does the custom Movement Panel do that in the background?

#19  

@Dave Schulpius,

Weren't you the one who posted in the thread where this started (Gwen's halloween thread) that you could set the Sabertooth to automatically ramp through Describe software? I haven't hooked mine up yet, but that sounded like an ideal solution for Sabertooth.

Alan

United Kingdom
#20  

Set the speed ramping going by first setting the speed for the motor (or motors) then call the ramping script to start. You needn't use the movement panel.

For example, if you had a script for moving a turret clockwise you would just need this (which is in the custom Movement Panel - so yes, this is done in the background);

# Set the required end speed for motor 1
$motor1speed_end = 1

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

When the script is run it will start the motor moving in the direction specified and ramp up to the speed specified. Once it's up to speed it will continue moving until told otherwise.

If it was for a sequence where it would ramp up to a speed, move for 10 seconds then ramp down to stopping you would need this;

# Set the required end speed for motor 1
$motor1speed_end = 1

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

# Sleep for 10 seconds
Sleep(10000)

# Set the required end speed for motor 1
$motor1speed_end = 63

# Start the ramping script going
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")
#21  

@Alen, Yes, I think it was me that said that. I was repeating what i read and was told by Dimension Engineering. I've never tried it though on just a Sabertooth.

@Rich, You're a jewel. Thanks for the clarity on the code. So what I hear you saying is all I need to do is send a version of your $motor1speed_end = 1 to bring the motor up to the wanted speed. I see by your scripts that changing the "1" to the value the controller is looking for is what I need to do and the motor will ramp up (and of course adjusting the Delay in the ramping script)?

However my application is a bit different than running two motors for wheels attached to a sabertooth. I'm using a DC motor on the elbow of my B9 Robot arm and have a Pot attached to it for feedback. I'm controlling it's speed and position with a Kangaroo x2 attached to the Sabertooth. DE's Kangaroo X2 does all the work figuring all this out but when it's in Independent Position mode like I'm using it there is no ramping.

I'm trying to rewrite your ramping script to give the Sabertooth a smoother start up. I'm sending Simple Serial commands through the Kangaroo connected to the Sabertooth through EZB's Uart port for the arm's up and down movement. DE says I can place a command loop like your script to ramp the speed so I thought I'd give it a try.

Here's the proper command to send through EZB's Uart port to have the Sabertooth/Kangaroo combo move one motor on it's channel 1 to a wanted position at a wanted speed:

uartWrite(1, 0, "1, p1800 s400", 0x0d)

Here's the code I have so far (thanks to Rich) . I have mixed results with it. I can get the motor to move to position and at the speed I want but haven't been able to get any ramping. I Plan to keep playing with it and have high hopes. Anyone feel free to jump with suggestions. ;)

Thanks! Dave


$rampdelay = 30 # Adjust to suit speed increase

# Check the direction of ramping up or down and set the steps to suit
IF ($motor1speed < $motor1speed_end)
  # If true motor speed needs to increase therefore +1
  $motor1steps = 1
ELSE 
  # Otherwise it needs to decrease therefore -1
  $motor1steps = -1
ENDIF 
  
REPEATUNTIL($motor1speed = $motor1speed_end)
  # This section will now loop from the above REPEATUNTL down to
  # ENDREPEATUNTIL until the above statement is true
  # (until motor speeds match those required).
  
  # Movement command
  
  # Uart - Serial Control Method (Sabertooth/Kangaroo)
UARTWrite(0, 0, "1, P"+$Moror1positon, "S"+$motor1speed, 0x0d)
  
  IF ($motor1speed = $motor1speed_end)
    # Avoid increasing speed when not needed -
    # in the case of uneven steps between motors.
    # Also state motor up to speed for info.
    Print("Motor1 Up To Speed")
  ELSE 
    # Otherwise increase or decrease the motor speed
    $motor1speed = $motor1speed + $motor1steps
  ENDIF  
    
    # Add a slight delay as required (increase/decrease the delay in the variable at the top of the script)
  SLEEP($rampdelay)
ENDREPEATUNTIL