# joypadcomp.hal -- hal configuration file to move a cnc machine using a joypad, joycounts component version # [JOG] # Components # We will use the component joycounts to convert the axis float value in a counts integer value # to send to the axis jog counts pin. # Load the hal_joystick component that creates joypad.axis. and joypad.button. pins loadusr hal_joystick -d /dev/input/js0 -p joypad # Load three joycounts components loadrt joycounts count=3 # Create links between the joypad axis pins and joycounts axisvalue for X Y Z net velX joypad.axis.0 => joycounts.0.axisvalue net velY joypad.axis.1 => joycounts.1.axisvalue net velZ joypad.axis.3 => joycounts.2.axisvalue # Create links between joycounts counts and jog counts for X Y Z net countX joycounts.0.counts => axis.0.jog-counts net countY joycounts.1.counts => axis.1.jog-counts net countZ joycounts.2.counts => axis.2.jog-counts # Enable jog for X Y Z setp axis.0.jog-enable TRUE setp axis.1.jog-enable TRUE setp axis.2.jog-enable TRUE # Set joycounts scale setp joycounts.0.scale 0.2 setp joycounts.1.scale -0.2 setp joycounts.2.scale 0.2 # Attach realtime functions to threads addf joycounts.0.updatecounts servo-thread addf joycounts.1.updatecounts servo-thread addf joycounts.2.updatecounts servo-thread # [BUTTONS-SAMPLES] # Here are two examples on how to attach some functions to joypad buttons. We will use Halui pins for the # second example. # Scale button # we set two buttons (6 and 4) to choose the jogscale value. Pressing button 6 will set the scale to 0.1 # while pressing button 4 will set it to 0.01. # Components # We will use a two values selector and a flipflop component loadrt mux2 loadrt flipflop # Link between buttons and flipflop, flipflop will output TRUE when rising edge is detected on set pin, FALSE # when rising edge is on reset pin. net button4 joypad.button.4 => flipflop.0.reset net button6 joypad.button.6 => flipflop.0.set # Link between flipflop and mux2, mux2 will output value mux2.0.in0 when mux2.0.sel is FALSE and mux2.0.in1 # when TRUE. net selected flipflop.0.out => mux2.0.sel # Link between the mux2 output and the jogscale pin for X Y Z net jogscale mux2.0.out => axis.0.jog-scale net jogscale mux2.0.out => axis.1.jog-scale net jogscale mux2.0.out => axis.2.jog-scale # Set parameters values setp flipflop.0.tmax 3750 setp mux2.0.tmax 3601 #Set the two scale values setp mux2.0.in0 0.1 setp mux2.0.in1 0.01 # Attach realtime functions to threads addf flipflop.0 servo-thread addf mux2.0 servo-thread # Flood button # We will set a single button (button 7) to start and stop flood. We will use Halui pins for that. # Components # We will use simply two and2 and 1 not components loadrt and2 count=2 loadrt not # newsig flood-is-on bit #newsig not-flood-is-on bit #newsig button7 bit # Flood-is-on halui pin is linked to the and2.0.in0 and the not-flood-is-on, generated using the not component # is linked to the and2.1.in0. So, if the flood is on, we will have and2.0.in0 TRUE and and2.1.in0 FALSE. net flood-is-on halui.flood.is-on => and2.0.in0 net flood-is-on halui.flood.is-on => not.0.in net not-flood-is-on not.0.out => and2.1.in0 # Link between button 7 and and.0.in1 and and.1.in1. In this way, if the flood for example is on, when the # button is pressed TRUE will be sent to and2.0.in1 and and2.1.in1, while the in0 value for and2 components # will be TRUE for the first and2 and FALSE for the second. So the first and2 will output TRUE. net button7 joypad.button.7 => and2.0.in1 net button7 joypad.button.7 => and2.1.in1 #linksp flood-is-on halui.flood.is-on #linksp flood-is-on and2.0.in0 #linksp flood-is-on not.0.in #linksp not-flood-is-on not.0.out #linksp not-flood-is-on and2.1.in0 #linksp button7 joypad.button.7 #linksp button7 and2.0.in1 #linksp button7 and2.1.in1 # Link between and2 outputs and halui pin flood on and off. So, as seen above, if the flood is on, the and2.0 # will output TRUE and the flood will turn off. net floodOff and2.0.out halui.flood.off net floodOn and2.1.out halui.flood.on # Attach realtime functions to threads addf and2.0 servo-thread addf and2.1 servo-thread addf not.0 servo-thread