UscCmd Possible?

This is my first robotics project and as of today I figured out how to control a robot from a web page using PHP script that executes UscCmd calling subs but here is my thing…

I’m wondering if it is possible to send variables of some sort to the command. Here is what I am looking for:

I’d like to create buttons that call a sub with UscCmd that moves servo 0 clockwise by say 30 or 100 and then after it moves, clicking it once again will turn it another 30 or so until it reaches the max or min depending which direction it is turning. I would like to make a sub for each direction for each servo as well. I tried using some simple math and get_position but I do not believe this was the proper method.

In a perfect world I would be able to tell the sub how far to step forward or back from UscCmd as well.

Writing something new using C# is probably a little out of my league right now as I tried tearing apart the examples to see how they tick and just can’t grasp the concept yet.

Is any of this even possible in such a simple way?

Thanks in advance!


Have you tried to use the --sub , command that allows a command to be passed in? I am actually not sure why you want to use subroutines for this - but I think you could do it like this:

sub step
  0 get_position 30 plus 0 servo

Does that not do what you want? You could also add an option to UscCmd for setting the target directly, using the setTarget() method in Usc.cs. This would be pretty easy, and it would allow you to just send the position that you want it to go to every time, so you would not have to do any Maestro scripting.


I’m very open to suggestions on better ways of hooking into the bot via a web interface. This was pretty much the only thing I could come up with so far that I knew I could manage. And I’m sure I’m not grasping the full spectrum of what is available to me with this device so I’m just kind of trudging with what I know and going from there. You could compare me playing with this stuff to a 5 year old trying to figure out an expert erector set, although I’ve had a real blast tinkering with maestro and making and especially refining my projects and so far the servos and controller were worth every bit I paid for them. I even have it all working in Debian Linux other than I can’t save scripts to the device with maestro or UscCmd for some reason.

Anyhow…with a little tinkering and your example I got what I wanted this time around.

I wrote 6 subs for each servo, 3 in each direction, each moves the servo at a different distance so I have 3 different levels of movement on the web page. I use simple web links and a GET to choose which sub to run in an iframe, this way I can have the camera running the whole time right above the controls. I have all of this running over wifi with a eeepc (apache, PHP, motion camera server, and camera all on board).

Great! I am glad you got it working - does that mean you did actually figure out how to save scripts on the device, or did you have to use Windows for that? If that is all working for you, I think you are probably doing it just fine. One other thing you could consider is using the subroutine with parameter command to tell it how far to turn left or right; with that, you could use an HTML imagemap or something to basically allow a click to point the camera at a new spot.

Any chance you will put this camera/Maestro server up on a public website so we can see? It sounds like a great project, way beyond what I was able to do with my Erector Set when I was 5.


Apologies for this being so long and having so many questions but this project is moving forward so fast I just want to keep on rolling while I’m feeling inspired.

The web code I wrote is totally insecure for being out on the net as of yet but I do have the page password protected and port forwarded on an odd port to show my buddies what I’m doing. If you would like to see what I have, let me know and I will message you the info. Yesterday I mounted a webcam to the “wrist” of the arm and made it so the cam watching the arm and the arm cam itself sit side by side on the page. Also remember this is my initial testing phase so the arm is put together with black tape and some other pieces. I’m definitely not some kind of engineer hehe.

I have never been able to get Maestro or UscCmd to save the settings in Linux and yes I have been bouncing back and forth to Windows to adjust the script. It’s kind of a pain but I’m fine with it if this is how it is.

There are a few things I can’t quite grasp as of yet including the with param stuff. In an ideal situation I would be able to pass the distance, speed and acceleration to the servos but I’m not so sure if that is even possible. I did see the stuff in the documentation but there was no usage example so I’m not sure what a line would look like that has speed and/or accel set. If you could give me an example of the scripting for the bot (working from your previous example if possible) and how UscCmd would be used it would be greatly appreciated.

I believe if I could figure this out I could eventually write a PHP class that interacted with a pre-built maestro_settings file. Load the file, apply it to the bot, put the software somewhere safe on the server and write your own PHP interface for controls. If I do get to this point I will share it with the world if it seems workable.

on another note… I believe I seen somewhere in this forum talks about using an old serial joystick controller to operate the servos manually by wiring the joystick to the maestro somehow. If you have any links to detailed information regarding this I would greatly appreciate that as well.

Eventualy I would like to have an option to connect a Playstation 2 controller (in analog mode) via usb adapter to the Linux machine controlling the arm but I am sure this would require building some sort of software to link the two. This might be out there but I have a vision of being able to control all pieces of the arm independently using the joysticks and using the buttons for movement “macros”. Maybe this is too far fetched, I dunno. Although this is just a simple arm, my ultimate goal with this new hobby is to build myself some sort of eeepc powered bot that drives or walks around and is controlled over a wifi connection.

As far as near future goals are concerned, I want to create or buy some sort of grasping device to mount on the end of the arm, if you have any ideas where I could get an inexpensive pre-built unit, once again I would appreciate it immensely.

I’m also wondering what other types of things can interface with the unit. I seen the lights example but here is my curiosity:

