Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1] 2
Author Topic: Lightweight Control Server
krummrey
Advanced
Posts: 66
Permalink
Post Lightweight Control Server
on: January 7, 2016, 13:56
Quote

I was wondering if anyone has written a light weight controller app for the Polargraph that would be able to run on a Raspberry Pi. My Laptop is tied up for hours while it is sending simple commands over USB. And while Processing now runs on Raspis the current controller is a little too heavy for the little computer.
So I was thinking if it would be possible to have a little print server like app running on the Raspi that will accept gcode from the Controller and then sends it command by command to the Polargraph.
What would it take to get that going?
My programming skills are very limited but I'd be willing to give it a try...

kongorilla
Pro
Posts: 389
Permalink
Post Re: Lightweight Control Server
on: January 7, 2016, 17:00
Quote

This isn't what you're asking for, but:

For my plotters that use gcode and GRBL shields, (so, not my Polargraph based projects) I've been using GRBLWeb on Raspberry Pis with wifi dongles. I've got one plotter with a very old RP1 that's been handling the job fine.

http://xyzbots.com/grblweb.html

That probably doesn't help you if you want a Sandy Noble Polargraphโ„ข system running. My programming skills are undoubtedly less than yours, and I have no idea how difficult it would be to make something like GRBLWeb communicate in Polargraph codes. Perhaps it's something you could take a look at, though.

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 7, 2016, 23:33
Quote

Kong that looks proper neat. I wish I wasn't such a javascript dunce or I'd just fork that. It's pretty much what I want out of the new Polargraph controller software.

In the meantime I knocked up this

https://gist.github.com/euphy/75366a70346689190bb5

which is a little python script that reads the contents of a command queue file, and sends the lines one by one to a Polargraph machine. It'll work fine on a pi, which is all already python'ed up.

Only python package required is pyserial:
    pip install pyserial
Use this wee script to send a command queue to a Polargraph machine.
If the filename is "mycommandqueue.txt" and the machine is connected on COM7, then do:
    python send.py mycommandqueue.txt COM7
    

Perhaps that's useful (tested in python 2.7).

Just updated https://github.com/euphy/polargraph/wiki/Standalone-command-queue-runner
sn

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 9, 2016, 14:48
Quote

So I got it running for the first time. Turns out that the Arduino needed it's own power. The Raspi wasn't able to drive it over USB.
The UNO mounts as /dev/ttyACM0

Connected successfully to /dev/ttyACM0 (<module 'serial' from '/usr/lib/python2.7/dist-packages/serial/__init__.pyc'>).
received: ?POLARGRAPH ON!
received: Hardware: 1
received: MC_UNO
received: Loaded width:732
received: Loaded height:884
received: Loaded mmPerRev:82.00
received: Loaded steps per rev:400
received: Loaded step multiplier:1
received: Loaded down pos:105
received: Loaded up pos:130
received: Recalc mmPerStep (0.20), stepsPerMM (4.88)
received: Recalc pageWidth in steps (3570)
received: Recalc pageHeight in steps (4312)
received: READY
Command 1/61132: C14,END (0%)
received: Basic Command executed.
received: READY
Ran 1 commands in 2.39 seconds: at 2.39 seconds per command, we'll finish in 16:29:58)
Command 2/61132: C17,3700,2810,2,END (0%)
received: maxLength: 5598
received: SYNC,3700,2810,END
received: Basic Command executed.
received: READY
...

How do I "home" it?
And how do I tell it what paper size I have and where it is located?
It is moving now, but not where I thought it should be.

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 9, 2016, 14:57
Quote

Aha right, that's good. I would expect to use the controller app interactively, to do your setup, and send your machine spec. The machine remembers it's own size, motor settings and pen lift positions between resets.

The machine does not remember it's pen tip width, or it's position between resets, so you need to build your command queue with those things in.

My exported command queues are always start with something like:

set motor speed
set motor acceleration
set pen width
set home position
<then the rest of the actual artwork>

Every drawing session must begin with a "set home".

Basically the same stuff you'd have to do interactively. Just don't connect the machine while you're building your queue, and then export it all. It doesn't need to know where your paper is, just where the pen is (set home), and where it should draw to (all the rest of your lines).

