How to: Image/ Media

INI and HA L files, running the show



INI and HAL. The INI file describes each axis's type, maximum and minimum speed, and homing locations, while the HAL file describes the hardware interface layer between Linux cnc and the external hardware. The Linux cnc package has some excellent, dense documentation on both the INI [





Shown right is the user interface, consisting of a 3d model displayed by tk (far left), and the gcode model with trace paths shown. The Axis data is displayed on the far right, and detailed below in the scara.xml section. In Linux CNC, 2 files do all the configuration hard-work.andThe INI file describes each axis's type, maximum and minimum speed, and homing locations, while the HAL file describes the hardware interface layer between Linux cnc and the external hardware. The Linux cnc package has some excellent, dense documentation on both the INI [ link ] and HAL [ link ] files.Shown right is the user interface, consisting of a 3d model displayed by tk (far left), and the gcode model with trace paths shown. The Axis data is displayed on the far right, and detailed below in the scara.xml section.

INI File Details:



Notes from the INI File Setup:

This ini file was based on a mix of the sample INI file for KUKA machines and a basic INI output from stepgen-config. Two threads control the machine, a SERVO thread which is a slower global positioning thread and a BASE thread which provides the higher speed pwm/pulse generation for STEP/DIRECTION output commands





A separate image is set to display on startup [robot.gif]



Added in Image detection on import, an awesome feature that loads 'image-to-gcode' when a greyscale image with png, gif, or jpg extension is loaded.

PROGRAM_EXTENSION = .png,.gif,.jpg Grayscale Depth Image

png = image-to-gcode

gif = image-to-gcode

jpg = image-to-gcode

The Traj section sets global max velocities, max accelerations

The Axes section sets each axis's parameters, input scales and setup for homing sequences.



