Learning HAL, examples of my coding - thoughts please and guidance

More
21 Nov 2019 14:52 #150830 by jools
I'm trying to learn HAL so I can control my spindle servo from the 7i96. Currently the stepgens I have are in position mode and I want them in velocity mode. I've looked at their code and have tried to understand it and then write my own bit.
Coudl people tell me if I'm on the right track.


# Joint 0
# axis enable chain
newsig emcmot.0.enable bit
sets emcmot.0.enable FALSE
net emcmot.0.enable <= joint.0.amp-enable-out
net emcmot.0.enable => hm2_[HOSTMOT2](BOARD).0.stepgen.00.enable pid.0.enable
#says create new signal which is a bit, sets that bit to false, then links that to the pin joint.0.amp-enable-out. So when joint.0.amp-enable-out is enabled it relays a signal to stepgen.00. on the 7i96 saying “we’re good to go”
#This enables step generator 00 and pid0 on the 7i96


# position command and feedback
net emcmot.0.pos-cmd joint.0.motor-pos-cmd => pid.0.command
net motor.0.pos-fb <= hm2_[HOSTMOT2](BOARD).0.stepgen.00.position-fb joint.0.motor-pos-fb pid.0.feedback
net motor.0.command pid.0.output hm2_[HOSTMOT2](BOARD).0.stepgen.00.velocity-cmd
setp pid.0.error-previous-target true

The above links (net) the signal in emcmot.0.pos-cmd on the pin joint.0.motor-pos-cmd (which is an output) to the pin pid.0.command
Questions: Is this link just in hal, so this is something internally for linux cnc to sort out. Essentially saying share information
Does this determine the motor running in position mode as I can’t see it defined anywhere else in HAL or INI
It also links signal in motor.0.pos-fb (which is an encoder position feedback i think) to the 7i96’s stepgen operator pin (00 lets say x axis) the motors feedback pin and to PID number one’s linked feedback (so it can do it’s PID loop thingy?).
Questions: Am I correct in thinking this net has linked one signal in to three pins, one on the 7i96 and two in linux cnc.
It links motor.0.command which is given through pin pid.0.output to the 7i96’s stepgen #00 Velocity-cmd

So essentially motor command says go to x10. First net gives that to PID0
At the same time the feedback reads your not there
Motor command gets the info which says your not equal to x10; move in the direction of x10.
This loops until x=10
Is that correct?

So say I wanted this particular stepgen to run in velocity mode for a spindle
net emcmot.0.velocity-cmd joint.0.motor-vel-cmd => pid.0.command
net motor.0.pos-fb <= hm2_[HOSTMOT2](BOARD).0.stepgen.00.position-fb joint.0.motor-pos-fb pid.0.feedback
net motor.0.command pid.0.output hm2_[HOSTMOT2](BOARD).0.stepgen.00.velocity-cmd
setp pid.0.error-previous-target true

Questions on the above:
- Do I need to tell linuxcnc that the stepgen is in velocity mode? Something like:
loadrt stepgen step_type=type0, type0, type0, type0 ctrl_type=typep, typep, typep, typev
See linuxcnc.org/docs/html/man/man9/stepgen.9.html as ref where I got this info
Do I need to set some pins and their value?

Cheers

Jools

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

More
21 Nov 2019 15:11 #150833 by Todd Zuercher
One thing I would suggest not doing. Try not to use hal pin names as signal names. It will make your hal very confusing. Every "net" command must contain a signal name, and the first text between two spaces after the "net" will be the signal name. The signal name is simply a reference you make up to name each of your hal net commands. Signals can be reused by multiple net commands to connect multiple input pins to a single output pin (even spanning different hal files.) From the example hal commands you have listed it looks like you are trying to omit the signal name, that can not be done, if you do that the first hal pin you list will be used as the signal name for that net command, and not as a hal pin.
The following user(s) said Thank You: jools

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

More
21 Nov 2019 15:22 #150834 by Todd Zuercher
Also the "newsig" command is depreciated, and is not nessisary. simply using a net command will create the signal. My understanding is that it once was nessisary but that hasn't been true for a very long time, (before I started using Linuxcnc.)

Also your "sets emcmot.0.enable FALSE" command is superfluous, and will likely set an alarm and maybe prevent Linuxcnc from starting, because you can't sets a value to a signal if it is connected to an output, which you do on the next line.

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

More
21 Nov 2019 15:32 #150835 by jools

Also the "newsig" command is depreciated, and is not nessisary. simply using a net command will create the signal. My understanding is that it once was nessisary but that hasn't been true for a very long time, (before I started using Linuxcnc.)

Also your "sets emcmot.0.enable FALSE" command is superfluous, and will likely set an alarm and maybe prevent Linuxcnc from starting, because you can't sets a value to a signal if it is connected to an output, which you do on the next line.



Hi Todd
This is strange because those bits of HAL were generated by the 7i96 tool and not myself. I changed the top one to create the bottom one :unsure:

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

More
21 Nov 2019 15:42 - 21 Nov 2019 15:49 #150836 by Todd Zuercher
I should have read your questions better.

A signal connects one output pin (whether from an internal Linuxcnc source or an outside source) to as many input pins as you like. in the case of your stepgen's position feedback it is connected to both Linuxcnc's joint position feedback and the pid position feedback much like the encoder for a servo would be. Hopefully that answers your first two questions.

No, you don't need to tell Linuxcnc that the stepgen is using a velocity command. But you do have to configure it's connection to Linuxcnc like a servo connection, and that should done for you by the configuration wizard (I've only used Pncconfig not the new config tool for the 7i96) The wizard for the 7i96 is rather new, hopefully there aren't too many bugs still in it.
Last edit: 21 Nov 2019 15:49 by Todd Zuercher.

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

More
21 Nov 2019 15:45 #150837 by Todd Zuercher

Hi Todd
This is strange because those bits of HAL were generated by the 7i96 tool and not myself. I changed the top one to create the bottom one :unsure:


Yes, sorry, I spouted off before looking it over very carefully, but those signal names do almost look like hal pin names.

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

More
21 Nov 2019 16:32 #150845 by jools

Hi Todd
This is strange because those bits of HAL were generated by the 7i96 tool and not myself. I changed the top one to create the bottom one :unsure:


Yes, sorry, I spouted off before looking it over very carefully, but those signal names do almost look like hal pin names.


:laugh: no probs

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

Time to create page: 0.089 seconds
Powered by Kunena Forum