HAL config for linear encoder and stepper motor
19 Feb 2017 19:50 #88288
by mgadid
HAL config for linear encoder and stepper motor was created by mgadid
Hello,
i'm newbe for linuxcnc. i'm trying to config HAL file thogh all the docomuntion are great. i find it hard to integret it all up.
and understand the internals.
i'm trying to config HAL file for linear encoder-with one wire puls. and creat a closed loop on the steeper baset on posion.
(stepper ruing with geackoG540).
i started to write the base and servo thread. but have doubts.
i know there is importents on the place a function is conected to thread.
i would appreciate your knowledge and experines with feedback on my work so far.
am i on the right track?![:S :S](/media/kunena/emoticons/dizzy.png)
# Generated by stepconf and converted configuration to lathe stepper+encoder with PID
#
# Loading Real Time Generic components
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hal_parport cfg="0 out"
setp parport.0.reset-time 3000
#config for charge pump
net estop-out charge-pump.enable iocontrol.0.user-enable-out
net charge-pump <= charge-pump.out
# Loading Real Time components
loadrt stepgen step_type=0,0
loadrt charge_pump
loadrt encoder num_chan=1
loadrt pid num_chan=1
#Adding fucntions to threads
addf parport.0.read base-thread
addf stepgen.make-pulses base-thread
addf charge-pump base-thread
####High speed function to count pulses (no floating point).
addf encoder.update-counters base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
####To setup DoubleStep on the parallel port you must add the function parport.n.reset after parport.n.write
####and configure stepspace to 0 and the reset time wanted. So that step can be asserted on every period in HAL
####and then toggled off by parport after being asserted for time specificed by parport.n.reset-time.
####parport.0.reset-time to 3000
####Low speed function to update latches and scale position.
addf encoder.capture-position servo-thread
####Performs all calculations for a single PID loop
addf pid.0.do-pid-calcs servo-thread
####computes the stepgen's current position and makes it available to HAL.
####The position feedback information is normally connected (by HAL) to the motion planner.
####what that mean?? does pid need to come after in the thread???
addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
#Parametes taken from the ini file
setp stepgen.0.position-scale [AXIS_0]SCALE
#if steplen is changed from 1 to 2, then it there will be two periods between the beginning and end of the step pulse
setp stepgen.0.steplen 1
#Minimum spacing between two step pulses (step types 0 and 1 only), in nano-seconds. Set to 0 to enable the stepgen doublefreq function.
#To use doublefreq the parport reset function must be enabled.
setp stepgen.0.stepspace 0
#Minmum time from the end of a step pulse to a direction change (step type 0 only), in nanoseconds.
setp stepgen.0.dirhold 25200
#Minimum time from a direction change to the beginning of the next step pulse (step type 0 only), in nanoseconds.
setp stepgen.0.dirsetup 25200
#Maximum accel/decel rate, in positions units per second squared. If 0.0, has no effect.
#Parametes taken from the ini file
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
i'm newbe for linuxcnc. i'm trying to config HAL file thogh all the docomuntion are great. i find it hard to integret it all up.
and understand the internals.
i'm trying to config HAL file for linear encoder-with one wire puls. and creat a closed loop on the steeper baset on posion.
(stepper ruing with geackoG540).
i started to write the base and servo thread. but have doubts.
i know there is importents on the place a function is conected to thread.
i would appreciate your knowledge and experines with feedback on my work so far.
am i on the right track?
![:S :S](/media/kunena/emoticons/dizzy.png)
# Generated by stepconf and converted configuration to lathe stepper+encoder with PID
#
# Loading Real Time Generic components
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hal_parport cfg="0 out"
setp parport.0.reset-time 3000
#config for charge pump
net estop-out charge-pump.enable iocontrol.0.user-enable-out
net charge-pump <= charge-pump.out
# Loading Real Time components
loadrt stepgen step_type=0,0
loadrt charge_pump
loadrt encoder num_chan=1
loadrt pid num_chan=1
#Adding fucntions to threads
addf parport.0.read base-thread
addf stepgen.make-pulses base-thread
addf charge-pump base-thread
####High speed function to count pulses (no floating point).
addf encoder.update-counters base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
####To setup DoubleStep on the parallel port you must add the function parport.n.reset after parport.n.write
####and configure stepspace to 0 and the reset time wanted. So that step can be asserted on every period in HAL
####and then toggled off by parport after being asserted for time specificed by parport.n.reset-time.
####parport.0.reset-time to 3000
####Low speed function to update latches and scale position.
addf encoder.capture-position servo-thread
####Performs all calculations for a single PID loop
addf pid.0.do-pid-calcs servo-thread
####computes the stepgen's current position and makes it available to HAL.
####The position feedback information is normally connected (by HAL) to the motion planner.
####what that mean?? does pid need to come after in the thread???
addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
#Parametes taken from the ini file
setp stepgen.0.position-scale [AXIS_0]SCALE
#if steplen is changed from 1 to 2, then it there will be two periods between the beginning and end of the step pulse
setp stepgen.0.steplen 1
#Minimum spacing between two step pulses (step types 0 and 1 only), in nano-seconds. Set to 0 to enable the stepgen doublefreq function.
#To use doublefreq the parport reset function must be enabled.
setp stepgen.0.stepspace 0
#Minmum time from the end of a step pulse to a direction change (step type 0 only), in nanoseconds.
setp stepgen.0.dirhold 25200
#Minimum time from a direction change to the beginning of the next step pulse (step type 0 only), in nanoseconds.
setp stepgen.0.dirsetup 25200
#Maximum accel/decel rate, in positions units per second squared. If 0.0, has no effect.
#Parametes taken from the ini file
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
Please Log in or Create an account to join the conversation.
20 Feb 2017 19:58 - 20 Feb 2017 20:08 #88381
by mgadid
Replied by mgadid on topic HAL config for linear encoder and stepper motor
hi,
i'm trying to config HAL file for linear encoder-with one wire puls. and creat a closed loop on the steeper baset on posion.
(stepper ruing with geackoG540).
i tried to understand how to integreat HAL components -motion, encoder, stepgen and pid
i put it on diagram. is that how the componets realy conected??
forum.linuxcnc.org/media/kunena/attachme...atHAL_2017-02-20.JPG
i'm trying to config HAL file for linear encoder-with one wire puls. and creat a closed loop on the steeper baset on posion.
(stepper ruing with geackoG540).
i tried to understand how to integreat HAL components -motion, encoder, stepgen and pid
i put it on diagram. is that how the componets realy conected??
forum.linuxcnc.org/media/kunena/attachme...atHAL_2017-02-20.JPG
Last edit: 20 Feb 2017 20:08 by mgadid. Reason: double upload
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
20 Feb 2017 20:35 - 20 Feb 2017 20:37 #88386
by Todd Zuercher
Replied by Todd Zuercher on topic HAL config for linear encoder and stepper motor
No guarantees this will work as advertised (step motors are not servos and won't step faster when stalled).
But it is Motion sends position cmd to PID, PID sends velocity cmd to Stepgenerator, Stepgenerator sends pulses to motor drive.
Encoder sends feed position back to PID and Motion
But it is Motion sends position cmd to PID, PID sends velocity cmd to Stepgenerator, Stepgenerator sends pulses to motor drive.
Encoder sends feed position back to PID and Motion
Last edit: 20 Feb 2017 20:37 by Todd Zuercher.
Please Log in or Create an account to join the conversation.
20 Feb 2017 21:05 #88395
by mgadid
Replied by mgadid on topic HAL config for linear encoder and stepper motor
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
20 Feb 2017 21:54 #88400
by Todd Zuercher
Replied by Todd Zuercher on topic HAL config for linear encoder and stepper motor
Close, the stepgen pin will be "stepgen.N.velocity-cmd" instead of position-cmd. But the basic gist of it is right.
Don't forget that the stepgenerator type needs to be set to velocity as well.
Pin names etc. will be different for a hardware step-gen.
Don't forget that the stepgenerator type needs to be set to velocity as well.
Pin names etc. will be different for a hardware step-gen.
Please Log in or Create an account to join the conversation.
21 Feb 2017 18:49 #88448
by mgadid
Replied by mgadid on topic HAL config for linear encoder and stepper motor
Thanks for pointing it out. ![:cheer: :cheer:](/media/kunena/emoticons/cheerful.png)
some how i missed the pid output is in vel units.
does step type 2 will work on steper motor? (there is no step and dir only phaze A and B . correct? )
![:cheer: :cheer:](/media/kunena/emoticons/cheerful.png)
some how i missed the pid output is in vel units.
does step type 2 will work on steper motor? (there is no step and dir only phaze A and B . correct? )
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
21 Feb 2017 19:26 #88452
by Todd Zuercher
Replied by Todd Zuercher on topic HAL config for linear encoder and stepper motor
What type works, will depend on your drives. Some drives can be configured for different input types, but the most common is standard type 0 step/dir.
A good description of how Linuxcnc's software step generator can be configured and how it works can be found here.
linuxcnc.org/docs/html/hal/rtcomps.html
A good description of how Linuxcnc's software step generator can be configured and how it works can be found here.
linuxcnc.org/docs/html/hal/rtcomps.html
Please Log in or Create an account to join the conversation.
21 Feb 2017 21:20 - 21 Feb 2017 21:23 #88464
by mgadid
Replied by mgadid on topic HAL config for linear encoder and stepper motor
Last edit: 21 Feb 2017 21:23 by mgadid.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
21 Feb 2017 21:39 #88466
by Todd Zuercher
Replied by Todd Zuercher on topic HAL config for linear encoder and stepper motor
PID and encoder settings can be set up only in hal. But they are usually set up in the ini, with the hal files using variables to reference the ini.
The following user(s) said Thank You: mgadid
Please Log in or Create an account to join the conversation.
21 Feb 2017 21:52 - 22 Feb 2017 18:41 #88468
by mgadid
Replied by mgadid on topic HAL config for linear encoder and stepper motor
so the next step is to fireup Linuxcnc and try the file?
![:unsure: :unsure:](/media/kunena/emoticons/unsure.png)
Last edit: 22 Feb 2017 18:41 by mgadid.
Please Log in or Create an account to join the conversation.
Time to create page: 0.118 seconds