Home designed and built 5C CNC lathe with ATC and C_Axis

More
02 Apr 2021 12:35 #204491 by andypugh

I cannot grasp how the signal, pins, etc integrate and till I manage that, there is no way I could read or change a HAL file without simply hacking.


Let me try a high-level overview.

To a large extent the HAL file is a way to map the values that come out of the motion module to physical pins on the interface and a way for physical pin values to be interpreted by the motion module. [1]

Consider the X axis on a stepper system.
First the HAL file will load the motion module. On being loaded the module sets up a lot of internal connections and configures itself by reading values from the INI file.
loadrt motmod ...{config options}...
The important pin here is (typically) joint.0.motor-pos-cmd. This is a double-precision floating point number.
The HAL file needs to create a signal to refer to this value by. We will choose to call it "this-is-my-X" to stress that the signal names can be anything.
net this-is-my-X joint.0.motor-pos-cmd
If we want, we can add an arrow for human readers. But LinuxCNC pays no attention to them.
net this-is-my-X <= joint.0.motor-pos-cmd
We need a pair of digital step/dir outputs rather than a floating point number. This is what the stepgen components do. I say "components" as there are a few of them. There is a software one for parallel ports, and integrated ones for Mesa, Pico, Pluto etc.
The Mesa / Pluto / Pico output the physical pulses on pins that are defined by their internal firmware. So here we will use the software stepgen as the example. Note that the output of the software stepgen does not _have_ to go to the parallel port. That is one of the strengths of HAL. You could set up a quadrature stepgen to drive an encoder counter. I don't know why you would want to, but you could.
So, we load a stepgen . Actually we will load 4, 3 in position mode and one in velocity mode.
loadrt stepgen ctrl_type=p,p,p,v
And connect the motor position command to the appropriate pin..
net this-is-my-X  => stepgen.0.position-cmd

We would then use further "net" commands to wire the bit-type step/dir signals to appropriate IO
net this-is-my-X-step stepgen.0.step => parport.0.pin-00-out

And, that, is basically, all that HAL does. It takes numerical or logical values, optionally converts them to other types of values, and transfers them to other moduels, and eventually out into the real world.

I don't know if this was any help. I just took a guess at where the conceptual block might be.

I recommend skimming through all the HAL modules listed here:
linuxcnc.org/docs/2.8/html/
under the headings "Commands and userspace components" and "Realtime components and kernel modules". Just to get a feel for the sorts of signal manpulations that HAL can do.

[1]This is the typical situation. The motion module is not always loaded, and there is not always any physical interface, but those are special cases.
The following user(s) said Thank You: Clive S, besriworld, johnmc1, NoJo

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

More
02 Apr 2021 13:08 #204495 by Clive S
Extremely well put Andy. Thankyou

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

More
03 Apr 2021 05:07 #204591 by NoJo
Thanks Andy - There are many of you willing to help, so I won't give up!

Regards
Joe

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

More
04 Apr 2021 13:12 #204760 by NoJo
Reading a lot...Learning slowly, but learning!

Andy, I have some 'practical' questions regarding functions I wish to implement and am not sure if this is the better place to ask - I will ask here, but if inappropriate will start a new post else where.
Firstly, I have read as many posts as I could find on both subjects below, but have not found definitive direction for a solution.


I need to implement some form of spindle motor deceleration before stop on M command. The motor as I explained is a 2KW plus stepper - it is internally closed loop ( encoder, etc), can spin @ 2500rpm, 40NM torque, etc.
When spinning with the lathe inertial masses ( chuck, etc) and coming to an immediate halt, bad things happen! I have found a number of posts on this subject, but all refer to not disabling the motor enable signal when giving the stop command. I tried to simulate this manually - disconnected the enable from the MESA 7i76 and enabled permanently - ground to enable. Then run my Gcode file, spindle @ 500RPM, and then M02. Spindle slams to a halt - which stands to reason, as the motor is enabled and step pulses cease so motion ceases as fast as possible.
I then set the spindle @ 500RPM again, enable active, and then set enable inactive ( remove the connection to ground manually)
The motor slams to a halt again - The motor can be rotated by hand when stopped, with enable inactive, same as when the motor is just turned on, but not enabled - it can be rotated, but is stiff. The motor still 'slams' to a halt in this test due to the re-generation effect in the motor creating a powerful magnetic brake. At 1000rpm, removing the enable, the motor comes to a standstill within 1-1/2 to max 2 revolutions!