Note that AXIS 0 and AXIS 1 are polar axes, while AXIS 2 is the linear Z axis for up/down # EMC controller parameters for a simulated hexapod of the minitetra type. # THIS FILE IS THE CURRENT WORKING SCARA PROJECT, # General note: Comments can either be preceded with a # or ; - either is # acceptable, although # is in keeping with most linux config files. # Settings with a + at the front of the comment are likely needed to get # changed by the user. # Settings with a - at the front are highly unneeded to be changed ############################################################################### # General section ############################################################################### # General section ------------------------------------------------------------- [EMC] #- Version of this INI file VERSION = $Revision$ #+ Name of machine, for use with display, etc. MACHINE = EMC-HAL-SIM-SCARA #+ Debug level, 0 means no messages. See src/emc/nml_int/emcglb.h for others DEBUG = 0 # DEBUG = 0x00000007 #DEBUG = 0x7FFFFFFF ############################################################################### # Sections for display options ############################################################################### [DISPLAY] #+ Name of display program, e.g., xemc DISPLAY = axis # DISPLAY = usrmot # DISPLAY = mini # DISPLAY = tkemc #- Cycle time, in seconds, that display will sleep between polls CYCLE_TIME = 0.200 #- Path to help file HELP_FILE = tkemc.txt #- Initial display setting for position, RELATIVE or MACHINE POSITION_OFFSET = MACHINE #- Initial display setting for position, COMMANDED or ACTUAL POSITION_FEEDBACK = ACTUAL #+ Highest value that will be allowed for feed override, 1.0 = 100% MAX_FEED_OVERRIDE = 2.0 #+ Prefix to be used PROGRAM_PREFIX = /home/cnc/emc2/nc_files #- Introductory graphic #PREVIOUS INTRO_GRAPHIC = emc2.gif INTRO_GRAPHIC = robot.gif INTRO_TIME = 6 PYVCP = scara.xml # Editor to be used with Axis EDITOR = gedit ############################################################################### # Task controller section ############################################################################### [TASK] # Name of task controller program, e.g., milltask TASK = milltask #- Cycle time, in seconds, that task controller will sleep between polls #CYCLE_TIME = 0.010 CYCLE_TIME = 0.001 ############################################################################### # Part program interpreter section ############################################################################### [RS274NGC] #- File containing interpreter variables PARAMETER_FILE = scara.var ############################################################################### # Motion control section ############################################################################### [EMCMOT] EMCMOT = motmod #- Timeout for comm to emcmot, in seconds COMM_TIMEOUT = 1.0 #- Interval between tries to emcmot, in seconds COMM_WAIT = 0.010 #- Servo task period, in nanoseconds #WAS SERVO_PERIOD = 1000000 #WAS BASE_PERIOD = 500000 SERVO_PERIOD = 400000 BASE_PERIOD = 80000 # WAS THIS WORKING BASE_PERIOD = 500000 #- Trajectory Planner task period, in nanoseconds - will be rounded to an # integer multiple of SERVO_PERIOD #TRAJ_PERIOD = 10000000 #WAS TRAJ_PERIOD = 100000000 TRAJ_PERIOD = 40000000 ############################################################################### # Hardware Abstraction Layer section ############################################################################### [HAL] # The run script first uses halcmd to execute any HALFILE # files, and then to execute any individual HALCMD commands. # # list of hal config files to run through halcmd # files are executed in the order in which they appear HALFILE = scara_sim_4.hal POSTGUI_HALFILE = scara_postgui.hal #- list of halcmd commands to execute # commands are executed in the order in which they appear #HALCMD = save neta #load halui to enable HALUI = halui [FILTER] PROGRAM_EXTENSION = .png,.gif,.jpg Grayscale Depth Image png = image-to-gcode gif = image-to-gcode jpg = image-to-gcode ############################################################################### # Trajectory planner section ############################################################################### [TRAJ] #+ machine specific settings AXES = 6 COORDINATES = X Y Z C HOME = 0 0 0 0 LINEAR_UNITS = 1.0 ANGULAR_UNITS = 1.0 CYCLE_TIME = 0.010 DEFAULT_VELOCITY = 50.0 #DEFAULTVELOCITY WAS 1 MAX_VELOCITY = 400.0 #MAX_VELOCITY = 600.0 DEFAULT_ACCELERATION = 100.0 DEFAULT_ACCELERATION = 30.0 MAX_ACCELERATION = 200.0 ############################################################################### # Axes sections ############################################################################### #+ First axis [AXIS_0] TYPE = ANGULAR HOME = 0.000 MAX_VELOCITY = 1400.0 MAX_ACCELERATION = 40.0 BACKLASH = 0.000 #INPUT_SCALE = 182 INPUT_SCALE = 310 OUTPUT_SCALE = 1.000 MIN_LIMIT = -12000.0 MAX_LIMIT = 16000.0 FERROR = 2.000 MIN_FERROR = 0.200 HOME_OFFSET = 0.0 HOME_SEARCH_VEL = 0.0 HOME_LATCH_VEL = 0.0 HOME_USE_INDEX = NO HOME_IGNORE_LIMITS = NO HOME_SEQUENCE = 0 #+ Second axis [AXIS_1] TYPE = ANGULAR HOME = -90.000 MAX_VELOCITY = 80000.0 MAX_ACCELERATION = 300.0 BACKLASH = 0.000 #usedtobeINPUT_SCALE = 420 INPUT_SCALE = 482 #INPUT_SCALE = 4000 OUTPUT_SCALE = 1.000 MIN_LIMIT = -14400.0 MAX_LIMIT = 16500.0 FERROR = 2.000 MIN_FERROR = 0.200 HOME_OFFSET = 0.0 HOME_SEARCH_VEL = 0.0 HOME_LATCH_VEL = 0.0 HOME_USE_INDEX = NO HOME_IGNORE_LIMITS = NO HOME_SEQUENCE = 0 #+ Third axis [AXIS_2] TYPE = LINEAR HOME = 25.000 MAX_VELOCITY = 3000.0 MAX_ACCELERATION = 200.0 BACKLASH = 0.000 INPUT_SCALE = 98 #INPUT_SCALE = 4000 OUTPUT_SCALE = 1.000 MIN_LIMIT = -2500.0 MAX_LIMIT = 39200.0 FERROR = 2.000 MIN_FERROR = 0.200 HOME_OFFSET = 25.0 HOME_SEARCH_VEL = 0.0 HOME_LATCH_VEL = 0.0 HOME_USE_INDEX = NO HOME_IGNORE_LIMITS = NO HOME_SEQUENCE = 0 #+ Fourth axis [AXIS_5] TYPE = ANGULAR HOME = 0.000 MAX_VELOCITY = 30.0 MAX_ACCELERATION = 200.0 BACKLASH = 0.000 INPUT_SCALE = 100 #INPUT_SCALE = 4000 OUTPUT_SCALE = 1.000 MIN_LIMIT = -180.0 MAX_LIMIT = 180.0 FERROR = 2.000 MIN_FERROR = 0.200 HOME_OFFSET = 0.0 HOME_SEARCH_VEL = 0.0 HOME_LATCH_VEL = 0.0 HOME_USE_INDEX = NO HOME_IGNORE_LIMITS = NO HOME_SEQUENCE = 0 ############################################################################### # section for main IO controller parameters ############################################################################### [EMCIO] #- Name of IO controller program, e.g., io EMCIO = io #- cycle time, in seconds CYCLE_TIME = 0.0100 # CYCLE TIME WAS 0.100 #- tool table file TOOL_TABLE = scara.tbl

