[resolved]Ethercat servo spindle orient problem while using M19 ?

More
11 Jul 2024 07:53 - 13 Jul 2024 09:43 #304871 by timaer
Hi,everyone 
    I've tried to follow the orient hal map to build a hal to test if it can be workable for orient ,but met some problem. while running M3 S100,M4 S100 such command it's all OK, but when I tried to use M19 R180 ,it didnt rotate at all. Using halshow display GUI,I noticed that while I run M3/M4 command,the spindle.on is true,but while I run the M19 R180  ,it is false.I dont know if it is the reason.Wish someone could help me ,point out where is the error of my hal .Thanks

###########################################################
#
# CIA 402 example snippet Hal
#
###########################################################

###########################################################
# Setup
###########################################################


loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS

loadusr -W lcec_conf ethercat-conf.xml
loadrt lcec
loadrt cia402 count=2
loadrt pid names=pos-pid,velo-pid
loadrt orient count=1
loadrt mux2 count=1


###########################################################
# Functions servo-thread
###########################################################

addf lcec.read-all servo-thread                 #reading from servo
addf cia402.0.read-all servo-thread
addf cia402.1.read-all servo-thread

addf motion-command-handler servo-thread
addf motion-controller servo-thread             #linuxcnc module ,cia402 module as a translator
addf pos-pid.do-pid-calcs servo-thread             
addf velo-pid.do-pid-calcs servo-thread
addf orient.0 servo-thread
addf mux2.0 servo-thread


addf cia402.0.write-all servo-thread
addf cia402.1.write-all servo-thread            #writing to servo
addf lcec.write-all servo-thread                


#########################################
#nets
#########################################
net emc-enable => iocontrol.0.emc-enable-in
sets emc-enable 1

#config

 
#
# Joint 0
#
setp cia402.0.csp-mode 0
setp cia402.0.velo-scale 166

#FOR SPINDLE
setp velo-pid.deadband 0.3      #limit pid tolerance
setp velo-pid.maxoutput 500     #limit pid maxoutput to protect
setp pos-pid.deadband 0.3
setp pos-pid.maxoutput 500    

net 0-statusword                                 lcec.0.0.cia-statusword  => cia402.0.statusword
net 0-opmode-display                             lcec.0.0.opmode-display  => cia402.0.opmode-display
net 0-drv-act-pos                                lcec.0.0.actual-position => cia402.0.drv-actual-position    
net 0-drv-act-velo                               lcec.0.0.actual-velocity => cia402.0.drv-actual-velocity 
net 0-speed-fb                                   cia402.0.velocity-fb     => velo-pid.feedback
net 0-pos-fb        pos-pid.feedback        <=   cia402.0.pos-fb          => orient.0.position  

#for spindle orient
#from linuxcnc motion to cia402 / cia402 to motion
#net 0-spindleON     spindle.0.on             => cia402.0.enable 
#net 0-target-speed  spindle.0.speed-out      => cia402.0.velocity-cmd

net 0-home-index    spindle.0.index-enable   => cia402.0.home
net 0-spindleON     velo-pid.enable          <= spindle.0.on         => cia402.0.enable
net 0-target-speed  spindle.0.speed-out      => velo-pid.command

net 0-orient        pos-pid.enable           <= spindle.0.orient     => orient.0.enable  => mux2.0.sel
net 0-angle         spindle.0.orient-angle   => orient.0.angle
net 0-orient_topos  orient.0.command         => pos-pid.command
  
net 0-pospid-tomux  pos-pid.output           => mux2.0.in1
net 0-velopid-tomux velo-pid.output          => mux2.0.in0
net 0-muxtoabs-final-speed      mux2.0.out   => cia402.0.velocity-cmd 
net 0-amp-fault     spindle.0.amp-fault-in   <= cia402.0.drv-fault


#from cia402 to servo
net 0-controlword         cia402.0.controlword         => lcec.0.0.cia-controlword
net 0-modes-of-operation  cia402.0.opmode              => lcec.0.0.opmode
net 0-drv-target-pos      cia402.0.drv-target-position => lcec.0.0.target-position
net 0-drv-target-velo     cia402.0.drv-target-velocity => lcec.0.0.target-velocity



#
# Joint 1
#
setp cia402.1.csp-mode 1
setp cia402.1.pos-scale 166

#from servo to cia402
net 1-statusword      lcec.0.1.cia-statusword  => cia402.1.statusword
net 1-opmode-display  lcec.0.1.opmode-display  => cia402.1.opmode-display
net 1-drv-act-pos     lcec.0.1.actual-position => cia402.1.drv-actual-position
net 1-drv-act-velo    lcec.0.1.actual-velocity => cia402.1.drv-actual-velocity


