Script wont reset on own

Hi. im a newbie needing help
im trying to learn the script language for my Micro Maestro 6-channel USB servo controller. im learning alot from the users guide. im trying to make a servo 0 flip a flap open with a single action, then close with repeat of action. so when run script, if flap is open, then it will close. then if when run script again, if flap is closed, it will open. I also have it turning on a led on servo 2 at same time. so the led is on when the flap is open, closed when flap is off. Heres what i came up with on my script:

# move servo 0 to either open or close
# depending on previous state
# also turns led on when in closed state

3  0 acceleration   #set acceleration
5  0 speed          #set speed

0 get_position

6000 less_than
if
   8000 0 servo
   8000 2 servo
else
   4000 0 servo
   4000 2 servo
endif

i can run the script fine the first time and it does what i want. but to run the script again it wont do anything, unless i restart the script. As long as i reset each time before running the script, it alternates open/closed like i want it to. how do i make it where i simply press “run script” repeatedly and it responds repeatedly to open or close without the need to restart the script?

I want to assign this script to a pc software program… where a single button runs the script to open or close, depending on the previous state. ive yet to get into that part yet with the SDK development kit … also a newbie at that. Any suggestions on a simple C++ compiler?

Anthony Garcia

Hello, Anthony.

Unforunately, the Maestro Control Center does not have the feature you are asking for. When you press “Run Script”, I believe it just starts the script running again from the point where it last was running. However, I will consider adding that feature in the future so you can just click one button to restart your script and run it.

In the meantime, there are some other things you could do to avoid needing to press two buttons. I would recommend adding the line “sub beginning” to the very top of your script in order to define subroutine 0 as starting there. Then you can make the script restart at subroutine 0 by running the following command at a Command Prompt:

UscCmd --sub 0

There are several different ways you could run that command besides typing it into a Command Prompt. If you are running Windows, then you could use AutoHotkey to bind that command to a particular key on your keyboard. You could also just use a normal Windows shortcut on your desktop to do the same thing by setting its “Shortcut Key” property.

For a C++ compiler and IDE (Integrated Development Environment), I recommend downloading Visual Studio Express 2012 for Windows Desktop. For help getting started with it, you can refer to the README.txt file in the Pololu USB Software Development Kit. The projects in the latest version of the Pololu USB SDK are built for Visual Studio 2008, but the process of upgrading them to 2012 is pretty easy; just try to open the project and Visual Studio will guide you through the rest.

–David

Thanks David for the help

I did download & install visual studio express for desktop. and have already played some with the simple sample in visual basic. As I try to figure out more… I may have more questions on how to incorporate the maestro script within the visual basic program. Or will that even be needed? I also will play with the windows shortcut idea too. Last time I played with visual basic was a decade ago… so I may have lots of questions.

Anthony

I would recommend just loading the script onto the Maestro before running the Visual Basic program, rather than trying to incorporate the Maestro script into the program. However, if that does not work for you for some reason, then you could compile and load a Maestro script using Visual Basic. The UscCmd utility does it, and you can see its C# source code in the Pololu USB SDK.

–David

David
the ‘sub beginning’ and running it from cmd prompt works great… thanks alot.
i assigned it to a short cut key… with the target as:
%windir%\system32\cmd.exe /k UscCmd --sub 0

And the short cut works really well now.
Lets test your windows prowess now.
When i run the shortcut, the cmd prompt dos window comes up, does everything correct, but i have to shut down the window my self.
ive seen autocad people assign cmd prompt command lines to shortcuts, and when they run them… the window comes up very quickly (too fast to read) then closes as fast and the command line was run successfully. I would like to do the same thing too. is it just a command line switch? or something in the windows shortcut properties? i tried exploring cmd ?, the properties of shortcuts, and internet searching for a answer with no results.
Thanks
Anthony

I am glad you are making progress. You should be able to just invoke UscCmd directly instead of running cmd.exe. So the Target of your shortcut should not have cmd.exe in it; the first thing in it should be the full path to UscCmd.exe in quotes. Arguments to UscCmd can be after that, outside the quotes. I think that doing this would solve your problem and make the window go away when the program is done.

–David