Kinematics

The robots forward kinematics are defined using the following, referenced to figure 1



The robots Inverse kinematics are defined using the following, referenced to figure 2





This is A HECKUVA LOT MORE COMPLEX than cartesian systems used in a makerbot style 3dprinter. The full kinematic model is defined, with some modifications, in this file [ Link ]. Note the kinematic file is complied before executing the robots actions, making modifications without compiling will have no effectThis isthan cartesian systems used in a makerbot style 3dprinter. Forward Kinematic Axis reference



Inverse Kinematic position reference



HAL File Details:



This is the HAL file that links all the system signals to the kinematic model and then outbound o the parallel port aka 'parport.0'



Mixing stepgen and scara kinematics was a difficult exercise, there are a number of commented-out sections from the debug process.



I ended up generating a servo-thread for each axis parameter (0-8) and then piped the output to the parallel port (parport, 0X378). After stepgen was generating step-direction data, that is linked to the actual positions (J0pos, etc). This acts as the feedback path keeping the robot actual positions bounded by the planned positions.



A few functions were inverted in output state, however a simple

setp parport.0.pin-03-out-invert 1 Inverted the state before it hit the hardware output



Fault inputs and limit switches were generated next to prevent out-of-bounds positioning and prevent the robot from running into the wall (again)



Lastly, each axis of the robot commanded positions were fed back into the scaragui



net j0 axis.0.joint-pos-fb scaragui.joint0



