My Grizzly G0619 mill
- BeagleBrainz
- Offline
- User is blocked
- Posts: 1437
- Thank you received: 570
component mpg_pendant "3 Axis Generic MPG";
description "For use with a generic 4 axis chinese ebay pendant inspired by the mpg component of Kurt Jacobson.";
//license "GPL";
author "Rob Murphy";
//function _;
//Input from non-multiplexed axis selector
pin in bit axis0;
pin in bit axis1;
pin in bit axis2;
pin in bit axis3;
//Input from non-multplexed scale selector
pin in bit scale0;
pin in bit scale1;
pin in bit scale2;
//Input from encoder
pin in s32 encoder_counts;
//Selectable jog scale values
param rw float mpg_scale0=1.00;
param rw float mpg_scale1=0.10;
param rw float mpg_scale2=0.01;
//Axis selection
pin out bit enable_axis_x;
pin out bit enable_axis_y;
pin out bit enable_axis_z;
pin out bit enable_axis_a;
//Joint selection
pin out bit enable_joint_0;
pin out bit enable_joint_1;
pin out bit enable_joint_2;
pin out bit enable_joint_3;
//MPG Scale
pin out float axis_mpg_scale;
pin out float joint_mpg_scale;
//Encoder Counts;
pin out s32 axis_encoder_counts;
pin out s32 joint_encoder_counts;
//Error Pins
pin out bit error_select_axis;
pin out bit error_select_scale;
function _;
license "GPL"; // indicates GPL v2 or later
;;
FUNCTION(_){
// Axis & Joint Selection
if (axis0 && !axis1 && !axis2 && !axis3) {
enable_axis_x = 1;
enable_axis_y = 0;
enable_axis_z = 0;
enable_axis_a = 0;
error_select_axis = 0;
}
else if (!axis0 && axis1 && !axis2 && !axis3) {
enable_axis_x = 0;
enable_axis_y = 1;
enable_axis_z = 0;
enable_axis_a = 0;
error_select_axis = 0;
}
else if (!axis0 && !axis1 && axis2 && !axis3) {
enable_axis_x = 0;
enable_axis_y = 0;
enable_axis_z = 1;
enable_axis_a = 0;
error_select_axis = 0;
}
else if (!axis0 && !axis1 && !axis2 && axis3) {
enable_axis_x = 0;
enable_axis_y = 0;
enable_axis_z = 0;
enable_axis_a = 1;
error_select_axis = 0;
}
// Only error if all axis select = 1
else if (axis0 && axis1 && axis2 && axis3) {
enable_axis_x = 0;
enable_axis_y = 0;
enable_axis_z = 0;
enable_axis_a = 0;
error_select_axis = 1;
}
// None selected
else if (!axis0 && !axis1 && !axis2 && !axis3) {
enable_axis_x = 0;
enable_axis_y = 0;
enable_axis_z = 0;
enable_axis_a = 0;
error_select_axis = 0;
}
enable_joint_0 = enable_axis_x;
enable_joint_1 = enable_axis_y;
enable_joint_2 = enable_axis_z;
enable_joint_3 = enable_axis_a;
// MPG Scale selection
if ( scale0 && !scale1 && !scale2 ) {
axis_mpg_scale = mpg_scale0;
error_select_scale = 0;
}
else if ( !scale0 && scale1 && !scale2 ) {
axis_mpg_scale = mpg_scale1;
error_select_scale = 0;
}
else if ( !scale0 && !scale1 && scale2 ) {
axis_mpg_scale = mpg_scale2;
error_select_scale = 0;
}
else if ( scale0 && scale1 && scale2 ) {
axis_mpg_scale = 0;
error_select_scale = 1;
}
else if ( !scale0 && !scale1 && !scale2 ) {
axis_mpg_scale = 0;
error_select_scale = 1;
}
joint_mpg_scale = axis_mpg_scale;
axis_encoder_counts = encoder_counts;
joint_encoder_counts = encoder_counts;
}
And the HAL file
Include your custom HAL commands here
# This file will not be overwritten when you run stepconf again
# This file was modified by R Murphy on Dec 24 2019 12:24:00
# This file was modified by R Murphy on Dec 28 2019 20:38:00
loadrt mpg_pendant
addf mpg-pendant.0 servo-thread
loadrt ilowpass
addf ilowpass.0 servo-thread
setp ilowpass.0.scale 1000
setp ilowpass.0.gain 0.01
setp mpg-pendant.0.mpg-scale0 .001
setp mpg-pendant.0.mpg-scale1 .0001
setp mpg-pendant.0.mpg-scale2 .00001
#net encoder-counts <= ilowpass.0.out
# Encoder count inputs
net jog_counts_in ilowpass.0.in <= hm2_7i92.0.7i73.0.1.enc0.count
net jog_counts_out mpg-pendant.0.encoder-counts <= ilowpass.0.out
# Axis/Joint select inputs
net jora_x_0_select_in mpg-pendant.0.axis0 <= hm2_7i92.0.7i73.0.1.input-10-not
net jora_y_1_select_in mpg-pendant.0.axis1 <= hm2_7i92.0.7i73.0.1.input-12-not
net jora_z_2_select_in mpg-pendant.0.axis2 <= hm2_7i92.0.7i73.0.1.input-14-not
# Scale inputs
net scale_select_0_in mpg-pendant.0.scale0 <= hm2_7i92.0.7i73.0.1.input-11-not
net scale_select_1_in mpg-pendant.0.scale1 <= hm2_7i92.0.7i73.0.1.input-13-not
net scale_select_2_in mpg-pendant.0.scale2 <= hm2_7i92.0.7i73.0.1.input-15-not
# Axis Jogging
# Axis encoder outputs
net axis_counts_out <= mpg-pendant.0.axis-encoder-counts
net axis_counts_out => axis.x.jog-counts
net axis_counts_out => axis.y.jog-counts
net axis_counts_out => axis.z.jog-counts
# Axis x-y-z select
net axis_x_enable_out axis.x.jog-enable <= mpg-pendant.0.enable-axis-x
net axis_y_enable_out axis.y.jog-enable <= mpg-pendant.0.enable-axis-y
net axis_z_enable_out axis.z.jog-enable <= mpg-pendant.0.enable-axis-z
# Axis scale
net axis_scale_out <= mpg-pendant.0.axis-mpg-scale
net axis_scale_out => axis.x.jog-scale
net axis_scale_out => axis.y.jog-scale
net axis_scale_out => axis.z.jog-scale
# Joint Jogging
# Joint encoder outputs
net joint_counts_out <= mpg-pendant.0.joint-encoder-counts
net joint_counts_out => joint.0.jog-counts
net joint_counts_out => joint.1.jog-counts
net joint_counts_out => joint.2.jog-counts
# Joint 0-1-2 select
net joint_0_enable_out joint.0.jog-enable <= mpg-pendant.0.enable-joint-0
net joint_1_enable_out joint.1.jog-enable <= mpg-pendant.0.enable-joint-1
net joint_2_enable_out joint.2.jog-enable <= mpg-pendant.0.enable-joint-2
# Joint scale
net joint_scale_out <= mpg-pendant.0.joint-mpg-scale
net joint_scale_out => joint.0.jog-scale
net joint_scale_out => joint.1.jog-scale
net joint_scale_out => joint.2.jog-scale
Please Log in or Create an account to join the conversation.
I think that this just shows how complex MPG's are
Please Log in or Create an account to join the conversation.
- BeagleBrainz
- Offline
- User is blocked
- Posts: 1437
- Thank you received: 570
Depending on the amount of selector pins there is the possibility of using a diode matrix.
If you have 4 individual inputs for each selector this would reduce to 2.
I don't actually think they are complex, just quite a few inputs to deal with, just a bit of repetition, more than anything else.
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Offline
- Platinum Member
- Posts: 812
- Thank you received: 329
Please Log in or Create an account to join the conversation.
- BeagleBrainz
- Offline
- User is blocked
- Posts: 1437
- Thank you received: 570
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Offline
- Platinum Member
- Posts: 812
- Thank you received: 329
Don't sweat it rodw. I am still very much in my infancy when it comes to programing anything. Some day I hope to actually know what I'm doing.rodw post=213102 userid=20660I wasn't trying to be smart, I just wanted to give more food for thought. Its really good you are working with hal and trying to do some of the harder stuff. There was an example in the docs that I found useful but it still needed some work and converting to the mesa encoders..
I've actually been meaning to take my MPG code and move it into a dedicated hal file so it can be shared
Here is what I came up with excluding the loadrt and addf commands.. Still not sure the ilowpass has been done correct. First time I tried to use it I had a massive crash because 1 click was equal to one metre!
Warning: Spoiler!
# ilowpass filter setp ilowpass.0.scale 10 setp ilowpass.0.gain 0.01 # Setup Jog Pendant on each axis setp axis.x.jog-vel-mode 0 setp axis.y.jog-vel-mode 0 setp axis.z.jog-vel-mode 0 # Scale Select metric (mm) setp mux4.0.in0 0.0 setp mux4.0.in1 1.0 setp mux4.0.in2 0.01 setp mux4.0.in3 0.1 #Axis Select (0=off, 1=x, 2=z, 3=y, na, 5=6, 6=4, 7=5) setp mux8.0.in0 0 setp mux8.0.in1 1 setp mux8.0.in2 2 setp mux8.0.in3 3 setp mux8.0.in4 4 setp mux8.0.in5 5 setp mux8.0.in6 6 setp mux8.0.in7 7 net mux8-sel0 <= hm2_7i76e.0.7i76.0.0.input-23 net mux8-sel1 <= hm2_7i76e.0.7i76.0.0.input-24 net mux8-sel2 <= hm2_7i76e.0.7i76.0.0.input-25 net mux8-sel0 => mux8.0.sel0 net mux8-sel1 => mux8.0.sel1 net mux8-sel2 => mux8.0.sel2 net mux-float conv-float-s32.1.in <= mux8.0.out net mux-s32 <= conv-float-s32.1.out net mux-s32 => select8.0.sel net axis-select-x <= select8.0.out1 net axis-select-y <= select8.0.out3 net axis-select-z <= select8.0.out2 net axis-select-4 <= select8.0.out6 net axis-select-5 <= select8.0.out7 net axis-select-6 <= select8.0.out5 net axis-select-x => axis.x.jog-enable net axis-select-y => axis.y.jog-enable net axis-select-z => axis.z.jog-enable # Encoder counts net jog-counter <= hm2_7i76e.0.7i76.0.0.enc0.count net jog-counter => ilowpass.0.in net smooth-counter <= ilowpass.0.out net jog-counter => axis.x.jog-counts net jog-counter => axis.y.jog-counts net jog-counter => axis.z.jog-counts net mux4-sel1 <= hm2_7i76e.0.7i76.0.0.input-22 net mux4-sel0 <= hm2_7i76e.0.7i76.0.0.input-21 net mux4-sel1 => mux4.0.sel1 net mux4-sel0 => mux4.0.sel0 net jog-scale <= mux4.0.out net jog-scale => axis.x.jog-scale net jog-scale => axis.y.jog-scale net jog-scale => axis.z.jog-scale [/spoiler] Hmm, I wonder where the preview has gone?
Most of my MPG file was sections of my original hal. cut and pasted till I got a dedicated MPG hal. I am still trying to figure out why it works with
a 7i76e board but wont work with my 6i25 / 7i76 combo boards. Oh and thank you and Beaglebrainz both for the other MPG examples .
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Offline
- Platinum Member
- Posts: 812
- Thank you received: 329
I am getting the feeling I just scratched the surface with what you posted here BeagleBrainz. Is their a document I should look into for writing components or is it all listed in the manual somewhere?I got lazy and modified a "all in one user comp" handles all the axis & step selection as well as having separate out pins for the joint & axis select pins. It's a bit rough but I've used it for about a year so far.
[/code]component mpg_pendant "3 Axis Generic MPG"; description "For use with a generic 4 axis chinese ebay pendant inspired by the mpg component of Kurt Jacobson."; //license "GPL"; author "Rob Murphy"; //function _; //Input from non-multiplexed axis selector pin in bit axis0; pin in bit axis1; pin in bit axis2; pin in bit axis3; //Input from non-multplexed scale selector pin in bit scale0; pin in bit scale1; pin in bit scale2; //Input from encoder pin in s32 encoder_counts; //Selectable jog scale values param rw float mpg_scale0=1.00; param rw float mpg_scale1=0.10; param rw float mpg_scale2=0.01; //Axis selection pin out bit enable_axis_x; pin out bit enable_axis_y; pin out bit enable_axis_z; pin out bit enable_axis_a; //Joint selection pin out bit enable_joint_0; pin out bit enable_joint_1; pin out bit enable_joint_2; pin out bit enable_joint_3; //MPG Scale pin out float axis_mpg_scale; pin out float joint_mpg_scale; //Encoder Counts; pin out s32 axis_encoder_counts; pin out s32 joint_encoder_counts; //Error Pins pin out bit error_select_axis; pin out bit error_select_scale; function _; license "GPL"; // indicates GPL v2 or later ;; FUNCTION(_){ // Axis & Joint Selection if (axis0 && !axis1 && !axis2 && !axis3) { enable_axis_x = 1; enable_axis_y = 0; enable_axis_z = 0; enable_axis_a = 0; error_select_axis = 0; } else if (!axis0 && axis1 && !axis2 && !axis3) { enable_axis_x = 0; enable_axis_y = 1; enable_axis_z = 0; enable_axis_a = 0; error_select_axis = 0; } else if (!axis0 && !axis1 && axis2 && !axis3) { enable_axis_x = 0; enable_axis_y = 0; enable_axis_z = 1; enable_axis_a = 0; error_select_axis = 0; } else if (!axis0 && !axis1 && !axis2 && axis3) { enable_axis_x = 0; enable_axis_y = 0; enable_axis_z = 0; enable_axis_a = 1; error_select_axis = 0; } // Only error if all axis select = 1 else if (axis0 && axis1 && axis2 && axis3) { enable_axis_x = 0; enable_axis_y = 0; enable_axis_z = 0; enable_axis_a = 0; error_select_axis = 1; } // None selected else if (!axis0 && !axis1 && !axis2 && !axis3) { enable_axis_x = 0; enable_axis_y = 0; enable_axis_z = 0; enable_axis_a = 0; error_select_axis = 0; } enable_joint_0 = enable_axis_x; enable_joint_1 = enable_axis_y; enable_joint_2 = enable_axis_z; enable_joint_3 = enable_axis_a; // MPG Scale selection if ( scale0 && !scale1 && !scale2 ) { axis_mpg_scale = mpg_scale0; error_select_scale = 0; } else if ( !scale0 && scale1 && !scale2 ) { axis_mpg_scale = mpg_scale1; error_select_scale = 0; } else if ( !scale0 && !scale1 && scale2 ) { axis_mpg_scale = mpg_scale2; error_select_scale = 0; } else if ( scale0 && scale1 && scale2 ) { axis_mpg_scale = 0; error_select_scale = 1; } else if ( !scale0 && !scale1 && !scale2 ) { axis_mpg_scale = 0; error_select_scale = 1; } joint_mpg_scale = axis_mpg_scale; axis_encoder_counts = encoder_counts; joint_encoder_counts = encoder_counts; } And the HAL file [code]Include your custom HAL commands here # This file will not be overwritten when you run stepconf again # This file was modified by R Murphy on Dec 24 2019 12:24:00 # This file was modified by R Murphy on Dec 28 2019 20:38:00 loadrt mpg_pendant addf mpg-pendant.0 servo-thread loadrt ilowpass addf ilowpass.0 servo-thread setp ilowpass.0.scale 1000 setp ilowpass.0.gain 0.01 setp mpg-pendant.0.mpg-scale0 .001 setp mpg-pendant.0.mpg-scale1 .0001 setp mpg-pendant.0.mpg-scale2 .00001 #net encoder-counts <= ilowpass.0.out # Encoder count inputs net jog_counts_in ilowpass.0.in <= hm2_7i92.0.7i73.0.1.enc0.count net jog_counts_out mpg-pendant.0.encoder-counts <= ilowpass.0.out # Axis/Joint select inputs net jora_x_0_select_in mpg-pendant.0.axis0 <= hm2_7i92.0.7i73.0.1.input-10-not net jora_y_1_select_in mpg-pendant.0.axis1 <= hm2_7i92.0.7i73.0.1.input-12-not net jora_z_2_select_in mpg-pendant.0.axis2 <= hm2_7i92.0.7i73.0.1.input-14-not # Scale inputs net scale_select_0_in mpg-pendant.0.scale0 <= hm2_7i92.0.7i73.0.1.input-11-not net scale_select_1_in mpg-pendant.0.scale1 <= hm2_7i92.0.7i73.0.1.input-13-not net scale_select_2_in mpg-pendant.0.scale2 <= hm2_7i92.0.7i73.0.1.input-15-not # Axis Jogging # Axis encoder outputs net axis_counts_out <= mpg-pendant.0.axis-encoder-counts net axis_counts_out => axis.x.jog-counts net axis_counts_out => axis.y.jog-counts net axis_counts_out => axis.z.jog-counts # Axis x-y-z select net axis_x_enable_out axis.x.jog-enable <= mpg-pendant.0.enable-axis-x net axis_y_enable_out axis.y.jog-enable <= mpg-pendant.0.enable-axis-y net axis_z_enable_out axis.z.jog-enable <= mpg-pendant.0.enable-axis-z # Axis scale net axis_scale_out <= mpg-pendant.0.axis-mpg-scale net axis_scale_out => axis.x.jog-scale net axis_scale_out => axis.y.jog-scale net axis_scale_out => axis.z.jog-scale # Joint Jogging # Joint encoder outputs net joint_counts_out <= mpg-pendant.0.joint-encoder-counts net joint_counts_out => joint.0.jog-counts net joint_counts_out => joint.1.jog-counts net joint_counts_out => joint.2.jog-counts # Joint 0-1-2 select net joint_0_enable_out joint.0.jog-enable <= mpg-pendant.0.enable-joint-0 net joint_1_enable_out joint.1.jog-enable <= mpg-pendant.0.enable-joint-1 net joint_2_enable_out joint.2.jog-enable <= mpg-pendant.0.enable-joint-2 # Joint scale net joint_scale_out <= mpg-pendant.0.joint-mpg-scale net joint_scale_out => joint.0.jog-scale net joint_scale_out => joint.1.jog-scale net joint_scale_out => joint.2.jog-scale
Please Log in or Create an account to join the conversation.
- BeagleBrainz
- Offline
- User is blocked
- Posts: 1437
- Thank you received: 570
Just joking.
In all serious there is some info in the online manual, under the hal, section I think, it gives a few basic examples.
Not being familiar with python I tend to lean more towards the C way of doing it. In realty the basics are all that hard, like anything else working out the logic of how to get want you done is the tricky bit.
Halcompile makes things easy, just make sure you have the linuxcnc-dev package installed if you already haven’t. That contains halcomplie and the other bits and pieces needed to build a module.
The good part is in the manual it has examples of how to use halcmd (I hope I got right) to load a module and manipulate it with having to load a full Linuxcnc config.
Please Log in or Create an account to join the conversation.
- my1987toyota
- Topic Author
- Offline
- Platinum Member
- Posts: 812
- Thank you received: 329
Please Log in or Create an account to join the conversation.
linuxcnc.org/docs/devel/html/hal/comp.html
Also review how some of the simplest components are written (eg and2.comp) and play around compiling a couple
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
Please Log in or Create an account to join the conversation.