Asked — Edited
Resolved Resolved by Rich!

Movement Scripting Help Please?≫

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?

PLEASE, PLEASE, PLEASE?

Thank you, Gwen

User-inserted image


ARC Pro

Upgrade to ARC Pro

Elevate your robot's capabilities to the next level with Synthiam ARC Pro, unlocking a world of possibilities in robot programming.

#17  

That's very nice of you @Rich

Thanks

United Kingdom
#18  

It's what I do, I'm more than happy to help when it comes to writing scripts and solving problems:) However, I do make you work a little bit for it.

Since I don't use a joystick I wasn't aware that you couldn't map scripts to directions and since (at least my joystick) sends the joystick x and y values all over the place when centred (very sensitive I guess) my original plan didn't quite work however, mapped to buttons works, possibly better.

I also don't have a sabertooth to test with. Using the custom graph I think I've got it all around the right way but a real sabertooth test is needed.

I've uploaded an example set of scripts and joystick control with mapped buttons (xbox controller, A and Y are forwards and reverse). You can download it here

What it does is this... On connection the init script must be run (set up on the connection control in the example project). This defines the motor speed variables. Without it being run it will fail on error as the variables don't exist.

The ramping script is called with control command. See the Test script for examples. However before using ControlCommand you need to set the desired end speeds. Simply set the $motor1speed_end and $motor2speed_end variables before the control command. For instance, if you wanted to ramp to full speed forwards you would use this code


$motor1speed_end = 1
$motor2speed_end = 128
ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

If it's part of a sequence or larger script change ScriptStart to ScriptStartWait to hold the script calling the command until the ramping is complete.

With the joystick buttons similar is done. Set the two speed variables as before and call the ramp speed script to run.

The ramp speed script simply increases or decreases the speed as required based on the current speed. This also means that if you suddenly need to go from forwards to reverse it wont stop quickly but ramp down then back up.

You may want to add in some emergency stop command though, as previously mentioned, just in case as ramping to stop positions may take some time, and in that time you may end up with a robot covered in furniture or a very squashed small child.

I didn't have time to comment the code properly but there isn't much that needs changing. Also it made it more difficult for me to follow when I was putting notes in it. Since it's easier to add these notes after making the script I'll do it now by annotating the main ramp code below

The ramp code is as follows;


# Script commands for gradual ramping to desired speeds using Sabertooth
# motor controller connected in simple serial mode on port D7 of EZ-B 0

# Author: Rich
# Version: 2014.10.28.00

# Desired speeds set elsewhere. This script is called with ControlCommands

$rampdelay = 20 # 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.

# Work out which direction the values need to go, i.e. increase or decrease
IF ($motor1speed < $motor1speed_end)
  $motor1steps = 1
ELSE 
  $motor1steps = -1
ENDIF 
  
IF ($motor2speed < $motor2speed_end)
  $motor2steps = 1
ELSE 
  $motor2steps = -1
ENDIF 
  

# A repeatuntil will avoid over 350 lines of extra code

# We repeat increasing the speed of the motors until both motors are at the desired speed
REPEATUNTIL($motor1speed = $motor1speed_end AND $motor2speed = $motor2speed_end)

# Send the serial commands to move the motors at the required speed
  SendSerial(D7,38400,$motor1speed)
  SendSerial(D7,38400,$motor2speed)

# Check if the motors are up to speed, if not increase it (or decrease it) by 1
  IF ($motor1speed = $motor1speed_end)
    Print("Motor1 Up To Speed")
  ELSE 
    $motor1speed = $motor1speed + $motor1steps
  ENDIF 
    # Increase motor 2's speed if required
  IF ($motor2speed = $motor2speed_end)
    Print("Motor2 Up To Speed")
  ELSE 
    $motor2speed = $motor2speed + $motor2steps
  ENDIF 
    
# Delay a little to reduce cpu load and to smooth out the ramping
  SLEEP($rampdelay)
ENDREPEATUNTIL 

That's pretty much all there is to it.

Just set the desired speed to ramp to (variables $motor1speed_end and $motor2speed_end) Run a controlcommand ARC does the rest and smoothly ramps from the current speed to the desired speed.

Check the sabertooth direction values, I didn't double check them.

Hopefully that's at least enough to copy & paste and get it up and running by halloween. It can be improved though and I'd be happy to revisit it when we both have a little more time.

Ask any questions you have, I'm always around to answer them (except for on the 31st when I'll be busy with my own Halloween stuff)

#19  

@Rich,

To script the joystick positions (as opposed to buttons), you use a custom movement panel, and script the movement directions there. A joystick will automatically drive the Movement Panel directions and center/stop (as will the arrow keys on the keyboard).

Alan

United Kingdom
#20  

Thanks (see I don't know everything:)) I'll update the project file in a bit to use the movement panel, I don't know why I didn't include a Movement Panel to begin with to be honest, too focused on making the script work without any sudden starting and stopping I guess.

Thanks Alan!

United Kingdom
#21  

Looks like I had a major brain fart on that one... I did know about the joystick moving the movement panel, I even unchecked the box for it!..

Project updated on the cloud, also fixed a couple of other things (such as the forward and reverse values) and added in ramping for turning too, however I'd be interested in knowing if the method works...

Also renamed the two graphs (the hard way - sidenote: DJ, any chance of having that in a future update? It would be really handy to know which graph does what)

Same link to the project as before or click here

#22  

I know you are helping... OMG ;)