I have a battery pack attached to the maestro to power the servos. I’d like to be able to turn the power to the pack on and off using UscCmd. This way I dont have to go out and shut it off when I am done playing with it and I can create a timer somehow in the page that detects large idle times and turns the battery power off. I read somewhere about using relays on a servo channel but once again, I just couldn’t quite grasp the concept.

Thanks for being so helpful.

Sorry for responding slowly to this, but my recommendation is that you add position/speed/acceleration-setting commands to UscCmd - I will try to send you example code that you can paste in to your copy of the source code in a day or two, when I get around to it. I do not think that your plans are at all unreasonable, and once you get UscCmd working the way you want it, I think you will be well on your way.

By the way, when you say you have not been able to apply the settings with UscCmd or the Control Center under Linux, can you explain exactly what you are doing and what happens when you try? There might be a remaining bug with saved sequences under linux, so if you could clear out any sequences before you try again, it might help you - but from what you have said, I do not think that is your problem.

You asked about grippers - we sell a couple of gripper units that are compatible with the maestro. Have you considered these?

As for switching the battery pack, you should probably put the switch on the high (positive) side, which means that a relay is probably the easiest way to go. You need to get one that draws less than 25mA from the Maestro, or go with a lower-current solid-state solution. But if your Maestro is plugged in (to USB) all the time, anyway, why not power your servos from a wall adapter?


Hello again,

Here is some code that you can paste into Maestro/UscCmd/Program.cs in our USB Software Development Kit. I have included a couple of lines of context so you know where to put it:

                setScriptDone(usc, 2);
            else if (opts["servo"] != null)
                string[] parts = opts["servo"].Split(new char[] {','});
                if(parts.Length != 2)
                    opts.error("Wrong number of commas in the argument to servo.");
                byte servo=0;
                ushort position=0;
                    servo = (byte)Int32.Parse(parts[0]);
                    position = (ushort)Int32.Parse(parts[1]);
                Console.Write("Setting servo "+servo+" to target "+position+"...");
                usc.setTarget(servo, position);
            else if (opts["sub"] != null)

If you do this, then recompile according to the instructions, you should be able to control the position of a servo using a command like “UscCmd.exe --servo 2,6000”. You should be able to figure out how to add speed and acceleration commands in the same way.

Good luck, and please let me know if you have more questions!

I forgot to mention - I tried your camera page when you sent it to me, but all it did was totally crash my firefox window, and I did not get around to trying it on any other browsers or operating systems. I guess you have it shut down already now, but I can try it again any time if you let me know that it is back up.


Yes I moved the camera to my other connection and did some work to optimize the webcam stuff. I never had a crash problem though and I use Firefox… I’m going to try to digest this code and see if I can make it work this morning.

I will also send you screenshots of what happens when I try to apply the settings in Linux as well today so you can see the error. My initial thought was device permissions, I tried making that device 666 and 777 to no avail as well. I tried applying as the root user as well with the same results.

Seen the grabber after I wrote the post… d’oh! :laughing:

Well that was quick, I had to install a few other mono pieces not in the docs to get it to compile. Seems I’ve gained a few errors now in the Maestro software. I’m thinking it had to do with the fact that I had to install mono-2.0*. We always have to remember I am using Debian testing so it may be in a funky state too.

Here’s where I am at with the Maestro software:

loads and complains about not having the script, I go to my saved script from Windows and it kind of loads it, tosses and error and does some weird stuff in the scripting window. I can move the servos on the slider tab, the speeds are all correct from the windows settings so it seems it is connecting to the device properly. I can also save frames etc… Here is what happens when I try to copy a set of frames to the script though:

~/maestro_linux$ ./MaestroControlCenter
System.NotSupportedException: CodePage 1252 not supported
at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000]
at System.Windows.Forms.RTF.RTF.GetToken () [0x00000]
at System.Windows.Forms.RTF.RTF.ReadFontTbl (System.Windows.Forms.RTF.RTF rtf) [0x00000]
at System.Windows.Forms.RTF.RTF.RouteToken () [0x00000]
at System.Windows.Forms.RTF.RTF.Read () [0x00000]
at System.Windows.Forms.RichTextBox.InsertRTFFromStream (System.IO.Stream data, Int32 cursor_x, Int32 cursor_y, System.Int32& to_x, System.Int32& to_y, System.Int32& chars) [0x00000]
at System.Windows.Forms.RichTextBox.InsertRTFFromStream (System.IO.Stream data, Int32 cursor_x, Int32 cursor_y) [0x00000]
at System.Windows.Forms.RichTextBox.set_Rtf (System.String value) [0x00000]
at Pololu.MaestroControlCenter.EditorTextBox.setRtf () [0x00000]
at Pololu.MaestroControlCenter.EditorTextBox.updateRtf () [0x00000]
at Pololu.MaestroControlCenter.EditorTextBox.OnTextChanged (System.EventArgs e) [0x00000]
at System.Windows.Forms.TextBoxBase.set_Text (System.String value) [0x00000]
at System.Windows.Forms.RichTextBox.set_Text (System.String value) [0x00000]
at Pololu.MaestroControlCenter.MainWindow.copyToScriptButton_Click (System.Object sender, System.EventArgs e) [0x00000]
at System.Windows.Forms.Control.OnClick (System.EventArgs e) [0x00000]
at System.Windows.Forms.Button.OnClick (System.EventArgs e) [0x00000]
at System.Windows.Forms.ButtonBase.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) [0x00000]
at System.Windows.Forms.Button.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) [0x00000]
at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.ButtonBase.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Button.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000]

