Fake encoder index for simulation

More
5 years 1 week ago - 3 years 4 months ago #223508 by andypugh
Save the following as "stepperspindle.comp" and compile / install it with
Code:
sudo halcompile --install stepperspindle.comp

in the HAL file
Code:
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:
Code:
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: 3 years 4 months ago by andypugh.
The following user(s) said Thank You: GaryLa

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

More
5 years 1 week ago #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
3 years 7 months ago - 3 years 7 months ago #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:
Code:
net spindle-counts stepgen.2.rawcounts stepperspindle.0.rawcounts

use:
Code:
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:
Code:
#net spindle-revs => spindle.0.revs #already used above

From the example:
Code:
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: 3 years 7 months ago by GaryLa. Reason: updated

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

More
3 years 7 months ago #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.

More
3 years 4 months ago #273218 by drummond
I got around to trying this, with little hope for success because I'm currently running the lathe spindle with a stepper motor in velocity mode and I wasn't sure how I might integrate stepperspindle.

I'm using 2.8.4 on an RPI4 with 7C81

It was an interesting exercise getting Halcompile to work, but I learned that raspbian responds to a right click on a file with a menu that includes "copy path(s)", click on that and you can paste the complete path into a terminal.

Once I had the comp file compiled and installed, I added the HAL entries as originally shown along with the amendments suggested by GaryLa

I loaded linuxcnc from a terminal (it's easier to find errors this way)  it didn't finish loading but:

./turner.hal:207: Pin 'stepperspindle.0.revs' does not exist

line 207 read: net spindle-pos stepperspindle.0.revs motion.spindle.0.revs
commenting it out resulted in linuxcnc loading without error.

a look at halshow pins under stepperspindle then 0 showed no pin with that name, but there was a very similar stepperspindle.0.spindle-revs and subbing this in resulted in that error going away, but

./turner.hal:207: Pin 'motion.spindle.0.revs' does not exist

Rinse and repeat finds we just need spindle.0.revs without the 'motion'

Now it loads without error.

Does it work, well that's a story for another day

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

More
3 years 4 months ago - 3 years 4 months ago #273220 by PCW
Note that you can use index with step/dir driven spindles
with LinuxCNC 2.9 and Mesa cards with the correct firmware.
This allows spindle synchronized moves without an encoder,
though an index input is still required.

 
Last edit: 3 years 4 months ago by PCW. Reason: clarify

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

Time to create page: 0.061 seconds
Powered by Kunena Forum