Fake encoder index for simulation

More
13 Apr 2020 07:41 #163849 by mydani
Hi,

for G33, an encoder index is required. Any idea whether there is a hack already available for simulation?
If not, I guess some simple comp which, based on requested spindle speed, could fake an index signal.

Regards,
Daniel

Please Log in or Create an account to join the conversation.

More
13 Apr 2020 17:32 #163893 by cmorley
I'm pretty sure there is; the lathe simulated configs fake encoder indexing.

Please Log in or Create an account to join the conversation.

More
15 Apr 2020 07:27 - 15 Apr 2020 07:28 #164027 by mydani
Ah, thanks for the hint. Of course it's there.
For anyone searching, there's a comp sim_encoder.
loadrt sim_encoder names=sim_encoder_0
net spindle-phase-Z sim_encoder_0.phase-Z => encoder_0.phase-Z
# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_0.ppr 12
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_0.scale 60
# scale encoder output to read in revolutions (that way thread pitches can be straightforward, a 20 tpi thread would multiply the encoder output  by 1/20, etc)
setp encoder_0.position-scale 48
addf sim-encoder.update-speed servo-thread
addf sim-encoder.make-pulses    base-thread
Last edit: 15 Apr 2020 07:28 by mydani.

Please Log in or Create an account to join the conversation.

More
14 Oct 2021 13:08 #223082 by GM2012
I do not use HAL as CNC is just my hobby and do not want to spend time learning HAL. I usually find what I need, but this time having trouble with this sim-encoder.
Anyone actually tested sim-encoder? Above posted code actually doesn't work. There is a sim_encoder_0 but also there is encoder_0. I could add line:

loadrt encoder names=encoder_0
and it 'works'.
I am not sure if simulated encoder can be used to replace a real encoder?
I have a small cnc lathe where I want to run spindle with external stepper (for threading). Lathe is custom build with Sherline head. As steppers (normally) do not have encoders why we cannot have a spindle run with a stepper without an encoder? We can assume that spindle will spin with constant RPM as we use stepper.
When I try threading with G76 .. gettting message "spindle not turning in G76".
I don't know if it is possible to display simulated spindle RPM in GUI? In HAL configuration I can only see sim-encoder.make-pulses and sim-encoder.update-speed changing in "watch".
In this simulated encoder I don't see something that would simulate spindle is turning.
Any help is appreciated.

Please Log in or Create an account to join the conversation.

More
14 Oct 2021 16:09 #223095 by andypugh
sim_encoder actually simulates an encoder, not an encoder counter.
linuxcnc.org/docs/2.8/html/man/man9/sim_encoder.9.html

ie it takes a velocity as input and outputs A,B,Z pulses.

The partial example you are copying only indicates how the sim-encoder has been hooked up to an already-existing encoder counter (encoder.0) for simulation.

To thread with a stepper motor spindle, and with no actual encoder, I would suggest a custom HAL component. It would need to take index-enable and stepgen rawcounts as input, and would output position and reset the index-enable.

I can write it for you, but you need to be willing to learn enough HAL to make use of it...
The following user(s) said Thank You: GM2012

Please Log in or Create an account to join the conversation.

More
16 Oct 2021 00:07 - 16 Oct 2021 00:16 #223262 by GM2012
I was able to install, use and understand Logitech "pendant". Problem is that I forget HAL as I don't use it often but can understand most of it. Any help in this direction is appreciated. I can really buy an encoder with two pulleys and install it and I know it will work. Just being cheap :). I do not cut threads to often. Have Sherline spindle thread attachment but it is hard to use in my opinion.
Meantime .. I've got an idea (and I am sure it is possible), to run my Spindle with 1rotation/sec, then run X-axis with properly calculated speed to cut thread with a simple g-code. Trying to find an answer how I can move X-axis and A-axis with a different feed rates at the same time. So far no luck, but maybe I'll find out.
And forgot to add .. small CNC lathe (for G-code 'idea') is connected to my-mill, X axis and spindle to A-axis.
Last edit: 16 Oct 2021 00:16 by GM2012.

Please Log in or Create an account to join the conversation.

More
18 Oct 2021 23:21 - 09 Jun 2023 13:07 #223508 by andypugh
Save the following as "stepperspindle.comp" and compile / install it with
sudo halcompile --install stepperspindle.comp

in the HAL file
loadrt stepperspindle
...
addf stepperspindle.0 servo-thread
...
net spindle-counts stepgen.2.rawcounts stepperspindle.0.rawcounts
net spindle-index-enable spindle.0.index-enable stepperspindle.0.index-enable
net spindle-pos stepperspindle.0.revs spindle.0.revs
setp stepperspindle.0.steps-per-rev 1600

Here is the component:
component stepperspindle "Allow threading with stepper spondle and no encoder";

pin in signed rawcounts "connect to the stepgen rawcounts pin";
pin io bit index-enable "connect to index-enable";
pin out float spindle-revs "connect to spindle.0.revs";
param rw signed steps-per-rev = 100 "stepper steps per rev / per index";

license "GPL";
author "andypugh";

function _;
;;

FUNCTION(_){
static rtapi_s64 counts;
static rtapi_s64 offset;
static int last_counts;
static int last_index;

// Handle rawcounts wrapping
counts += rawcounts - last_counts;
last_counts = rawcounts;

// handle index-enable
if (index_enable){
if (! last_index){ // new index-enable
offset = counts - (counts % steps_per_rev) + steps_per_rev;
} else if (counts > offset){ // passed virtual index
offset = counts - (counts % steps_per_rev);
index_enable = 0;
}
}
last_index = index_enable;

// calculate position
spindle_revs = (counts - offset)/ (float)steps_per_rev;
}
Last edit: 09 Jun 2023 13:07 by andypugh.
The following user(s) said Thank You: GaryLa

Please Log in or Create an account to join the conversation.

More
19 Oct 2021 18:20 #223587 by GM2012
Andy, didn't have time yet to implement and check but thank you so much!

Please Log in or Create an account to join the conversation.

More
17 Mar 2023 12:27 - 18 Mar 2023 14:54 #266910 by GaryLa
Thanks for the well-written example.

For those who might use this with a MESA board, change stepgen "rawcounts" to hostmot2's "counts"

So instead of:
net spindle-counts stepgen.2.rawcounts stepperspindle.0.rawcounts

use:
net spindle-counts hm2_7i96s.0.stepgen.00.counts stepperspindle.0.rawcounts

Also, I commented out the below PNCCONF code because it conflicted with the example andy gave:
#net spindle-revs => spindle.0.revs #already used above

From the example:
net spindle-pos stepperspindle.0.spindle-revs spindle.0.revs

Also, hostmot2 exports as 2-digit numbering:

stepgen.00.counts, versus stepgen.0.rawcounts although it may still work as single-digit, I didn't try it.
Last edit: 18 Mar 2023 14:54 by GaryLa. Reason: updated

Please Log in or Create an account to join the conversation.

More
20 Mar 2023 21:12 #267186 by drummond
What a great set of posts!

Thanks to everyone that posted, but particularly Andy for putting together that component and GaryLa for expanding the idea to mesa card users.

The search facility on this forum doesn't work as well as it could so I've come to the conclusion that bookmarking threads like these is the best way to go.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

Time to create page: 0.178 seconds
Powered by Kunena Forum