I haven't totally tested that script in a real-world scenario, so YMMV!

sn

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 9, 2016, 15:21
Quote

So I recorded all the gcode that I use to set up my Polargraph and played it back. It works! ๐Ÿ™‚ I just have to prepend that to the drawing code.
Still having issues with my power to the Raspi. Whenever the servo moves the connection gets lost. When I have it powered by my Macbook it is stable. That setup doesn't free up my Laptop then. ๐Ÿ˜‰
So off to look out for a beefy USB power plug...

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 9, 2016, 15:31
Quote

Ah that rings a bell. I don't know if a bigger PSU for the pi will help.

I forget which motorshield you're using - I remember the AFMSv1 has a jumper to allow the motor's PSU to also power the attached arduino.

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 10, 2016, 14:06
Quote

Just to test things out I have a power supply for the shield and the Arduino. Even then the Raspi stalls when the servo goes off.
I found a new problem though. The settings stored on the Arduino don't match up. When I dug into it I found out that the settings are off in the Controller now too. Whenever I upload the settings and retrieve them back I get different settings back.
Could my EPROM be broken? How can I find out where things go wrong? Compile the firmware with my settings hardcoded into it?

Image

Using FIRMWARE_VERSION_NO = "1.2.1"

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 10, 2016, 23:08
Quote

EEPROM _does_ have a lifespan in terms of the number of write cycles it takes, but it's 10,000 or so, I don't think that's the issue. If it was corrupted, you'd be getting more oddly changed numbers too, rather than just proportionally diminished.

One thing to know is that only machine width and machine height are actually stored in the arduino - all the rest are used exclusively by the controller.

However, I noticed that your mm per rev had changed, and tried that: bingo. Upload 700mm wide machine with 95 mm per rev, then change to 94 mm per rev, then the machine width is pushed down to 693.

I don't know if this is the effect that you're seeing exactly, but I can confirm that mmPerRev and stepsPerRev are kind of "master number" that all the other ones depend on. Internally in the polargraph, the machine width is expressed in steps, but converted to mm when downloading the spec.

So when you change the physical size of the steps by changing the mmPerRev, you change the physical size of the machine - it doesn't recalculate the machine width.

To be honest, this has never been a problem, because mmPerRev and stepsPerRev have always been very static, fixed values. This is probably the first time that those values have been modified other than during an initial setup. If this is the same problem you're seeing, I'd recommend doing your machine spec uploads in two stages - first change the mmPerRev and/or stepsPerRev, then do it again to make sure the machine width and height is properly set.

Also worth mentioning that it's best to change those two values by editing the properties.txt file, rather than by using the UI. I'm sure you've already noticed it tends to mess the other measurements up.

I'll have a think about the best way to fix this.

sn

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 11, 2016, 17:45
Quote

It gets even stranger. When I read out the values with the Arduino monitor the are correct, the controller messes things up. I wouldn't mind if the pen wouldn't end up where it shouldn't. I've measured everything twice now, after I have converted to fishing lines. I'll try to play with the values until it kinda works out.

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 11, 2016, 21:48
Quote

Krummrey do you use the "save as" and "load" features in the controller to work with multiple properties files?

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 11, 2016, 23:20
Quote

Yes for different paper sizes.They all share the same machine settings though.

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 12, 2016, 23:06
Quote

I've never like those features, and I know there's something wrong with how they work. I admit I use default.properties.txt exclusively. I'll try to have a look into what it's beef is.

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 13, 2016, 11:02
Quote

Thanks for all the effort you're putting into this project. I really appreciate it.

Coming back to the original idea of having a light weight controller for drawing svgs/gcode. I do all the vector work in Illustrator and save them as SVGs. If I were to use a dokument size of my machine and place and scale the lines there, there is no need to do the same in the controller. The cartesian coordinates are already there.
A light weight controller would only have to transcode the cartesian x-y coordinates to the "polar" a-b coordinates and send them to the machine. All it needs to know is the machine specs (saved in the eprom) and that the pen is in it's home position, right?

