techninja / cncserver

A RESTful API server for driving serial based CNC devices
133 stars 39 forks source link

Other Bot Support: operating three servos #47

Closed MakerBlock closed 10 years ago

MakerBlock commented 10 years ago

Pretty please, could you create a way to control three servos (XYZ) with CNCSERVER? It would be great to have a pause for pen swapping too. Thank you!

techninja commented 10 years ago

Sure thing! First some requirements for bot support:

Serial Interface:

I'm guessing there's an Arduino program/firmware that opens the serial port for writing (at what baud rate? 9600 is common). How do we talk to it?

XY Position

There's two ways to send positional commands, absolute, and relative. The EBB moves steppers and is therefore forever relative, but since the mini draw bot is driven by servos, they're always absolute. The way CNCserver actually takes absolute positional commands is with a percentage, 0 to 100 (with floats for precision).

Maybe if you wanted to avoid decoding decimals byte for byte over serial, you could decide on some maximum resolution for the bot (maybe 1000 positions or about 333 PPI), and allow a command like M250,1000,2000, which would move the X servo to 1/4 of 180 degrees [250/1000 * 180], and the Y servo to full 180 [1000/1000 * 180], and make sure to do it over 2 seconds [2000 ms], which would require the firmware to work out the amount of time to wait between each sub-movement and break it up. Speed is probably optional as servos do pretty good when you just set them to go to a position, and get pretty jittery when you tell them to wait between small movements, though I guess it all depends on how you do it.

Z Position

Same deal as before, though 0 to 100 would probably be enough, as the 99% use case is going to be lifting and dropping: Z80,0 would lift (or drop?) the servo to 80% of 180, and 0 here is the speed (fast as you can!). Probably not even needed, but I guess for some stuff it might be good to be able to slow it down? Doubt it.

Firmware Response

This is basically an API. You need to be able to throw out the garbage, and let operators know if they're commands were any good. Once a command has been parsed (and we know it's the end of the command because of a carriage return or other char), and everything looks good, it should be stuck in a short buffer (EBB firmware only has two: the command that's running, and the one that's next), and a serial reply should be given. The EBB returns "OK", or an error of some kind. This isn't very verbose, or terribly useful, but it's the bare minimum.

Extras

Pen changes are nice, but... wouldn't it be awesome if we could alert the user when it's time? Maybe add an alert feature so it can play a song via buzzer or speaker, something like A1 would be sufficient, and the firmware would decide what the alert tone would be for each number. Perhaps a tone for "Change my pen!" and then another for "All done!".


Once all this is figured out, then I can begin adding the functionality. And I'd love to help with the firmware if needed, though without a little bot in my hand it will be a little tough. Can't wait!

:rocket: :neckbeard: :rocket:

EmbeddedMan commented 10 years ago

Note that the current EBB firmware does support up to 8 RC servo outputs using the "S2" command, if one ever wanted to add support for these types of things in the higher level software, they could be made to do fun things . . . .

*Brian

On Fri, Dec 20, 2013 at 12:15 AM, James T notifications@github.com wrote:

Sure thing! First some requirements for bot support: Serial Interface:

I'm guessing there's an Arduino program/firmware that opens the serial port for writing (at what baud rate? 9600 is common). How do we talk to it? XY Position

There's two ways to send positional commands, absolute, and relative. The EBB moves steppers and is therefore forever relative, but since the mini draw bot is driven by servos, they're always absolute. The way CNCserver actually takes absolute positional commands is with a percentage, 0 to 100 (with floats for precision).

Maybe if you wanted to avoid decoding decimals byte for byte over serial, you could decide on some maximum resolution for the bot (maybe 1000 positions or about 333 PPI), and allow a command like M250,1000,2000, which would move the X servo to 1/4 of 180 degrees [250/1000 * 180], and the Y servo to full 180 [1000/1000 * 180], and make sure to do it over 2 seconds [2000 ms], which would require the firmware to work out the amount of time to wait between each sub-movement and break it up. Speed is probably optional as servos do pretty good when you just set them to go to a position, and get pretty jittery when you tell them to wait between small movements, though I guess it all depends on how you do it. Z Position

Same deal as before, though 0 to 100 would probably be enough, as the 99% use case is going to be lifting and dropping: Z80,0 would lift (or drop?) the servo to 80% of 180, and 0 here is the speed (fast as you can!). Probably not even needed, but I guess for some stuff it might be good to be able to slow it down? Doubt it. Firmware Response

This is basically an API. You need to be able to throw out the garbage, and let operators know if they're commands were any good. Once a command has been parsed (and we know it's the end of the command because of a carriage return or other char), and everything looks good, it should be stuck in a short buffer (EBB firmware only has two: the command that's running, and the one that's next), and a serial reply should be given. The EBB returns "OK", or an error of some kind. This isn't very verbose, or terribly useful, but it's the bare minimum. Extras

Pen changes are nice, but... wouldn't it be awesome if we could alert the user when it's time? Maybe add an alert feature so it can play a song via buzzer or speaker, something like A1 would be sufficient, and the firmware would decide what the alert tone would be for each number. Perhaps

a tone for "Change my pen!" and then another for "All done!".

Once all this is figured out, then I can begin adding the functionality. And I'd love to help with the firmware if needed, though without a little bot in my hand it will be a little tough. Can't wait!

[image: :rocket:][image: :neckbeard:][image: :rocket:]

— Reply to this email directly or view it on GitHubhttps://github.com/techninja/cncserver/issues/47#issuecomment-30990982 .

techninja commented 10 years ago

Alrighty! Above commits could maybe possibly be enough to make CNC Server work for the proposed imaginary firmware I suggested in my above comment. Notes/Questions:

techninja commented 10 years ago

Configuration stuck in bot support branch and technically working, re-open this issue to confirm usage (and naming) to get into master.