Here are screenshots of everything I could think of as far as odd behavior:

The compiled code:

It WORKS! but could you explain something to me:
When I call this I figured I would be calling the numbers from the maestro interface.
IE min was 960 , max was 2352

But when I call this I get a whole new set of numbers ranging from 2000 upto 7k+.I don’t understand how these numbers correlate.

I tried a wal-wart I had laying around it was 6v but the controller did goofy things with it plugged in. I tried batteries and it has been rock solid since. The only issue I have now is the servos seem to do whatever they feel like doing when I turn the battery pack on, sometimes jamming the arm into the base until I call a sub I made called home… but the movement accuracy is excellent right now. I played with ALOT of R/C cars when I was a kid and never knew how accurate servos really were! I have a box of old parts and stuff so this is where the battery pack and switch came from. I’ve also got a few other older servos to tinker with but they are the other style Futaba plugs, I just need to buy a few pigtails. One other thing I have is my old electronic speed controller from my last Kyosho car. I’m assuming it would act as a servo and drive a motor as long as I have a battery pack connected to it?

I’m thinking I could maybe recreate the status panel in maestro at some level if I get this working properly.

whoowhee… THANK YOU for your time, I truly appreciate it.

Almost forgot for them Debian Squeeze folks including what was required in the docs I had to install the following to get UscCmd fromt he SDK to compile:

apt-get install mono-2.0* libmono-i18n1.0-cil libgamin0 libmono-winforms1.0-cil

didn’t require libmono-i18n1.0-cil libgamin0 libmono-winforms1.0-cil but apt suggested them, I just installed all of 2.0 for good measure.

apt-get install mono-gmcs

Hello again and thanks for the detailed bug report. I think you are just encountering this bug about saved sequences under linux that I mentioned before - can you try deleting all of your sequences before you click “Apply” and see if that makes it work?

The numbers in the script have to be integers, so you use units of 0.25 us there. That means the neutral position of 1500.0 us is instead written as 6000.

Your ESC will probably work with the Maestro just fine. Of course, you should make sure not to short multiple supplies together - if it has BEC capability, you need either use that to power your servos or make sure it is off/disconnected.


The winforms mono library is definitely needed; it powers the whole GUI. We developed the Linux versions of the Maestro software under Linux using libmono-winforms2.0-cil, and in the documentation we recommend that people install that version, but you installed version 1.0. I recommend uninstalling version 1.0 and installing version 2.0 to see if that helps.


Thanks for the input:

first… I’ll try the winforms 2.0 out this week

second… I just spent all day working up a killer setup with the boost I got on this thread… That little chunk of code and where to put it set me in a good direction… muchos gracias :smiley:

I’m not going to get into details but I created an Ajax-ish interface that has sliders for each of the servers and a short slider for each servo speed. now I can set the speed and slide to where I want it… very cool. My setup can also move all of the servos simultaneously, change directions mid-move, and change speed while a servo is moving. :wink:

Here’s a screeshot of the interface:

I’m wondering, is there a place I can see these built-in commands (API?) such as:


wondering what kinds of different status are involved here and what they mean

setScriptDone(usc, 1);

Just interested in looking at what I can do now that I have some headway. I thought I seen this somewhere but I can’t seem to find it again.


Sure, all of those functions are in Usc.cs and are documented with comments. Within the Visual Studio editor you can probably just type “usc.” and the list of functions with documentation should pop up.


By the way, the functions you mentioned are actually in Program.cs, but they are basically just wrappers for the Usc.cs functions I was talking about.

Any chance I could get a link to a relay for sale that would work to control the power on and off to the servos? i’m sending 6v to them via 4AA batteries if that matters. I went looking for a 25Mah unit but fail to understand all the specifications in the electronics catalogs. thought I might find one on the site but I didn’t have any luck.



I don’t know of any relays that can switch many amps with a coil that can be driven straight from a microcontroller. You’ll have to drive the coil through a transistor, and once you’re doing that, the coil current won’t matter much, so the only requirement will be a 5V coil. You might even be able to power the coil from the servo battery so that it doesn’t waste power when the servo battery is disconnected (though you might prefer using USB power for the coil or you might have trouble with the relay turning on and off if your servo supply has a lot of glitches).

- Jan

excellent information, you guys rock!

Just wanted to share something here:

This is the next step … I have a Playstation 2 to USB controller adapter… I’m driving sheep around a screen right now tearing the code apart but I should be able to drive the arm with this thing from what I am seeing. It will be clunky at first but it will work…

After that the sky is the limit… :smiley: