HAL config for linear encoder and stepper motor

More
19 Feb 2017 19:50 #88288 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


# 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.

More
20 Feb 2017 19:58 - 20 Feb 2017 20:08 #88381 by mgadid
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
Attachments:
Last edit: 20 Feb 2017 20:08 by mgadid. Reason: double upload

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

More
20 Feb 2017 20:35 - 20 Feb 2017 20:37 #88386 by Todd Zuercher
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
Last edit: 20 Feb 2017 20:37 by Todd Zuercher.

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

More
20 Feb 2017 21:05 #88395 by mgadid
Thanks Todd :)

if i got you right it will be like:
Attachments:

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

More
20 Feb 2017 21:54 #88400 by Todd Zuercher
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.

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

More
21 Feb 2017 18:49 #88448 by mgadid
Thanks for pointing it out. :cheer:
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.

More
21 Feb 2017 19:26 #88452 by Todd Zuercher
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

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

More
21 Feb 2017 21:20 - 21 Feb 2017 21:23 #88464 by mgadid
Thank you.
i miss understud previuse replay. i messedtup step type with ctrl type.
so now i defined it as: stepgen step_type=0 ctrl_type=v

and component integration hear below.

after finishing the HAL file does the basic INI need to be config too?
i mean by adding and config pid and encoder

Attachments:
Last edit: 21 Feb 2017 21:23 by mgadid.

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

More
21 Feb 2017 21:39 #88466 by Todd Zuercher
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.

More
21 Feb 2017 21:52 - 22 Feb 2017 18:41 #88468 by mgadid
so the next step is to fireup Linuxcnc and try the file? :unsure:
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.113 seconds
Powered by Kunena Forum