# core HAL config file for simulation - 4 axis # load RT modules loadrt scarakins #loadrt trivkins loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD traj_period_nsec=[EMCMOT]TRAJ_PERIOD num_joints=[TRAJ]AXES #OLDCONFIG loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD traj_period_nsec=[EMCMOT]TRAJ_PERIOD num_joints=[TRAJ]AXES loadrt ddt count=12 #THINGS DANE ADDED loadrt stepgen step_type=0,0,0,0 loadrt probe_parport loadrt hal_parport cfg="0x378 out " loadrt pwmgen output_type=0 addf stepgen.capture-position servo-thread addf stepgen.update-freq servo-thread addf stepgen.make-pulses base-thread addf parport.0.read base-thread addf parport.0.write base-thread # add motion controller functions to servo thread addf motion-command-handler servo-thread addf motion-controller servo-thread addf ddt.0 servo-thread addf ddt.1 servo-thread addf ddt.2 servo-thread addf ddt.3 servo-thread addf ddt.4 servo-thread addf ddt.5 servo-thread addf ddt.6 servo-thread addf ddt.7 servo-thread addf ddt.8 servo-thread # create HAL signals for position commands from motion module newsig J0pos float linksp J0pos <= axis.0.motor-pos-cmd linksp J0pos => stepgen.0.position-cmd #DANEMOD newsig J1pos float linksp J1pos <= axis.1.motor-pos-cmd linksp J1pos => stepgen.1.position-cmd #DANEMOD newsig J2pos float linksp J2pos <= axis.2.motor-pos-cmd linksp J2pos => stepgen.2.position-cmd #DANEMOD newsig J3pos float linksp J3pos <= axis.3.motor-pos-cmd linksp J3pos => stepgen.3.position-cmd #DANEMOD # loop position commands back to motion module feedback linksp J0pos => axis.0.motor-pos-fb linksp J1pos => axis.1.motor-pos-fb linksp J2pos => axis.2.motor-pos-fb linksp J3pos => axis.3.motor-pos-fb #DANEMOD newsig Xpos-fb float linksp Xpos-fb <= stepgen.0.position-fb newsig Ypos-fb float linksp Ypos-fb <= stepgen.1.position-fb newsig Zpos-fb float linksp Zpos-fb <= stepgen.2.position-fb #linksp Xpos-fb => axis.0.motor-pos-fb #need to add in other signals (y,z) #DANEMOD newsig Xen bit linksp Xen <= axis.0.amp-enable-out linksp Xen => stepgen.0.enable newsig Yen bit linksp Yen <= axis.1.amp-enable-out linksp Yen => stepgen.1.enable newsig Zen bit linksp Zen <= axis.2.amp-enable-out linksp Zen => stepgen.2.enable newsig Aen bit linksp Aen <= axis.3.amp-enable-out linksp Aen => stepgen.3.enable #DANEMOD # connect signals to step pulse generator outputs newsig Xstep bit newsig Xdir bit newsig Ystep bit newsig Ydir bit newsig Zstep bit newsig Zdir bit newsig Astep bit newsig Adir bit linkps stepgen.0.step Xstep linkps stepgen.0.dir Xdir linkps stepgen.1.step Ystep linkps stepgen.1.dir Ydir linkps stepgen.2.step Zstep linkps stepgen.2.dir Zdir linkps stepgen.3.step Astep linkps stepgen.3.dir Adir #DANEMOD setp stepgen.0.position-scale [AXIS_0]INPUT_SCALE setp stepgen.1.position-scale [AXIS_1]INPUT_SCALE setp stepgen.2.position-scale [AXIS_2]INPUT_SCALE setp stepgen.3.position-scale [AXIS_5]INPUT_SCALE #LINK TO OUTSIDE net Xstep => parport.0.pin-14-out net Xdir => parport.0.pin-04-out net Ystep => parport.0.pin-06-out net Ydir => parport.0.pin-07-out net Zstep => parport.0.pin-02-out net Zdir => parport.0.pin-03-out setp parport.0.pin-03-out-invert 1 setp parport.0.pin-07-out-invert 1 setp parport.0.pin-04-out-invert 1 newsig extrude float # send the position commands thru differentiators to # generate velocity and accel signals # define the signals, and hook them up newsig J0vel float newsig J0acc float linksp J0pos => ddt.0.in linkps ddt.0.out => J0vel linksp J0vel => ddt.1.in linkps ddt.1.out => J0acc newsig J1vel float newsig J1acc float linksp J1pos => ddt.2.in linkps ddt.2.out => J1vel linksp J1vel => ddt.3.in linkps ddt.3.out => J1acc newsig J2vel float newsig J2acc float linksp J2pos => ddt.4.in linkps ddt.4.out => J2vel linksp J2vel => ddt.5.in linkps ddt.5.out => J2acc newsig J3vel float newsig J3acc float linksp J3pos => ddt.6.in linkps ddt.6.out => J3vel linksp J3vel => ddt.7.in linkps ddt.7.out => J3acc # estop loopback #DANEMOD net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in # create signals for tool loading loopback net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed # amp control #newsig xena bit #linksp xena axis.0.amp-enable-out #newsig yena bit #linksp yena axis.1.amp-enable-out #newsig zena bit #linksp zena axis.2.amp-enable-out #newsig aena bit #linksp aena axis.3.amp-enable-out newsig xflt bit linksp xflt axis.0.amp-fault-in newsig yflt bit linksp yflt axis.1.amp-fault-in newsig zflt bit linksp zflt axis.2.amp-fault-in newsig aflt bit linksp aflt axis.3.amp-fault-in #DANEMOD # estop loopback # net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in net estop-out <= iocontrol.0.user-enable-out net estop-out => iocontrol.0.emc-enable-in #used to be this net estop-out => parport.0.pin-01-out net estop-out => parport.0.pin-17-out # create signals for tool loading loopback net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed #DANEMOD-LIMIT SWITCH net both-y <= parport.0.pin-13-in-not net both-y => axis.1.neg-lim-sw-in net both-y => axis.1.pos-lim-sw-in #DANEMOD-JOYSTICK # for remote joypad loadusr -W hal_input -KRAL Dual loadusr -W scaragui net j0 axis.0.joint-pos-fb scaragui.joint0 net j1 axis.1.joint-pos-fb scaragui.joint1 net j2 axis.2.joint-pos-fb scaragui.joint2 net j3 axis.3.joint-pos-fb scaragui.joint3

