Help needed to get my 7i76E + 7i85S + 7i73 on my mill going.

More
23 Dec 2017 17:41 #103490 by tecno
once you resolve lut 5 to a speed = speedrange is more what I am looking for.

Will read up on LUT5, thank´s Rod

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

More
23 Dec 2017 18:28 #103492 by rodw
After a bit of reading myself, maybe LUT5 is not the answer.
A custom written component would make it trivial though.

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

More
23 Dec 2017 18:32 #103493 by tecno
OK, for those with the knowledge but for a beginner like me you are talking utopia ;)

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

More
23 Dec 2017 19:42 - 23 Dec 2017 19:46 #103494 by rodw
Try this. Totally untested of course... but it does compile with halcompile.
component gearbox "LinuxCNC HAL component for Techno's gearbox";

author "Rod Webster";

pin in  bit input_a     "input a";
pin in  bit input_b     "input b";
pin in  bit input_c     "input c";
pin in  bit input_d     "input d";
pin in  bit input_e     "input e";
pin in  bit gear_shift  "gear shift, true if high";
pin in  bit higear      "true if in high gear";
pin out float speed     "speed in RPM";
   

function _;
license "GPL";
;;

#include <rtapi_math.h>


FUNCTION(_) {
    static double speedarray[4][5] = {
        {2500.0, 1500.0, 900.0, 540.0, 325.0},
        {1500.0, 900.0,  540.0, 325.0, 195.0},
        {1250.0, 750.0,  450.0, 270.0, 160.0},
        { 750.0, 450.0,  270.0, 160.0, 100.0}
    };
    int idx;
    
    idx  = (higear) ? 0:1 +  (gear_shift) ? 0:2;
    if(input_a)
        speed = speedarray[idx][0];
    if(input_b)
        speed = speedarray[idx][1];
    if(input_c)
        speed = speedarray[idx][2];
    if(input_d)
        speed = speedarray[idx][3];
    if(input_e)
        speed = speedarray[idx][4];
}

To install type
halcompile --install gearbox.comp
then loadrt and addf as per normal Just set your inputs for each gear. Have a look at the pins in halshow first, They should be input-a... input-e

Setting idx is not intuitive as it uses C's ternary operator. Basically, one value decides if it is based at row 0 or row 2 and the next decides if it should read that row or the next one.

Writing Components is LinuxCNC's best kept secret.

File Attachment:

File Name: gearbox.comp
File Size:1 KB
Attachments:
Last edit: 23 Dec 2017 19:46 by rodw.

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

More
23 Dec 2017 19:57 #103495 by tecno
WOW
Thanks Rod but I need some clarification to understand.

pin in bit input_a "input a"; Is pin in =hm2_7i76e.0.7i76.0.0.input-10 (net input_a hm2........)

Hi range {2500.0, 1500.0, 900.0, 540.0, 325.0}, = A, B, C, D, E
{1500.0, 900.0, 540.0, 325.0, 195.0}, = A, B, C, D, E

Lo range {1250.0, 750.0, 450.0, 270.0, 160.0}, = A, B, C, D, E
{ 750.0, 450.0, 270.0, 160.0, 100.0} = A, B, C, D, E

loadart and addf = gearbox ??

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

More
23 Dec 2017 20:17 #103496 by rodw
Bengt,

Once you install the component with halcompile, it is like any other standard LinuxCNC component so yes, it will be something like this
loadrt gearbox
addf gearbox servo-thread
net gear-a <= hm2_7i76e.0.7i76.0.0.input-10
net gear-a => gearbox.input-a

Just be aware that the underscores '_' in pin names become hyphens '-' in HAL which is why I suggest using halshow to see with your own eyes the pin names.

The only other thing to consider is that I made the speed output to be a float. If it needs to be a s32 or a u32 in Hal, we will need to change the type in the C code.

And yes, I made the array the same format as your spreadsheet so you have it correct.

Hopefully, the code will select the right row of values. if the gear-shift pin = 1 (true) then it should select either row 0 or 1 depending on the value of the higear pin. If gear-shift is false, it should select rows 2 or 3. You may need to add a checkbox to your GUI for one of these pins.

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

More
23 Dec 2017 20:52 #103497 by tecno
Will try to give this a whirl tomorrow if possible.
Thanks and have a peaceful Christmas.

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

More
23 Dec 2017 22:17 #103499 by andypugh

Have a look at lut5 as that gives you 5 bits of input.


It is probably something you could do with a mux. You need 5 input bits so probably mux_generic using “ff32”

You could just connect each sensor to a select bit, set the inputs to 1,2,3 etc and see what output you get for each selector position, then change them.

This doesn’t get as far as what you do with the numbers when you have them, though.

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

More
23 Dec 2017 23:31 #103500 by rodw

Have a look at lut5 as that gives you 5 bits of input.


It is probably something you could do with a mux. You need 5 input bits so probably mux_generic using “ff32”


I did think of a mux but thought I was short a few bits. I had forgotten about mux_generic to get more.

I also thought of adding a separate parameter for each gear ratio rather than a hard coded array. I might have done this if the hi/lo ratios could have been locked down to a simple multiple of the base ratio but that did not appear to be the case.

I think sometimes a custom component is very efficient and results in much easier to maintain and understand hal files. This is a good candidate for it as writing the component probably took no more time than cobbling all the required hal components together.

Prospective LCNC integrators would be well advised to play with an Arduino to gain a smattering of C and maybe do the Google python course as it adds so much more flexibility to your problem solving ability. That's my thoughts anyway.

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

More
24 Dec 2017 07:09 #103524 by tecno

I might have done this if the hi/lo ratios could have been locked down to a simple multiple of the base ratio but that did not appear to be the case.


Lo is 50% of Hi or do I misunderstand this?

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

Moderators: cmorley
Time to create page: 0.138 seconds
Powered by Kunena Forum