Asked — Edited

Time For A Script

I want to start writing some scripting, but don't know where to start. I need a format to follow to know what I should consider as first thing, second, etc. I know the following things I want to do on startup but don't have an example or guide to look at.

Here is what I want to do: 1) Set all servos to a home position at a slow speed so as not to damage anything. 2) set maximum speed for each servo. 3) sequence through the AutoPosition functions as I want or as the inputs allow (voice commands or sonic sensors etc.) 4) At end go to shut down mode and set all servos to a home position.

I am not looking to have someone write the code for me, I am just asking for a place for an example or show me a format.

I need to start somewhere. I know others will benefit from this advice.

Ron R


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.

United Kingdom
#1  

Hey Ron.

I'm in complete agreement with you in the other thread about having a one stop area containing script examples. We know that some can be found in the Cloud and through forum searches, but this is time consuming, has the possibility to have something missed, and they don't always come with simple to understand explanations. I'm all for learning the scripting language rather than having it handed to me on a plate, but seeing a working example personally helps me see how the different elements work.

Anyway, I can help with a startup script with the following example...

# This will clear the selected servo 
# speeds for initialisation. (Zero is 
# servo reset).

ServoSpeed(d0, 0)
ServoSpeed(d1, 0)
ServoSpeed(d2, 0)
ServoSpeed(d3, 0)
ServoSpeed(d4, 0)
ServoSpeed(d5, 0)


# Move the servos into initialisation 
# positions where you want the servos 
# to start from. (Change the last set
# of numbers to how 
# you want them.)

Servo(d0, 2)
Servo(d1, 180)
Servo(d2, 18)
Servo(d3, 77)
Servo(d4, 163)
Servo(d5, 105)


# This will set the servo speed for 
# these servos which will be used 
# from now on.

ServoSpeed(d0, 5)
ServoSpeed(d1, 5)
ServoSpeed(d2, 5)
ServoSpeed(d3, 5)
ServoSpeed(d4, 5)
ServoSpeed(d5, 5)

# Then add any start up
# scripts here...

To do a closedown script, you could add a script control (something like an Off button. I have one on my K-9 mobile app) and create something similar to the script above. The only thing you need to remember is to press this before you kill the power. As far as I'm aware, there is no other way to do it.

Hope that helps.

Steve.

#2  

I don't know of any way to run a shutdown script either when you shut down power. We have brought up this problem in the past and haven't found a good answer. However I've been thinking that maybe some type of timer circuit connected to a relay that the main power would run through could be added that would delay shutdown when the power button was pushed. Then a second switch could be added that would be triggered at the same time as the power button. The second switch could be monitored by an ADC port on EZB and watched by a looping shut down script. When the script sees the ADC voltage change it would run the shutdown routine script. The shutdown script would have to finish before the timer circuit released the relay to shut down power.

Another simpler way would be just to have a button you need to push or a voice recognition command that would run a shutdown script. But as Steve mentioned you would have to remember to run it each time before you shut down power. I don't like to have to remember things so I don't like this last option. mad

United Kingdom
#3  

@Dave.

I have to be honest and agree with you about my idea of remembering to "press a button" to run a shut down script. My Victor project which was based on a Roomba used this, because I had to reset the Roomba's state to allow it to charge it's battery. If I forgot and shut the project down or killed the v4's power without running the shutdown script, the Roomba wouldn't charge. I had to reopen the project, power on the EZ-B again, then run he script to reset the Roomba (or manually reset it) to allow it to charge. It was a pain in the neck sometimes. eyeroll

I do like the idea of using a relay and timer though. I'll have to give that some thought myself for future projects.

#4  

Ya, the more I thing about it the more I think it could work. I just saw this BattleSwitch in anouther threaad that would work.

BattleSwitch

User-inserted image

This may work also:

Timed relay

User-inserted image

#5  

I think I have a timer with a relay around somewhere. I will dig it up and that will be one thing less to buy. I may need to latch it on startup with a push button and a relay. I will send a signal from the ezb when it is time to shut down. The timer can run for "x" seconds then remove power.

Ron R

United Kingdom
#6  

The forum tag EZ-Script should give you plenty of examples to go by, however the tags aren't always used as they should be so you'll likely have to wade through the rubbish to get to what you need.

Or, just check my forum posts and cloud, pretty much all of my cloud projects are script based and most give a link to the forum posts they marry up to. My forum posts should help too, however be aware there may be some syntax changes in the EZ-Script since I wrote the posts.

My Ping Roam script topic has a lot of detail in it, including some scans of my code with my hand written notes on it which show my process of working out the sequence of events that needs to happen.

The EZ-Script manual is pretty explanatory too.

Not to mention the many example projects which come with ARC which DJ has provided working examples of pretty much every script function.

The rest is pure logic.

#7  

Does anyone know of any examples which work with the Date-Time functions? There is zero about what needs to go in the arguments for the functions in the Script Manual. MonthName() I figured out. MinDate() and MaxDate() return (and I believe set) the range of dates that can be worked with by the other functions (I think). They usually are associated with a date-time picker. But even there, what format do the arguments go in for setting those values? The rest, who knows. Is it MS date-time format doubles? Ascii text? How many arguments? What order. The manual just totally leaves you hanging. What good are the functions if there is no explanation of their usage? I'm referring to these: AddDays() AddMonths() AddYears() AddHours() AddMinute() AddSeconds() FmtNum() FmtDate() CDateTime()

#8  

Hi Rich... Good to hear from you... I have tried to do some scripting and so far it does what I hoped. I visited your old list of scripting info. I had forgot you had posted it.

My MINI ME will be more animated driven by events or voice commands. I think I got the idea how this script works now that that I am using the Auto Position control.

Thanks to all, Dave , Steve and Rich. As soon as I figure out how to load a video to this forum will post my Mini Me robot update.

Ron R