Add second MPG

More
4 years 6 months ago #239839 by chris@cnc
Add second MPG was created by chris@cnc
i have two MPG, one in operator panel and one mobile.
At the moment is the mobile one connect only. Now i try to connect the second one, but it seems is more difficult as expected.
My idea was to write a custom comp.
I would split the axis select input in master and slave and if master zero will be slave inputs forwarded.
Not so easy are the encoder counts.
I try to add both to one out but forgot that in real time this numbers running real fast to the moon and back.
Next idea is the two s32 encoder input turn back to bit value and in second step count again. So we always count one + one.
But this option is beyond my skills.
Has someone this option running or could give me a hint how to realize it?
 

Please Log in to join the conversation.

More
4 years 6 months ago #239851 by andypugh
Replied by andypugh on topic Add second MPG
Adding the encoder counts together ought to work for jogging, as that works on counts only.

Can you show us your mpg HAL?

Please Log in to join the conversation.

More
4 years 6 months ago #239854 by chris@cnc
Replied by chris@cnc on topic Add second MPG
There are two files. 4-mpg.hal is the old one with mpg in operator panel and 4-mpg-whb.hal is the new mobile mpg.hal.
I was not able to add the encoder count from hm2_7i76e.0.7i84.0.1.enc0.count and whb.axis.x.jog-counts in one axis.x.jog-counts signal. So i keep my old config and wrote a new one for the whb04 handwheel only.

Please Log in to join the conversation.

More
4 years 6 months ago #239860 by andypugh
Replied by andypugh on topic Add second MPG

I was not able to add the encoder count from hm2_7i76e.0.7i84.0.1.enc0.count and whb.axis.x.jog-counts in one axis.x.jog-counts signal. 
How were you adding them? I mean literally adding them together with a sum2 HAL component.
 

Please Log in to join the conversation.

More
4 years 6 months ago #239895 by chris@cnc
Replied by chris@cnc on topic Add second MPG
I try to use sum2. But this use type float and pin whb.axis.x.jog-counts is S32.
./7-second-mpg.hal:39: Signal 'mpg' of type 's32' cannot add pin 'sum2.0.in1' of type 'float'
I take a look inside and basically is the same as my idea but i see my mistake.
I wrote "out0 += in0 + in1;" instead of "out0 = in0 + in1;" and it seems now count properly.
Well, thank you for help. I think now it could be a useful option to include the ilowpass calculation too. I could save a few lines in hal.
 

Please Log in to join the conversation.

More
4 years 6 months ago #239896 by andypugh
Replied by andypugh on topic Add second MPG

I try to use sum2. But this use type float and pin whb.axis.x.jog-counts is S32.
 
Sorry, I had forgotten about that complication. 
You could cast to float, add and convert back with conv_s32_float and conv_float_s32 and that is probably OK for an MPG where you probably don't make more than a few million pulses a day. 
However it sounds like you made a custom component (?) which is a better idea. 

Please Log in to join the conversation.

More
4 years 6 months ago #239928 by chris@cnc
Replied by chris@cnc on topic Add second MPG
Yes, i wrote a custom comp now.
I test it today and seems to work as expected.
I share this comp if someone need. How to use and compile is in mpg.txt descriptions and my hal as example.

Please Log in to join the conversation.

More
4 years 6 months ago #239987 by andypugh
Replied by andypugh on topic Add second MPG
I think that version of the .comp has += where it should be =?

An alternative to your current setup would be to store the state of each switch on each MPG and then output the most recently changed.
That might be more seamless.
Code:
if (old_1_1 != in_1_1) { out_1 = in_1_1; old_1_1 = in_1_1; } if (old_2_1 != in_2_1){ out_1 = in_2_1; old_2_1 = in_1_1; }

(Though I would probably do it with a bitfield, an array of inputs and a loop)

Please Log in to join the conversation.

More
4 years 6 months ago #240014 by chris@cnc
Replied by chris@cnc on topic Add second MPG

I think that version of the .comp has += where it should be =?
 
No, this is the correct one including modified ilowpass lines.
My first idea was simple addition in0 to in6
Code:
FUNCTION(_) {     out0 += in0 + in1 + in2 + in3 + in4 + in6; }
But this "+=" error count very fast to overflow. After see the sum2 function, i realized that must be work in this way.
Code:
FUNCTION(_) {     out0 = in0 + in1 + in2 + in3 + in4 + in6; }
After this was working i want to add the ilowpass function.
Simple test was to replace this term with "in" variable of ilowpass function.
And for my surprise it works...
 

Please Log in to join the conversation.

Time to create page: 0.183 seconds
Powered by Kunena Forum