So, playing with enables won't work - I need to actually decelerate the motor with decreasing step pulse frequency.
I also tried using 'spindle at speed' modes - and set the speed in the Gcode file to slower speeds, expecting L_CNC to wait till the spindle speed is achieved before the next speed command - did not - ran through the Sxxx commands in one shot..
The wait till speed reached works in the cnc file - the next G0 or G1 commands seem to pause till preceding spindle speed commands are achieved.

The second is a bigger project...To implement a C axis with the same Spindle Stepper motor.
Again, I have read all I could find, but the poster knew far more than me each time, and was able to glean solutions from replies that I am unable to understand!

Thank you for any help!
Joe

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

More
04 Apr 2021 13:28 - 04 Apr 2021 13:31 #204762 by PCW
In this type of situation you would typically limit the spindle speed rate of change
with VFD programming but since you are using a servo you would need to limit
the rate of change in LimuxCNC's commanded spindle speed. This can be done with
the "limit2" component. By passing LinuxCNCs commanded spindle speed through the
limit2 component, you can now specify the maximum rate of change in spindle speed
(in RPM/Second)

man limit2

Enable brings an additional complication in that LinuxCNC now has to wait for the spindle
speed to reach 0 before removing the spindle enable when stopping.
Last edit: 04 Apr 2021 13:31 by PCW.

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

More
05 Apr 2021 20:09 #204949 by NoJo
I am going to ask for more concerted help please..!

Still trying to implement a spindle deceleration before stop on my spindle step/dir servo

I have attached my current HAL file. Would one of you experts be so kind as to take a look and add to it the items/terms required to implement the limit2 function indicated by PCW. It does not have to be perfect, but at least all the parameters that are needed to be set up, the nets needed, etc, in terms of the signal names as used in my HAL file. This should at least help me to understand how these things tie together and allow me to follow the required connections and statement in the file in my so far futile attempts at understanding the HAL file...

I spent the whole day today digging through forum postings - did not find any examples that made sense to me ( there are very few by the way) - I also spent hours contemplating the Spindle Example in docs/html/examples/spindle.html - many terms are 'similar' to the names in my HAL file, but not exact and I have no idea how to assimilate that example's names and nomenclature into my file! Since it appears one can choose any name for anything it is hard to understand if my 'spindle-at-speed' is the same one as the one in the example file!

This is the example:
# load real time a limit2 and a near with names so it is easier to follow
loadrt limit2 names=spindle-ramp
loadrt near names=spindle-at-speed

# add the functions to a thread
addf spindle-ramp servo-thread
addf spindle-at-speed servo-thread

# set the parameter for max rate-of-change
# (max spindle accel/decel in units per second)
setp spindle-ramp.maxv 60

# hijack the spindle speed out and send it to spindle ramp in
net spindle-cmd <= spindle.0.speed-out => spindle-ramp.in

# the output of spindle ramp is sent to the scale in
net spindle-ramped <= spindle-ramp.out => scale.0.in

# to know when to start the motion we send the near component
# (named spindle-at-speed) to the spindle commanded speed from
# the signal spindle-cmd and the actual spindle speed
# provided your spindle can accelerate at the maxv setting.
net spindle-cmd => spindle-at-speed.in1
net spindle-ramped => spindle-at-speed.in2

# the output from spindle-at-speed is sent to spindle.0.at-speed
# and when this is true motion will start
net spindle-ready <= spindle-at-speed.out => spindle.0.at-speed


My file has a 'spindle-at-speed' which also appears in the use of the near component in the spindle section of the file, but in the example, at the top, there is a
loadrt near names=spindle-at-speed.
My file just says
loadrt near
how does my files 'near' even know of the name 'spindle-at-speed' when done this way??

Hard to understand from this lack of 'conformity' how the elements connect and are used!
I also looked at the man limit2 -
That was not really much help - all that documentation works fine if you already know it all...