#from linuxcnc motion to cia402 / cia402 to motion
net 1-home-index joint.1.index-enable   => cia402.1.home
net 1-enable     joint.1.amp-enable-out => cia402.1.enable
net 1-amp-fault  joint.1.amp-fault-in   <= cia402.1.drv-fault
net 1-pos-cmd    joint.1.motor-pos-cmd  => cia402.1.pos-cmd
net 1-pos-fb     joint.1.motor-pos-fb   <= cia402.1.pos-fb


#from cia402 to servo
net 1-controlword         cia402.1.controlword         => lcec.0.1.cia-controlword
net 1-modes-of-operation  cia402.1.opmode              => lcec.0.1.opmode
net 1-drv-target-pos      cia402.1.drv-target-position => lcec.0.1.target-position
net 1-drv-target-velo     cia402.1.drv-target-velocity => lcec.0.1.target-velocity
Last edit: 13 Jul 2024 09:43 by timaer.

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

More
11 Jul 2024 08:19 #304873 by Aciera
for M19

'spindle.on' is false
'spindle.orient' is true

Have a look at section 2:
linuxcnc.org/docs/devel/html/config/core...html#sec:motion-pins


When you call M19 what do you see when you watch this signal:

net 0-muxtoabs-final-speed mux2.0.out => cia402.0.velocity-cmd
The following user(s) said Thank You: timaer

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

More
11 Jul 2024 08:36 - 11 Jul 2024 08:47 #304874 by timaer
Hi,Thank you ,Aciera.I just runned M19 R180,and the 0-muxtoabs-final-speed value is 0.2, is this the reason why the orient not working ?
BTW,"for M19 'spindle.on' is false 'spindle.orient' is true ",that's the exact situation while I runned M19,but still ,the orient action not happed.
Last edit: 11 Jul 2024 08:47 by timaer.

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

More
11 Jul 2024 08:46 #304876 by Aciera
Looks like the spindle drive is only enabled when using M3/M4:

net 0-spindleON velo-pid.enable <= spindle.0.on => cia402.0.enable

I guess you need to enable the spindle drive if 'spindle.0.on' is true OR 'spindle.0.orient' is true
So maybe try inserting an 'OR2' component with the 'spindle.0.on' signal on input 0, 'spindle.0.orient' signal on input 1 and the output going to 'cia402.0.enable'
The following user(s) said Thank You: timaer

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

More
11 Jul 2024 09:10 - 11 Jul 2024 09:10 #304882 by timaer
Hi,Aciera,I've modified it following your suggestion.it seems to be still not working.before modifying ,the final value is always 0.2 and after modifying ,now the value jump over again in 0.2 and -0.2 .


###########################################################
#
# CIA 402 example snippet Hal
#
###########################################################

###########################################################
# Setup
###########################################################


loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS

loadusr -W lcec_conf ethercat-conf.xml
loadrt lcec
loadrt cia402 count=2
loadrt pid names=pos-pid,velo-pid
loadrt orient count=1
loadrt mux2 count=1
loadrt or2 count=1


###########################################################
# Functions servo-thread
###########################################################

addf lcec.read-all servo-thread #reading from servo
addf cia402.0.read-all servo-thread
addf cia402.1.read-all servo-thread

addf motion-command-handler servo-thread
addf motion-controller servo-thread #linuxcnc module ,cia402 module as a translator
addf pos-pid.do-pid-calcs servo-thread
addf velo-pid.do-pid-calcs servo-thread
addf orient.0 servo-thread
addf mux2.0 servo-thread
addf or2.0 servo-thread


addf cia402.0.write-all servo-thread
addf cia402.1.write-all servo-thread #writing to servo
addf lcec.write-all servo-thread


#########################################
#nets
#########################################
net emc-enable => iocontrol.0.emc-enable-in
sets emc-enable 1

#config


#
# Joint 0
#
setp cia402.0.csp-mode 0
setp cia402.0.velo-scale 166

#FOR SPINDLE
setp velo-pid.deadband 0.3 #limit pid tolerance
setp velo-pid.maxoutput 500 #limit pid maxoutput to protect
setp pos-pid.deadband 0.3
setp pos-pid.maxoutput 500

net 0-statusword lcec.0.0.cia-statusword => cia402.0.statusword
net 0-opmode-display lcec.0.0.opmode-display => cia402.0.opmode-display
net 0-drv-act-pos lcec.0.0.actual-position => cia402.0.drv-actual-position
net 0-drv-act-velo lcec.0.0.actual-velocity => cia402.0.drv-actual-velocity
net 0-speed-fb cia402.0.velocity-fb => velo-pid.feedback
net 0-pos-fb pos-pid.feedback <= cia402.0.pos-fb => orient.0.position

#for spindle orient
#from linuxcnc motion to cia402 / cia402 to motion
#net 0-spindleON spindle.0.on => cia402.0.enable
#net 0-target-speed spindle.0.speed-out => cia402.0.velocity-cmd

net 0-spindleon-normal velo-pid.enable <= spindle.0.on => or2.0.in0
net 0-home-index spindle.0.index-enable => cia402.0.home
net 0-target-speed spindle.0.speed-out => velo-pid.command