Joystick Interface



To preform manual homing, or just putz around with a robot, i use a Logitec usb game controller. Its intuitive to use and more functional than virtual buttons.



To add the game controller functionality, the following mods to my postgui file were made:



3 nets were made to vary speed (1-3). The speed was bounded by setp scale parameters

setp mux4.0.in1 50

setp mux4.0.in2 200

setp mux4.0.in3 800 In this case, holding input 1 while preforming joystick motions scaled by a factor of 50 steps/min (SLOW), whereas switching to holding input 3 scaled by a factor of 800 steps/min (FAST) net j0 pyvcp.joint0 net j1 pyvcp.joint1 net j2 pyvcp.joint2 net j3 pyvcp.joint3 #DANEMODS-JOYSTICK loadrt or2 count=2 loadrt mux4 count=1 addf or2.0 servo-thread addf or2.1 servo-thread addf mux4.0 servo-thread # set the jog speed for the joypad again use numbers that make sense for your machine setp mux4.0.in0 0 # this one must be 0 to prevent motion unless a button is pressed setp mux4.0.in1 50 setp mux4.0.in2 200 setp mux4.0.in3 800 # the following does the magic of setting the jog speeds net remote-speed-slow or2.0.in0 input.0.btn-trigger net remote-speed-medium or2.1.in0 input.0.btn-thumb net remote-speed-fast or2.0.in1 or2.1.in1 input.0.btn-thumb2 net joy-speed-1 mux4.0.sel0 <= or2.0.out net joy-speed-2 mux4.0.sel1 <= or2.1.out net joy-speed-final halui.jog-speed <= mux4.0.out net joy-x-jog halui.jog.0.analog <= input.0.abs-z-position net joy-y-jog halui.jog.1.analog <= input.0.abs-hat0x-position net joy-z-jog halui.jog.2.analog <= input.0.abs-hat0y-position #setp input.0.abs-z-offset -0.003921569 setp input.0.abs-z-scale 50.00 setp input.0.abs-hat0x-scale 0.80 setp input.0.abs-hat0y-scale 0.40

Mating g-code from skeinforge into Linux CNC

Skeinforge [ Link ] is an amazing tool for slicing a model, starting as an STL file, into a series of G-Code commands that reprap or even Linux CNC can make use of. There are some extra features that skeinforge puts into a g-code output file, to control extruders, fans, and heaters. These 'extra features' will throw errors in a plain-vanilla linux cnc setup. These are 'M-codes', listed on the rep-rap wiki [ link ]&[ link ]. Without 'm-files' present in the location speficied from the HAL file, linux cnc will throw an error. Examples:

M101: Extruder on (fwd)

M102: Extruder on (rev) <'oozebane' skeinforge, useful for preventing extruder oozing>

M103: Extruder off

M104: Extruder Set Temp

M106: Turn on Fans

M017: Turn off Fans

Example 'M-code' file

The following is a code-snippet from my initial M101 file.

Its located in /home/<machine_name>/emc2/nc_files

#!/bin/bash

# file to turn on parport pin 09 to on

halcmd setp parport.0.pin-09-out 1

exit 0

All this m-file does is call halcmd and set pin 09 of the parallel port to a logic '1' output.

Finally, a PSA :

REMEMBER TO ALLOW EXECUTION OF M-FILES

To verify that an M-File is executable, graphically, simply right-click on the file, goto 'permissions' and doublecheck that 'allow executing file as program' is checked off. Verify for each M-File you make.

