Congratulations Rich, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Movement Scripting Help Please?>

Assistance Requested

Help gwen4156 with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

gwen4156 claims to have checked these sources:

Can anyone help with scripting? I need to be able to have the speed of the G-Bot be ramped up and down rather than full on/off or there is a serious risk it will topple.
Right now I have the sabertooth control set up as in the attached photo. I have joystick 1 of the joystick control controlling it but I only get full on or off or full clockwise or counterclockwise rotation. Also, the joystick is 90 degrees off what I'd like( '3 o'clock' = forward, '9 o'clock' = reverse, '12 o'clock' = clockwise in place, '6 o'clock' = counterclockwise in place - but I can live with that for now if I have too).
I've been reading and watching tutorials and it seems like the movement scripting control is designed to do this but the input lines are different between the movement script control and the sabertooth control(stop, forward, reverse, left right versus 'left forward', 'right forward', 'left turn left', 'right turn left', 'left turn right', 'right turn right', 'left reverse', 'right reverse') and I have no idea how to write a script command to appropriately include a variable to do what I'm trying to do (OMG, that high school curse had come true! It comes down to algebra! doesn't it? Oh noooo!)
Can anyone take mercy on us and our Halloween plans and suggest some script to try and tell me which lines should go where?


Thank you, Gwen
User-inserted image

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.

Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


There is no support for sabertooth speed ramping - I will have to add that.

I'll add it to the list Smile


OMG! DJ... Is that something that could happen quickly? How long is your list?

If not, is there a work around? Can I use another control to control the sabertooth that might support ramping?


There are a little over 300 items in the list. The priority of each item depends on what section of the code i'm working on


You can achieve a type of ramping (I think I mentioned this before) if you use serial commands (to the sabertooth) and the custom Movement Panel instead of the pre defined sabertooth Movement Panel... Or you can just use it in any script to achieve your ramping with a joystick... You assign variables to use as speed of your sabertooth... These variables can be easily change on the fly to simulate ramping... When using the custom Movement Panel write your code in the scripts available behind the forward, left, right and reverse command in the control...

something like below is serial commands to tell the sabertooth to move forward (depending on your motor wiring... loop this a few times changing the variable values will give you your ramping to some extent


$leftMotorSpeed=35 #about 50% power 63 is stop
$rightMotorSpeed=227 #about 50% power 192 is stop

SendSerial(D23,38400,$leftMotorSpeed) #any value from 1 to 127 = left motor
SendSerial(D23,38400,$rightMotorSpeed # any value from 128 to 255 = Right motor

Changing the values of $leftMotorSpeed and $rightMotorSpeed) will either slow, speed up or reverse the corresponding motor...


As Richard has pointed out, the values will affect the speed of the motors.

I posted a quick example of a ramping script a while ago, I've no idea what topic it was in though and it's probably quicker if I throw up another quick example of how to gradually increase or decrease a variable...

As always, this is an example so will need to be tailored to your project and probably used as part of a larger script.


# Speed ramp forwards direction of motor 1 (left) from slow to full speed
$startspeed = 65 # Check this value - I do not have a sabertooth to try it with
$endspeed = 1
$speedsteps = 1 # Change this to change the ramping speed

# Set up the variable for the serial command
$newspeed = $startspeed

# Looping code to gradually increase the speed
RepeatUntil($newspeed = $endspeed)

# Send the command to the sabertooth

# Increase the speed by 1
$newspeed = $newspeed - $speedsteps

# Reduce load on CPU

# Loop back

# Speed should now be at $endspeed and script will stop

I haven't tested it and it was written straight in to the forum so there may be some syntax errors (there shouldn't be but there may be).

You could take the first 3 variables out of this script and save the script as a ramping control script triggered by ControlCommand() from another script. Have the script which triggers this one set the start speed, end speed and speed steps and it'll save you having to rewrite it over and over if you need ramping for other actions.

If that last paragraph doesn't make sense I'll knock up a quick Example Project which would explain it clearer, just ask.

Hope that's of some help Smile


Hi Rich, Thanks for your response. I'm sure this is my work around and I know you did mention this before. I guess I just don't know enough about the syntax of the scripting to manipulate it with any skill.

Is anything after # a comment?

I have the script manual but it doesn't seem to include a primer or rules on syntax. I am unsure how to loop etc. Do I separate commands with commas? Do successive commands need to be on separate lines? Is there a 'loop' command etc?

I will experiment with this as I'm sure its my best option to get something going soon.

Is there anything like a scripting primer?

Thanks so much for giving me something to work with anyway!



@Rich... LOL...It's funny. I can usually get most of my coding to achieve the same results as you do (I mean with a little thought and some time on my part). However, my code still ends up being clunkier (not a word, I know) and bloated compared to yours dude... Tongue

@Gwen yes, the # is a comment out marker same as // is to C


Yes anything with a # is a comment (put there to explain what each part does so you can understand it and follow it).

The loop is the RepeatUntil() part and ends at the EndRepeatUntil. If you wanted a constant, forever loop you could use a :label and Goto() to achieve this or set a RepeatUntil() to have an impossible statement i.e. RepeatUntil(1>2)

You don't need to change much in my example I posted (however refresh the page as I noticed I made a mistake and had the code incrementing from 65 to 127 not decreasing from 65 to 1). Just the start point, end point and number of steps per loop of the code.

To move the other direction the script will need modification as far as the following goes;


# Increase the speed by 1
$newspeed = $newspeed - $speedsteps

To increase in reverse (for motor 1) it needs to add $speedsteps to $newspeed not subtract it so change the - to a +

Motor 2 works the other way... the Sabertooth likes to get confusing to follow Smile

As for separating commands. They are separated on a new line. The scripts run stupidly fast (like thousands of lines of code per second) so if you set one line to move motor 1 then another to move motor 2 both would appear to move at the same time, the delay in starting is so small it's not worth even trying to think about.

What's a "scripting primer"? (I guess that means no lol)


@Richard, you haven't seen some of my scripts! Some are very bloated and clunky. I'll often rewrite them with simpler methods after I first write them and take a look at what's written (I kind of auto pilot when writing scripts). Just look at my PingRoam examples and even the topic where I posted my methods of improving it Smile