net 0-orient pos-pid.enable <= spindle.0.orient => orient.0.enable => mux2.0.sel => or2.0.in1
net 0-spindleON or2.0.out => cia402.0.enable
net 0-angle spindle.0.orient-angle => orient.0.angle
net 0-orient_topos orient.0.command => pos-pid.command

net 0-pospid-tomux pos-pid.output => mux2.0.in1
net 0-velopid-tomux velo-pid.output => mux2.0.in0
net 0-muxtoabs-final-speed mux2.0.out => cia402.0.velocity-cmd
net 0-amp-fault spindle.0.amp-fault-in <= cia402.0.drv-fault


#from cia402 to servo
net 0-controlword cia402.0.controlword => lcec.0.0.cia-controlword
net 0-modes-of-operation cia402.0.opmode => lcec.0.0.opmode
net 0-drv-target-pos cia402.0.drv-target-position => lcec.0.0.target-position
net 0-drv-target-velo cia402.0.drv-target-velocity => lcec.0.0.target-velocity



#
# Joint 1
#
setp cia402.1.csp-mode 1
setp cia402.1.pos-scale 166

#from servo to cia402
net 1-statusword lcec.0.1.cia-statusword => cia402.1.statusword
net 1-opmode-display lcec.0.1.opmode-display => cia402.1.opmode-display
net 1-drv-act-pos lcec.0.1.actual-position => cia402.1.drv-actual-position
net 1-drv-act-velo lcec.0.1.actual-velocity => cia402.1.drv-actual-velocity


#from linuxcnc motion to cia402 / cia402 to motion
net 1-home-index joint.1.index-enable => cia402.1.home
net 1-enable joint.1.amp-enable-out => cia402.1.enable
net 1-amp-fault joint.1.amp-fault-in <= cia402.1.drv-fault
net 1-pos-cmd joint.1.motor-pos-cmd => cia402.1.pos-cmd
net 1-pos-fb joint.1.motor-pos-fb <= cia402.1.pos-fb


#from cia402 to servo
net 1-controlword cia402.1.controlword => lcec.0.1.cia-controlword
net 1-modes-of-operation cia402.1.opmode => lcec.0.1.opmode
net 1-drv-target-pos cia402.1.drv-target-position => lcec.0.1.target-position
net 1-drv-target-velo cia402.1.drv-target-velocity => lcec.0.1.target-velocity
Last edit: 11 Jul 2024 09:10 by timaer.

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

More
11 Jul 2024 09:50 #304889 by Aciera
Besides the pins you were already watching also have a look at the 'orient' component pins:
linuxcnc.org/docs/html/man/man9/orient.9.html

This should verify if you are getting any useful signal to 'pos-pid.command'

I see that you have not connected 'orient.0.mode' to 'spindle.0.orient-mode'. Not sure if the 'orient' component has a default value for its 'mode'-pin but you may want to make the connection just to be sure.

Note that I know nothing about the EtherCAT side of things at all, including the 'cia402' component.
The following user(s) said Thank You: timaer

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

More
11 Jul 2024 09:57 #304891 by timaer
Thank you,Aciera. I just followed the pin guide map in the following link wiki.linuxcnc.org/uploads/orient.svg , I dont know if I need to net the orient.mode and spindle.orient-mode,because it 's not mentioned in that link.

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

More
11 Jul 2024 10:18 #304892 by Aciera
I guess you could verify by checking the value of the 'orient.0.mode' pin.
The following user(s) said Thank You: timaer

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

More
12 Jul 2024 01:37 #304956 by timaer
I've checked the 'orient.0.mode' pin value,it is always 0 no matter I executed M3S100 or M19R180, is it normal?

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

More
12 Jul 2024 17:07 #305012 by spumco

I've checked the 'orient.0.mode' pin value,it is always 0 no matter I executed M3S100 or M19R180, is it normal?

M19 "P" indicates the direction mode.  The default is '0' (bi-directional).

spindle.n.orient-mode outputs the M19 P-value (default 0) and should be connected to orient.n.mode.

Mine looks like this:
net SPIN0-ORIENT-MODE       <=  spindle.0.orient-mode
net SPIN0-ORIENT-MODE       =>  orient.s0.mode

I think if that connection is left out of HAL orient.n.mode defaults to '0', but it doesn't hurt to have the connection.  Otherwise if for some reason you want to restrict direction with an M19 P-value you won't be able to.

Below is my lathe spindle config with orient stuff that works.  Step/dir servo motor.

The spindle.0.revs pin is necessary to synchronize my sub-spindle to the main spindle and is not required for orient.  None of the 'loadrt' stuff is in there, but the pin names should be self-explanatory.

Warning: Spoiler!
The following user(s) said Thank You: timaer

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

Time to create page: 0.102 seconds
Powered by Kunena Forum