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

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.

#9  

Thanks Rich. I will definately copy this one.

PRO
Synthiam
#10  

Rich, for the PWM version... use the ServoSpeed() command. Something like this...

This will initialize the ramping...



# set PWM Ramping for hbridge pwm ports
ServoSpeed(d0, 3)
ServoSpeed(d1, 3)

Now when ever you want to make the robot move, simply do this


# example moving forward
PWM(d0, 0)
PWM(d1, 0)

Set(d2, true)
set(d3, false)
set(d4, true)
set(d5, false)

PWM(d0, 100)
PWM(d1, 100)


# example stopping
PWM(d0, 0)
PWM(d1, 0)

Also, look at the EZ-Cloud for the Continuous Rotation servo Ramping Demo. It uses ServoSpeed() as well to ramp PWM between positions.

United Kingdom
#11  

Thanks for the tips, they will certainly come in handy when I have a proper look at pwm/h-bridge control.

The issue I see with it is the ramping down then back up for moving from forward to reverse. My method wont ramp properly but I'm sure there's a simple way that I missed. And no doubt it'll cone to me out of the blue like most things do, usually while I'm driving (I have a long drive ahead of me so it's all good).

PRO
Synthiam
#12  

For PWM H-Bridge, simply use the ServoSpeed(). As in my above example. The servospeed() will ramp the speed between PWM's.

Works really well:)

United Kingdom
#13  

@ellis, I'll be posying example projects when I get home. There is already a sabertooth one (very similar to this one) on the cloud, just check under my name for it. Replace the speed ramp script for the one in post 1 and it should work.

For servo control (which I believe your controller uses) just adjust the values in the movement panel.

Once I get back home (probably late tomorrow) I'll pop up some more examples.

PRO
Synthiam
#14  

For servo control, load the project from the EZ-Cloud called Continuous Rotation Speed Ramp Demo. It shows how to use the ServoSpeed() command on the Continuous Rotation Servos for speed ramping.

Remember... ServoSpeed() ramps between two PWM's. So if you have the PWM set to 10, a ServoSpeed() of 0, and set the PWM to 100, it will instantly move to 100 PWM.

If you have a PWM set to 10, a ServoSpeed() of 2, and set the PWM to 100, it will take N time to get to 100 PWM.

So using the PWM ramping for HBridge PWM and Continuous rotation is a good way for speed ramping with one line of code per channel.

PRO
Synthiam
#15  

To better understand what ServoSpeed() does, watch this video...

So if you can understand what it is doing - it's slowly ramping the PWM between two points. It does this inside of the EZ-B. You can leverage this PWM command ServoSleep() to use for speed ramping of HBridge PWM and Continuous Rotation.

#16  

DJ I will try this ASAP. It can't be that simple. Can it?

Also thanks to Rich. I have been on your cloud and impressed with you vast number of samples. I am looking forward to visiting them. I know I need several.

Ellis