Hi,
sorry, but this can't work :
addf motion-command-handler servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf lcec.read-all servo-thread
addf lcec.write-all servo-thread
addf cia402.0.read-all servo-thread
addf cia402.1.read-all servo-thread
addf cia402.0.write-all servo-thread
addf cia402.1.write-all servo-thread
addf pid.s.do-pid-calcs servo-thread
addf classicladder.0.refresh servo-thread
#addf spi_interlock servo-thread
addf carousel.0 servo-thread
addf near.0 servo-thread
addf scale.0 servo-thread
The function execution order is an fundamental part of every machine control, plc, software programm etc.
I explained this a few times in the ethercat thread, also in the doc for the 402 component and it is good explained in the
"Hal introduction" and "Hal Basics" Chapter of the linuxcnc docs .....
In an Microcontroller or Realtime Program you have an task. (example servo-thread) this task is executed in an specified rate (examble every 1ms) . Into this task you have to add programms (functions) that do certain things. if you got more then one function and they have to interact together it is important which is the first that is executed. Injecting fuel after the ignition of the spark plug will not work...
In an hal-thread the functions are executed as they are added in the hal file (addf).
looking at this:
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf lcec.read-all servo-thread
addf lcec.write-all servo-threadyour task starts and do the calculating of the motion part, but you have not readed the position and other values from the hardware yet. the result is that motions uses the old value from the last cycle. If you have a PID Systems this would let to horible behaviour.... The correct order would be :
-First read from hardware
-motion calculations
-(pid calculations) (important: pids after motion!)
-last write to hardware (with the new calculated values from this cycle)
this also is important for the 402 component and for scale/near components. You need the actual values from this cycle.
The correct order for your hal would be:
addf lcec.read-all servo-thread
addf cia402.0.read-all servo-thread
addf cia402.1.read-all servo-thread
addf scale.0 servo-thread scale in front of near, because it calcs the input for near and motion
addf near.0 servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf pid.s.do-pid-calcs servo-thread
addf classicladder.0.refresh servo-thread
#addf spi_interlock servo-thread
addf carousel.0 servo-thread
addf cia402.0.write-all servo-threadaddf cia402.1.write-all servo-threadaddf lcec.write-all servo-thread
i hope this helps, i think the behaviour should now changed. At your old order the pos_cmd (with the new home pos) arrived one cycle later as the mode switch bit. so the drive would have seen zero or another value instead of the new readed fb_pos and it says fb-err at this moment.
hmm, hab gerade erst in der hal gesehen das ich mir gar keinen in Denglisch hätte abbrechen müssen.....