I'm hoping to be able to make a program in MMF2, to control a number of servos, connected to a computer via USB and one of these devices: http://www.pololu.com/catalog/product/1350
I've looked through the documentation & files, and it includes the C# source code for a dll which is supposed to simplify the task (takes care of all the low-level stuff for you). I'm hoping that I will be able to use the CallDll extension with this dll.
The problem is, I haven't been able to figure out what functions I can call, what parameters they take, and perhaps even what they actually do.
I would be extremely grateful if any of the programmers out there could take a look at the files, and see if they can work it out.
Finally, this is a real long shot I know, but how much work would it be to create an MMF2 extension from this source code?
How much would I likely have to pay someone for them to do it?
EDIT: I'm only really interested in how to set the position of each servo - not all the stuff like setting speed/acceleration, or returning any data.
looks interesting. too bad i have no knowledge of C#.
if you have the sources, have you tried building the dll yourself? id assume you can use any classes and/or methods within the sources after calling the dll.
edit: as for the mmf extension, the sources are in C#, mmf extension development is in C++. not sure how that would work -_-
I suggest trauling through the C# code and getting it to work from the .Net extension. Oh, and that source doesn't compile without the assembly . It's difficult for someone to help you with this given the hardware requirements, and there's not much reason to do so given that this is very specific to your needs. Maybe someone with some time to kill will be able to help.
You're much better off searching a regular coding site. There's loads of them out there.
If it's C# you're doing, try a site designed to help people with C# problems.
I think there's maybe 6 or 7 people total, maybe less who can code in a regular language that actually post here at TDC.
There's probably 5 more maybe lurking in the shadows here at TDC, but yea, try a REAL programming site.
I'm not where I want to be when it comes to working with "fake" programming as of yet, and until I can make some decent games with this stuff, I'll leave the Real programming alone (other than scanning through some books once in awhile for logic ideas of course).
Wish I could help other than telling you to look elsewhere. It just seems to lack any real value. I mean after all, you've probably been asking at the Real programming sites too and found the people to be abrasive and slow to respond, am I right?
That's one thing I've always loved about TDC, even if you don't get the answer you're looking for, at least you get an answer.
The sad thing is that you'll probably need to go to 10 different forums and wait for 2 weeks or more before you get a satisfactory answer and on top of that, you'll need to register for each and every one. I hate what the internet has turned into. It could have been so much more.
Blood of the Ancient One, Seen only as Shadow, Faster than Lightning, Fierce as the Greatest Dragon, Nearly Invisible, Floating in a Dream, Entered through the Demon Door, Destroyer of Evil in a Realm with a Red Sky Scarred, Who could I be ?
Lol, this isn't exactly something you can just go up and ask anyone on the Internet about. It's like an assignment for 4th year electrical engineering/comp science degree or at least something where a bunch of straight A undergraduates gather around and build some junk.
I could probably look through it, but I'm too lazy to do it without a lot of incentive, seeing how I go to TDC to get away from this stuff
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.
I know absolutely nothing about C# (or any other kind of C for that matter), so I guess I underestimated how difficult this is (although the files are commented, and the manufacturer claim it's supposed to be really easy).
I'll try posting on a programming forum, and I'll ask the manufacturers if they can shed any light on the matter.
I may also post in the bidding pool section on the clickteam forums - I would be prepared to pay for an extension to handle this stuff.
I think I may be gettign somewhere...
Part of the source file "Usc.cs" looks like this:
public void setTarget(byte servo, ushort value)
{
try
{
controlTransfer(0x40, (byte)uscRequest.REQUEST_SET_TARGET, value, servo);
}
catch (Exception e)
{
throw new Exception("Failed to set target of servo " + servo + " to " + value + ".", e);
}
}
I hope this suggests that the compiled dll will have a function called "setTarget", which takes two parameters - a byte which specifies which of the 6 servos to control, and a ushort which specifies the target position of the servo.
Does that sound right?
There are other similar functions that appear to set the speed/acceleration/etc of specific servos too.
I'm sort of a programmer - have rarely used C# but I'm familiar with the basics of it. The difficulty I have here is figuring out exactly what you want to do and which functions you need. I've heard of a servo but I'm not sure exactly what one is - could you give a bit of an overview?
Regarding the setTarget method, it'd be a good idea to have a look and see what the controlTransfer method does - also maybe try and find what uscRequest is. I'll have a quick look for you and see if I can help you out.
To be honest, I've not worked much with DLLs or the DLL extension for MMF - but are you even sure you can call parameters to source code that has been compiled to a DLL file?
Notes for myself
- setTarget takes 2 arguments - byte servo, ushort value
- setTarget calls controlTransfer, otherwise fails with exception
- controlTransfer takes arguments (0x40, (byte)uscRequest.REQUEST_SET_TARGET, value, servo);
- 0x40 Hex = 64 dec = 100 oct = @ char (seems to be used for setting target, speed, acceleration .etc)
- uscRequest.REQUEST_SET_TARGET = 0x85 (from Usc_protocol.cs)
- Would guess the controlTransfer method sets up packet transfer?
Thanks a lot for your help Flava - I appreciate it
Originally Posted by Flava
To be honest, I've not worked much with DLLs or the DLL extension for MMF - but are you even sure you can call parameters to source code that has been compiled to a DLL file?
What do you mean? Why wouldn't I be able to?
The library is apparently included specifically for people who want to create their own programs, so I hope it will be possible.
I only linked to the part I thought I needed before, but the complete SDK is here: http://www.pololu.com/docs/0J41
It includes an example application as well as the library, and the "UsbWrapper" library (see below).
controlTransfer is apparently a function in the "UsbWrapper" library, which does the complicated low-level stuff.
It looks like this:
- <member name="Mololu.WinusbHelper.WinUsbDevice.controlTransfer(Pololu.WinusbHelper.WinUsbDevice.WINUSB_SETUP_PACKET,System.Byte[])">
<summary>Performs a control transfer with a data stage. Calling this function is slightly safer than calling controlTransfer(WINUSB_SETUP_PACKET, Byte *) because this function can verify that buffer is not null and that buffer is long enough.</summary>
<param name="buffer">If this is a Read transfer, this is the buffer that the data from the device will be read in to during the data stage. If this is a Write transfer, this is the buffer that will be written to the device during the data stage.</param>
<param name="setupPacket">The SETUP packet to send to the device.</param>
<returns>The number of bytes transferred in the data stage. This is usually equal to setupPacket.wLength.</returns>
</member>
It seems that "setTarget" is probably the main function I want to use. The problem is if I also need to call some kind of initialization/setup functions as well.
Oh yeah, and a servo is like a stepper motor, except for it can't rotate continuously (generally only about 180 degrees). It has the normal positive and negative wires to supply power, and then a third wire which tells it what angle to rotate to (connected to a radio control receiver, or in this case a USB servo controller).
Can you actually upload the dll? I imagine the dll is written in C or C++, the C# code you uploaded requires a reference to that dll, so I can't compile the C# code without it.
i just played around with the sdk. the first thing you linked to, "Usc" is part of the Maestro Toolset. it cant compile by itself. you have to compile from the maestro C# solution.
it produces
Sequencer.dll
UsbWrapper.dll
Usc.dll
MaestroExample.exe
and
UscCmd.exe
and includes an already compiled dll called
Bytecode.dll
if you want me to upload the everything compiled from source for you to figure out what to do with it i'll be more than happy to. but dont ask me how to use any of those though cause i have no idea how to program in C# as i have not learned it yet.
Thanks, but I've managed to compile everything already.
The problem is working out how to use it - there's no way to get a list of functions/parameters from a compiled dll (I tried depends.exe), so I supplied the source instead, hoping someone might be able to make sense of it.
I think I've got most of what I need figured out now, but like I said - I need to experiment once the unit actually arrives.
The actual servo controller should be arriving tomorrow or the next day.
If I get it working with MMF2 then of course I'll let everyone know how I did it (maybe write an article).
Is that what you're interested in, or just the bit about dlls?
Well, it arrived, but I'm having difficulty getting it to work.
I plugged in a 4.8V battery pack and servo (all wired up the correct way), and it just melted the servo before I even connected it to a computer
I am a retired clicker but I did do my degree in electronics and computer science and I worked as an embedded systems engineer for a while! Robotics is also one of my many hobbies, I am currently building a mini sumo robot and I have built a couple of micromices.
Anyhow from a very very brief read up on the board, it appears to offer a virtual COM port over USB. I have controlled embedded systems over USB from MMF2 using the Serial port object, it works very well!
The example application with it allows you to connect, send and receive. If it was me I would read up on the protocol and find the COM port the board is hiding on (device manager, it will probably come up something like Microchip CDC) and see if it responds to sending some commands.
You may need a bigger battery pack greater than 4.8V for PC less operation. If it is less than 5V and if it's a conventional regulator you will need greater than about 5.5 to 6V to beat the drop across the regulator - hence the microcontroller onboard would probably not be powered. 4.8 is fine for the motors, plugging in to USB should power up the micro as well as the motors.
Thanks for all the info - I'll look into that Arduino thing. It's cheap, which is nice
It's not actually for a robot as such - I just need to have 3 servos and 1 motor controlled by a laptop (so it pretty much has to be USB; bluetooth would be better but it's too expensive). It will be connected to the computer at all times.
I now have the controller working using the supplied software, so I at least know it's not broken, but no luck with the dll in MMF2. I'll look into using the serial connection, but the dll would have been better - don't suppose you have any ideas of how to get that working, do you?
Hi, I just had an quick peek through the source code and I think you should read the file: "Usc_protocol.cs" since that file defines the constants needed to communicate.
The file: "Usc.cs" holds the class which setups an object that represents the connection to the computer. Err well you probably figured this out yourself from the comments.
But it seems like this was setup to read, store and execute script files. So I would say: create a simple script file and figure out which functions are called from the class located in: "Usc.cs" because if the file: "UscSettings.cs" takes care from loading the settings and script(s?)
This function is "Usc.cs" loads the settings: "public void setUscSettings(UscSettings settings, bool newScript)"
And that's probably all I could do so far. Good luck with controlling your servo's. You could always control them by letting mmf create the little scripts for you and send it to the hardware. But it's some sort of intermediate solution.
Unfortunately I am in embedded programmer, I have dabbled in system programming (command line apps in C/C++ and a tiny bit of python) but Jenswa (Hi there fellow iklik-it dude , long time no see hope your well) and others in this thread I think have more experience on PC side than me. I work at the low levels close to hardware, so that's where I feel most comfortable .
I had a look at the Edwards protocol (http://www.seetron.com/ssc.htm) which the board also accepts. Its 3 bytes and is very simple!
Byte 1: Marker 0xFF (hex) or 255 in decimal (note this is not a sting of 255 but a single byte - one character)
Byte 2: Servo number from 0x00 to 0xFE (0 to 254)
Byte 3: Servo position from 0x00 to 0xFE (0 to 254 with 127 being centre)
I have modified the serial port example for MMF2 to send packets according to Edwards protocol, and I have emailed it you - it should get something working in a fashion if you can not figure the DLL approach out. Assuming Pololu are not fibbing about it being able to use either protocol, it should work. Find the com port the board is on, alter as necessary, then open the port (9600 baud should be fine). The little red indicator AO should go green if all is good!
Also note my example will only work from the second servo on and also you will lose one position increment at the one end. For testing just move the motor plug along the connector to the 2 nd position
This is due to a 0 character being a null terminator for strings. If this works you may be able to use the binary object (i.e. use 3 bytes and address them manually) then send a string from the binary object. I'm not sure about the serial object itself though, this maybe a limitation of using MMF - a null terminator is usually used to tell functions to stop reading characters (singular bytes) from this array (i.e. stop here no more data, unless you want to read out the end of the array and read god knows what ! ). As there is there no way to set the string length any other way I think that maybe a limitation.
Thank you very much for going to all that trouble to help me
Like you said, it does look like it ought to be quite simple using the serial object - but unfortunately, it doesn't seem to be working so far
Looking in Control Panel, the servo controller seems to use 2 COM ports:
Pololu Micro Maestro 6-Servo Controller Command Port (COM4)
Pololu Micro Maestro 6-Servo Controller TTL Port (COM5)
I've tried them both, but with no success.
I don't get an error message, and the circle goes green, but the servo just doesn't move.
I've tried plugging the servo into all the different channels.
I've also tried sending a "baud rate indication byte" as mentioned here: http://www.pololu.com/docs/0J40/5.c - don't really know what it's for, but I figured it was worth a try
If you have any other suggestions, feel free to let me know.
Otherwise, thanks again for the help you've already given me
At least I know who to give the servo controller to now, if I give up trying to make it work myself