Limit2 is described such in linuxcnc.org/docs/html/man/man9/limit2.9.html :

limit2 - Limit the output signal to fall between min and max and limit its slew rate to less than maxv per second. When the signal is a position, this means that position and velocity are limited.

Fine, that is understood.
then :
loadrt limit2 [count=N|names=name1[,name2...]]
Loadrt - fine
count=N - also understood
Then, what are the names and to what do they need to refer to or connect to??
There is no 'english' explanation I could find that explains each element and term, the dependencies etc.
then the pins list:

limit2.N.in float in
limit2.N.out float out
limit2.N.load bit in

When TRUE, immediately set out to in, ignoring maxv

limit2.N.min float in (default: -1e20)
limit2.N.max float in (default: 1e20)
limit2.N.maxv float in (default: 1e20)

Again, with no explanation of implementation , it is not possible for ME to 'pass LinuxCNCs commanded spindle speed through the
limit2 component, and specify the maximum rate of change in spindle speed' !!

Sheesh, for what is actually a very simple function I am trying to implement, this is difficult!

Thank You!
Joe
Attachments:

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

More
05 Apr 2021 20:21 #204953 by PCW

My file just says
loadrt near
how does my files 'near' even know of the name 'spindle-at-speed' when done this way??


It does not, if you use "near" you must only load it once so you either use
named instances or numbered instances, you cannot use both at once

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

More
05 Apr 2021 21:28 #204967 by NoJo
Thanks for responding PCW,

It does not, if you use "near" you must only load it once so you either use
named instances or numbered instances, you cannot use both at once


Where does one find the rules that those in the know state so easily?
I was not implying the use of both at once - I simple did not know that they were equivalent in some fashion - and no matter how hard I dig in those docs, that knowledge does not seem to be there.

My file has at the start:
loadrt near
( no names, no numbers)
then
addf near.0 servo-thread
( another 'near', with a number, but a servo thread..)

Then:
net spindle-vel-cmd-rps => near.0.in1
net spindle-vel-fb-rps => near.0.in2
net spindle-at-speed <= near.0.out
setp near.0.scale 1.000000
setp near.0.difference 1.666667

The example has :
loadrt near names=spindle-at-speed
then:
net spindle-cmd => spindle-at-speed.in1
net spindle-ramped => spindle-at-speed.in2

So I can see some indication of what you said about names and numbers -
I presume 'my' near.0.in1 = the example's spindle-at-speed.in1 ?

Anyway, I think I have asked enough times, pleaded...and am just starting to annoy people. I am not really getting anywhere, so thanks for everyone's indulgence and patience, but this is just to much pain with very little advancement for too long!

As I indicated earlier, the only reason for trying to go the route of Linuxcnc was because of the C_Axis for this lathe. But that is still a pipe dream, what with the basics being so elusive. I realise L_CNC is very versatile considering what other folk have managed to do with it, and naively thought a Basic Lathe would be a doddle...Such a pity it is such a hurdle, when options like MACH3/PlanetCNC, etc are so easy to configure and make work for simple setups like a 2 axis lathe.

Was a project with good intentions!

Thanks again to everyone, will leave you all in peace now!

Regards
Joe

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

More
05 Apr 2021 21:57 #204969 by PCW
if you just
loadrt near

You get the the count option and the default count is 1 if not specified
if you specify a count (N) , you get N instances of near with indexs
from 0 to N-1

If you use the names option, you get as many near instances
as you have names.

I presume 'my' near.0.in1 = the example's spindle-at-speed.in1 ?
and you specify names.


Yes, if you use the names options, near.N.whatever is replaced with your_name.whatever

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

More
06 Apr 2021 20:40 #205182 by andypugh

As I indicated earlier, the only reason for trying to go the route of Linuxcnc was because of the C_Axis for this lathe. But that is still a pipe dream, what with the basics being so elusive.


Don't give up.

Apart from anything else you are likely to have exactly the same problem with spindle deceleration with Mach, and I wouldn't want to guarantee that there will be a solution there.

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

Time to create page: 0.115 seconds
Powered by Kunena Forum