So I'm trying to sort this out... Your download link opens an .xml file which confuses me greatly. OMG more code. Sorting code from code... Oh my...

I tried to grab the relevant code from it. I will parse it bellow. Can you describe (as explicitly as possible blush:D ) please exactly where to place which pieces of code?

Sorry I'm so obtuse with this... Nuclear medicine is easy, this,... isn't.... lol

I could assign the code to the cross joystick Not sure if that's what you call it but the ARCs software see its four deflections as buttons with the possibility of commands being issued when its depressed and when its released) on the game controller.


# Test ramping up and down

Print("Move forward")
$motor1speed_end = 1
$motor2speed_end = 128

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

Print("Move reverse")
$motor1speed_end = 129
$motor2speed_end = 255

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

Print("Stop")
$motor1speed_end = 64
$motor2speed_end = 192

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

Print("Move forwards")
$motor1speed_end = 1
$motor2speed_end = 128

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

Print("Stop")
$motor1speed_end = 64
$motor2speed_end = 192

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

Print("Move reverse")
$motor1speed_end = 129
$motor2speed_end = 255

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

Print("Stop")
$motor1speed_end = 64
$motor2speed_end = 192

ControlCommand("Movement Controls", ScriptStartWait, "Ramp Speed")

Sleep(1000)

# Script commands for gradual ramping to desired speeds using Sabertooth
# motor controller connected in simple serial mode on port D7 of EZ-B 0

# Author: Rich
# Version: 2014.10.28.00

# Desired speeds set elsewhere. This script is called with ControlCommands

$rampdelay = 20 # 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.

IF ($motor1speed < $motor1speed_end)
  $motor1steps = 1
ELSE 
  $motor1steps = -1
ENDIF 
  
IF ($motor2speed < $motor2speed_end)
  $motor2steps = 1
ELSE 
  $motor2steps = -1
ENDIF 
  
REPEATUNTIL($motor1speed = $motor1speed_end AND $motor2speed = $motor2speed_end)
  SendSerial(D7,38400,$motor1speed)
  SendSerial(D7,38400,$motor2speed)
  IF ($motor1speed = $motor1speed_end)
    Print("Motor1 Up To Speed")
  ELSE 
    $motor1speed = $motor1speed + $motor1steps
  ENDIF 
    # Increase motor 2's speed if required
  IF ($motor2speed = $motor2speed_end)
    Print("Motor2 Up To Speed")
  ELSE 
    $motor2speed = $motor2speed + $motor2steps
  ENDIF 
    
  SLEEP($rampdelay)
ENDREPEATUNTIL 

JoystickScriptsDown><string>$motor1speed_end = 1
  $motor2speed_end = 128
  ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")</string><string/><string/><string>$motor1speed_end = 127
  $motor2speed_end = 255
  ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

JoystickScriptsUp><string>$motor1speed_end = 64
  $motor2speed_end = 192
  ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")</string><string/><string/><string>$motor1speed_end = 64
  $motor2speed_end = 192
  ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

ControlCommand("Movement Controls", ScriptStart, "Init (Run First)")
ControlCommand("Graph", ScriptStart)

User-inserted image

:P:P

#23  

ok, I have to go out soon so I wont be able to decipher more and experiment until later tonight (~9:30pm or so ET)

Why when I click the link you provide do I get .xml with even more code to work through?

Also @thetechguru, when I was experimenting with my previously listed verbose ramping script, I did enter it into a custom movement script control and it seemed to ramp and function as expected when executed but when I tried to move it with the joystick it didn't work. I wasn't sure why I was using a clean project for experimentation..

United Kingdom
#24  

The download should download a .ezb file (which yes, is an xml file if you want to get technical). It should open in ARC though, don't try to understand it or copy it from a text editor, that's how problems happen:)

If you struggle to open it from downloading via the forum it's on the cloud so try opening it from within ARC. Under the File ribbon menu on the right is the EZ-Cloud. Click Open Then choose Public Library at the top of the dialogue that pops up In Catagory choose EZ-Script Examples In User select Rich (currently has a 32 after it) Hit search It should be the top one, sabertooth ramping

Open it. Save it locally

You can then merge the required controls. These would be...

Custom Movement Panel Movement Controls

Note: If you have a Movement Panel already you must remove it before merging.

Then, in your connection control click on the gear icon for the config In the top box 0 - Connection Established Cmd: put

ControlCommand("Movement Controls", ScriptStart, "Init (Run First)")

An even better option, attach your current project to this topic, I'll download it and add in the required "bits" that are needed and upload it.

Yes you could add it to the d-pad (the cross joystick) provided it is seen as buttons by ARC.

Provided you have merged the script manager (renamed to Movement Controls) in to the project just use the following code snippets.

All of these are on button down.

Forward/Up

$motor1speed_end = 1
$motor2speed_end = 255

ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Reverse/Down

$motor1speed_end = 127
$motor2speed_end = 129

ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Left

$motor1speed_end = 1
$motor2speed_end = 129

ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Right

$motor1speed_end = 127
$motor2speed_end = 255

ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")

Now on all of those On Button Up needs to be

$motor1speed_end = 64
$motor2speed_end = 192

ControlCommand("Movement Controls", ScriptStart, "Ramp Speed")