jmpinit / p5.axidraw

A p5.js library for controlling the AxiDraw pen plotter.
https://jmpinit.github.io/p5.axidraw/
MIT License
23 stars 1 forks source link

AxiDraw SE/A1 with Brushless Servo Upgrade is not supported to control pen up/down #1

Open melaniehuang opened 11 months ago

melaniehuang commented 11 months ago

axi.moveTo() works great however the axi.penUp() and penDown() shows no response.

My hypothesis is that the SE/A1 with Brushless Servo upgrade requires a different configuration. See equivalent config additions here that were added to the Python library:

https://axidraw.com/doc/py_api/#api-changelog

v 3.8 (2023-01)
Added new [penlift](https://axidraw.com/doc/py_api/#penlift) option, to enable brushless servo option.
jmpinit commented 11 months ago

Thanks for trying it out!

I don't have a Brushless Servo Upgrade Kit to test with, but if you would be so kind as to help me test a solution then I think we can get it working.

I've made a test sketch here: https://editor.p5js.org/jmpinit/sketches/GsWZ7_OKC It's the servo-out example from this branch I just made: jmpinit.brushless-servo

If you click the sketch you should be able to connect the AxiDraw. Then if you click at different Y heights it should tell the AxiDraw to set the servo to different positions. It might only move a little bit but that's okay for the purposes of the test, as long as it moves at all. If that works then I should be able to add support for the brushless servo upgrade, but I'll ask your help again for testing it if you don't mind.

Notes for myself:

The brushless servo is connected to the third header from the bottom (as explained in the installation instructions). This is labeled "B2" and corresponds to pin RP5, so the pin index for the S2 command is 5.

melaniehuang commented 11 months ago

@jmpinit Thanks for looking into this! I can confirm it works with the top quarter of the sketch canvas.

const dutyCycle = constrain(map(mouseY, 0, height, 0, 0.25), 0, 2);

I changed the mapping so I could test with more fidelity and its working great!

benoitwimart commented 8 months ago

Hi, I have the A3 model with a brushless servo kit. The script https://editor.p5js.org/jmpinit/sketches/GsWZ7_OKC with this sketch https://raw.githubusercontent.com/jmpinit/p5.axidraw/main/examples/mouse-control/sketch.js works for movement, but the pencil doesn't move when I click, and it stays stuck at the top maximum position. Note: I am still a bit lost with npm, packages, and other things.

jmpinit commented 8 months ago

@benoitwimart does your brushless servo kit work correctly with the software from Evil Mad Scientist? Maybe it's running an older version of the firmware? Could you let me know what firmware version is installed? One way to do this is to use the AxiDraw CLI: https://axidraw.com/doc/cli_api/#version

benoitwimart commented 8 months ago

It's run with Inkscape and Saxi (with a fork for brushless), I think it's the last firmware (but I will check).

benoitwimart commented 8 months ago

I have this :

Your AxiDraw has firmware version 2.8.1. Your firmware is up to date; no updates are available.

In Chrome (not Firefox) https://editor.p5js.org/jmpinit/sketches/GsWZ7_OKC is OK but I need to setup Pen in inkscape after few click (maybe out of range ?)

Mouse-control sketch paste in this works for XY but not Z. (good news: webpack is running on my folder :)

jmpinit commented 8 months ago

@benoitwimart do you mean that the linked sketch does make the pen move, but only in Chrome and not in Firefox?

It would definitely be out of range with the default, because it is set to the maximum possible. You could try using the range that @melaniehuang found to work for the dutyCycle (0 to 0.25).

Just in case because you mentioned webpack - it should only be necessary to setup the JS build (yarn, webpack, etc.) if you are making changes to the source code of the library. If you just want to use it in a sketch then you can just include the p5.axidraw.js file from the latest release in your sketch. Or if you want to use this branch you could copy the p5.axidraw.js file that is part of the sketch linked above.

Someday maybe I'll get a brushless servo upgrade and then I can add proper support. For anyone else reading this - PRs are also welcome if you happen to have one and want to do it 🙏 .

benoitwimart commented 8 months ago

Firefox (Mac OS) can't connect to Axidraw with your extension (it's work with Saxi). Chrome (Mac OS) is OK for me.

Yes, webpack is running so I can build the code to do some tests. axi.penDown(); and axi.penUp(); is not support for brushless ? just dutyCycle ?

I make a short message on ems-chat discord :) Windell Oskay help me to hack Saxi for my brushless servo.

benoitwimart commented 8 months ago

For me it's OK with axi.servoOut(5, 0.9); to axi.servoOut(5, 2.0);

jmpinit commented 8 months ago

Great! To answer your question above - yes penDown and penUp do not support the brushless servo upgrade kit for now. The brushless servo is connected differently than the regular servo motor. The EBB control board in the AxiDraw provides a "Set Pen State" command which controls the regular servo motor, and that's what penUp and penDown are using currently in this library. The brushless servo gets connected to a spare servo port on the control board, so it must be controlled with a different command called "General RC Servo Output", which can emit the servo control signal on any available IO port.

I'll make it so that penUp and penDown issue both commands, use a best guess for the duty cycle value, and provide some way to adjust it.

One small note - a duty cycle value greater than 1 is not valid and should trigger an error. Melanie wasn't hitting that because her map statement would not produce a value greater than 1. Maybe you are in the same situation but I thought I'd mention it just for completeness / clarity.