A worklow I had in mind would look like this:

  • Create a workspace in Illustrator/inkscape the size of your machine
  • Place and scale all elements in Illustrator/inkscape
  • Export as SVG
  • Import the SVG into the controller
  • SVG is being parsed, beziers are converted to lines (arcs?)
  • Path is optimized for travel distances (optional)
  • XY cartesian coordinates are converted to AB polar coordinates
  • Pen is placed on on the machine to the home position by the user
  • Gcode is generated and exported to the machine or Raspi-draw-server

All that wouldn't really require a GUI as all the placements are done in Illustrator.
Only a machine setup would have to be done previously.
Being really optimistic, all of that might fit into an Illustrator/inkscape script so that you could draw right from either of those applications.;)
Inkscape already has a path reordering script.

Am I missing something in this concept? Seems that a workflow like that would be way simpler for anything that doesn't use the raster image functions of the polargraph.
All of the pieces are there, I just can't judge how hard it would be to reassemble them into something like that.

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 14, 2016, 08:10
Quote

Krummrey I don't think you are missing anything, that's a really good, very achievable spec. I think you're right to be optimistic too, there's nothing tricky in there.

Simplest interface to this I think would be:

build_queue <svg input filename> <steps per rev (default 200)>

It takes the machine size from the SVG.

All new stuff is python, so would need a way to parse and segment SVGs - https://github.com/cjlano/svg looks good at first glance.

I'd suggest for the preamble commands (set home, speed etc), then that's just a template file (before_start.txt) and there's an ending one too.

sn

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 14, 2016, 11:47
Quote

Hm... so I found this Primer on Beziers. But again I have no idea how I could turn any of it into code. Bezier.js looks promising as a starting point for an Illustrator script.
Do I wish I had paid more attention in math when I was in school... ๐Ÿ˜‰

Do I get that right, you're moving away from Processing to Python?

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 14, 2016, 19:19
Quote

I'm very much out of love with Processing, it's not suitable for an app the size and complexity of the Polargraph controller just because of the awful IDE and weird build process.

The recent experiences with the prebuilt binaries are turning me right off too, that's a real problem.

The python build and distribute process is not trivial, and less well established on Windows. But on the other hand, developing with Python is nice, whereas developing with Java doesn't make me happy at all.

A better solution would be an entirely javascript based client, like the xyzbots thing. I like that, but my modern javascript skills are pretty weak.

Octoprint is similar to the thing I'm thinking will replace the app.

sn

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 18, 2016, 17:02
Quote

So it'll be web based but not running on a LAMP stack. More likely in python or node.js? Sounds great to me. I will not ask when that will see the light of day... ๐Ÿ˜‰

sandy
Administrator
Posts: 1449
Permalink
Post Re: Lightweight Control Server
on: January 18, 2016, 21:29
Quote

Exactly. The polarweb project (or Octoprint) uses a web library called flask that runs as a web server, and you just start it up, and open a browser to localhost:5000.

Having things presented through a browser presents a bit of a challenge for interactivity, but it's not insurmountable, and Polargraph doesn't need that much anyway.

Installation is the sticking point with Python. It's great on linux but a bit unexpected on Windows.

krummrey
Advanced
Posts: 66
Permalink
Post Re: Lightweight Control Server
on: January 20, 2016, 13:48
Quote

Meanwhile we have the send.py script to work with. I've added a notification with IFTT that will send a push notification on my phone when it's done drawing.
It's just a few lines of code for those wanting to have it:

import requests
    def close(self):
        print "Finished sending {:d} commands in {:0.2f}".format(self.total_lines, time.time() - self.time_started)

#       http://docs.python-requests.org/en/latest/user/quickstart/#passing-parameters-in-urls
#       curl -X POST -H "Content-Type: application/json" -d '{"value1":"File","value2":"Rows","value3":"Time"}' https://maker.ifttt.com/trigger/{your trigger name}/with/key/{your key}

        m, s = divmod(time.time() - self.time_started, 60)
        h, m = divmod(m, 60)
        d, h = divmod(h, 24)

        url = 'https://maker.ifttt.com/trigger/{your trigger name}/with/key/{your key}'
        payload = {'value1': sys.argv[1], 'value2': self.total_lines, 'value3': "{:02d}:{:02d}:{:02d}".format(int(h), int(m), int(s))}
        r = requests.post(url, json=payload)
        print(r.text)

        self.file.close()

Image

Pages: [1] 2
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.032 seconds.