- Joined
- Dec 18, 2019
- Messages
- 7,495
Well done! Glad to see you going at it. Don't think that the platform is limiting you at this point, so keep on going. Remember that on a lathe, with a chuck on it, (and the part) there's quite a bit of rotational inertia. What that means is the angular acceleration isn't that great. So the changes are not instantaneous. If your encoder (and platform) can keep up with smoothed changes, then you are golden.Tons of conversation, cool, the links are sweet!
I tested driving a spare stepper with an a4988. Worked as expected. Next, tested adding that simple "one step" code to the PIO micropython encoder reading example I got working earlier. Just in a naive 1 pulse = 1 step manner. Worked, but as expected with a 125MHZ clock running on one state machine to monitor the encoder, the encoder could be turned faster than the stepper could keep up with generating pulses 1:1, it seemed.
Again, just to get familiar since this is my first foray with PIO, I separated the encoder reading assembly into its own state machine, running at 125MHZ. I created a second SM at 125KHZ with a wait(1, irq, 1) to test limiting the max step rate of the stepper to something I had previously found reasonable. I substituted the pulse step gen from the encoder detector assembly with a raise IRQ 1, which the second PIO SM picked up on. One direction only. No specific microstepping selected/config'd.
Just for playing around and making sure I could get the requisite hardware doing something somewhat "sane," things seem to work well enough, video:
I had previously tested adding a variable delay to the simple stepper functionality test, to delay X cycles before a step is taken based on a value pushed into the register. This also seemed to work as expected, but I didn't test extensively. Next I'm going to try adding that to this version, to do a simple 1 : X integer ratio of real-time encoder pulses to stepper pulses. Micropython isn't doing anything aside from activating the state machines and setting initial values.
I'm happy to go through experimenting and realizing a few "wrong approaches" as long as I'm tinkering and interested. As to why not just use an esp32, I'm liking the straightforwardness of PIO stuff and just learning while having fun. It's great to know I could use one of the esp32s I have laying around (ESP32-CAMs, actually, which I managed to install an esp32 implementation of wireguard to a while back while retaining webcam server functionality, so it could join an external VPN which I could monitor remotely, but that's another topic)! I could also just as well spend time setting up the linuxcnc installation I have going on a spare computer and do some rudimentary ELS stuff with that, since I found a module there. Tbh it might be a better investment of time, given all the functionality built in. But definitely not the point or my interest this exact second, I'm just exploring and it's really great to see the same thing implemented on many different uCs. It opens things up to people that might only have what's on hand, gets people chatting and thinking, etc. I mean heck, when I saw that MOV EXEC was a function and could read pins or data and exec that from external sources, I was kinda excited that I could potentially use two cheap picos to do things in tandem for fun.
Regarding simplicity, it seems seems inexorable that people have widely different definitions of it. That's kinda fun, too. It definitely seems evident from the discussion of ELS and just thinking about what the implications are for timing and control isn't something that instantly resolves itself in my head. Like, there's an implication that if a x:x ratio of encoder to stepper pulses is performed, just that this loop is running at a given clock dictates a step speed. "Doing things" in time relates to a velocity, and the discussion around velocity/position/precision needed is interesting. I'm ignorant to all but the basics of lathe stuff anyhow, so my mental concept of "good and responsive enough, assuming one only has to compensate for slight spindle bogging down from tool pressure" versus "threads will have this amount of slop acceptable in control scheme until they are out of spec" is kinda nonexistent.
I'm happy to try to re-familiarize myself enough with C to implement things in C if it comes to that point. The jump table encoder implementation with error handling that is in C seems like it wouldn't be difficult to use with my current experiment in micropython, but that jump table version is running short on spare instruction space. Not sure what 1/X variable electronic gear ratio gets me at this point (if anything useful), since I haven't thought about gearing/pitch/etc yet.
As you found out, steppers won't start instantaneously at high rates of speed, but if they are following the load (the spindle) even from a dead stop to full speed they will and do come up to speed. Personally, I'd recommend a closed loop stepper, so if the stepper falls behind, it automatically catches up. I use a closed loop stepper and have had excellent results with it. I didn't use a stepper library with controlled acceleration at all. Heck, I used no library, just directly pulsed the stepper driver. I could get away with that because of the relatively high moment of inertia of the headstock and chuck. It wasn't naivete that lead me to this, but more the physics. If you look at what's in your system, you can often make good trade offs that dramatically reduce the system complexity and cost. Why over design when it isn't necessary?
A variable (really fixed) ratio on the stepper is often used to give you more torque to move the lead screw. There's no free lunch though, you have to spin the stepper faster to make up for the gear ratio. Most times, it is to your advantage. It may allow you to use a slightly smaller stepper. I sized my stepper for a 1:1 drive ratio (used a 4 Nm stepper) and it works fine on my 10 x 22.