Canada
Asked — Edited

Scripting Attempt # 1

Hey All,

I've been working on my big R2 recently. It has a Sabertooth 2x25 for the foot drives and a Syren 10 for the dome.

So that leaves me with using serial commands to control the dome.

My dome uses a Pittman motor. R2's dome has a large gear type setup. The Pittman motor is a bit abrupt for starting and stopping. I've made my first attempt at advance scripting.

Take a look, have a laugh.

I'm hoping maybe someone can help me optimize/tweak it.

My main goal is to do gradual ramp ups to top speed (Left or Right) and a gradual ramp down to stop.

Dome Right - Full Speed
# Ver 1.0

# $DomeDirection 0=Right 1=Left 3=Stop
# Full Speed Right = 0

$DomeRight=0

:Begin
If ($DomeDirection=0)
  Goto(Done)
   Endif
Else
If ($DomeDirection=1)
  Goto(SlowLeft)
   Endif
Else
# Set Dome Direction = Right
$DomeDirection=0
SendSerial(D8, 38400, 125)
Sleep(200)
SendSerial(D8, 38400, 100)
Sleep(200)
SendSerial(D8, 38400, 75)
Sleep(200)
SendSerial(D8, 38400, 50)
Sleep(200)
SendSerial(D8, 38400, 25)
Sleep(200)
SendSerial(D8, 38400, $DomeRight)
goto(Done)

:SlowLeft
SendSerial(D8, 38400, 225)
Sleep(100)
SendSerial(D8, 38400, 200)
Sleep(100)
SendSerial(D8, 38400, 175)
Sleep(100)
SendSerial(D8, 38400, 128)
$DomeDirection=3
Return()

:Done
#Dome Left - Full Speed
# Ver 1.0

# $DomeDirection 0=Right 1=Left 3=Stop
# Full Speed Left = 255

$DomeLeft=255

:Begin
If ($DomeDirection=1)
  Goto(Done)
   Endif
Else
If ($DomeDirection=0)
  Goto(SlowRight)
   Endif
Else
# Set Dome Direction = Left
$DomeDirection=1
SendSerial(D8, 38400, 129)
Sleep(200)
SendSerial(D8, 38400, 150)
Sleep(200)
SendSerial(D8, 38400, 175)
Sleep(200)
SendSerial(D8, 38400, 200)
Sleep(200)
SendSerial(D8, 38400, 225)
Sleep(200)
SendSerial(D8, 38400, $DomeLeft)
$DomeDirection=1
goto(Done)

:SlowRight
SendSerial(D8, 38400, 25)
Sleep(100)
SendSerial(D8, 38400, 50)
Sleep(100)
SendSerial(D8, 38400, 75)
Sleep(100)
SendSerial(D8, 38400, 126)
$DomeDirection=3
Return()

:Done
Dome Stop
# Ver 1.0

# Script configuration - change the values below to suit
# $DomeDirection 0=Right 1=Left 3=Stop

#Dome Stop
:Begin
If ($DomeDirection=0)
  Goto(Right)
    Endif
Else
If ($DomeDirection=1)
  Goto(Left)
    Endif
Else
If ($DomeDirection=3)
goto(Stop)
Endif
Goto(Begin)

:Right
SendSerial(D8, 38400, 25)
Sleep(100)
SendSerial(D8, 38400, 50)
Sleep(100)
SendSerial(D8, 38400, 75)
Sleep(100)
SendSerial(D8, 38400, 100)
Sleep(100)
#Stop
SendSerial(D8, 38400, 127)
$DomeDirection=3
return()

:Left
SendSerial(D8, 38400, 225)
Sleep(100)
SendSerial(D8, 38400, 200)
Sleep(100)
SendSerial(D8, 38400, 175)
Sleep(100)
SendSerial(D8, 38400, 150)
Sleep(100)
#Stop
SendSerial(D8, 38400, 127)
$DomeDirection=3
Return()

:Stop


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

United Kingdom
#1  

That's a lot of script to read through at 2am...

A couple of pointers where I would have done different (not necessarily correct but a different method).


SendSerial(D8, 38400, 125)
Sleep(200)
SendSerial(D8, 38400, 100)
Sleep(200)
SendSerial(D8, 38400, 75)
Sleep(200)
SendSerial(D8, 38400, 50)
Sleep(200)
SendSerial(D8, 38400, 25)

Could be replaced with


$speed = 125
:loop1
IF($speed > $domeright)
  SendSerial(D8, 38400, $speed)
  $speed = $speed - 25
  Sleep(200)
  Goto(loop1)
ENDIF

It just saves the tiresome task of writing almost the same lines of code over and over. Double check the $speed variable, I have a feeling it may be used on some controls such as the custom movement panel.

Additionally you could reduce/remove the sleep commands and increase the speed at a slower rate by changing the $speed=$speed-25 to $speed=$speed-1 (or whatever value is smoother).

Some parts could probably be thrown in as what I call sub routines (labels and returns), and called with the Goto() command to save typing the exact same code over and over.

I'll have another look in the morning, my eyes are tired and my brain shut off 15 minutes ago :)

Also check the syntax of the Ifs, there are a few Elses after EndIfs, you only need to go If, ElseIf, Else, EndIf. Hope that makes sense, I'll elaborate in the morning if it doesn't.

Canada
#2  

Thanks Rich,

Ya I'm sure there is some better ways to do this.

I did it systematically simple. That's how I roll!

I'll tinker with what you posted for now.

Your help is greatly appreciated.