Advice needed: Custom gear switch component

More
09 Oct 2021 12:08 - 09 Oct 2021 13:00 #222632 by Baderbahn
Hello Guys,

Long time ago a friend gave me a .comp- File which is calculating the gearswitch-movement of the gearbox of my Deckel milling machine.

Yesterday, I installed the component and wired the HAL successfully, but got stuck with the calculation of the choosen gear.
Every time the .comp file just give out the same gear. It seems, that the input-value doesn't get noted.
In Halshow, I checked the Inputs and outputs of the component and saw, that gmoccapy send out the values correctly to the component but the calculation always sends back the same gear (25).
I tried to change a few things, but nothing really works... maybe you are able to find a programming issue ?
I can't getg rid of the feeling, it's just a typo...

Below, you'll find the pinout and calculation section of the .comp file:
//Speed Pins
pin in float speed_in "Eingegebene Drehzahl";                   //programmed speed
pin out float speed_out "Gewählte Getriebedrehzahl";     //choosen speed

//Output Pins
//gearbox block 1
pin out bit block1_1 "Block1 Bit1";
pin out bit block1_2 "Block1 Bit2";
pin out bit block1_3 "Block1 Bit3";

//gearbox block 2
pin out bit block2_1 "Block2 Bit1";
pin out bit block2_2 "Block2 Bit2";
pin out bit block2_3 "Block2 Bit3";

//gearbox intermediate gear
pin out bit vorgelege_1 "Vorgelege Bit1";
pin out bit vorgelege_2 "Vorgelege Bit2";
pin out bit vorgelege_3 "Vorgelege Bit3";

//motor rpm
pin out bit spindle_fast "Hohe Drehzahl";
pin out bit spindle_slow "Niedrige Drehzahl";

//gear switch signal
pin out bit schalten "Umschaltsignal";

FUNCTION (_) {
    // gear ratio of the gearbox
    hal_float_t speed;
    int drehzahl[22] = {0, 25, 31, 40, 50, 63, 80, 100, 125, 160, 200, 250,
                315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500};    
    int i;
    hal_bit_t stufe = 0;
    static hal_bit_t stufe_alt;

    //set value
    speed = speed_in;
    if(speed < 0)
        speed = -speed;

    //calculate gear ratio
    for(i = 0; i < 22; i++){
        if(drehzahl[i] <= speed) stufe = i;     //always choose lower gear ratio
    }
    if(speed > 0 && speed <= 25) stufe = 1;     //special cause: between 0 and 25 always choose 25

    //set all to 0
    block1_1 = FALSE;
    block1_2 = FALSE;
    block1_3 = FALSE;
    block2_1 = FALSE;
    block2_2 = FALSE;
    block2_3 = FALSE;
    vorgelege_1 = FALSE;
    vorgelege_2 = FALSE;
    vorgelege_3 = FALSE;
    spindle_fast = false;
    spindle_slow = false;
    //schalten = false;

    //idle
    if(speed == 0){
        //block1_1 = TRUE;
        //block1_2 = TRUE;
        //block1_3 = TRUE;
        //block2_1 = TRUE;
        //block2_2 = TRUE;
        //block2_3 = TRUE;
        //vorgelege_3 = TRUE;
        stufe = stufe_alt;            //if spindle ist turned off, change nothing
    }

    //intermediate gear
    if(stufe > 0 && stufe < 13)                    vorgelege_2 = TRUE;
    if(stufe >= 13)                            vorgelege_1 = TRUE;

    //BLOCK2
    if((stufe < 7)             || (stufe >= 13 && stufe < 16))    block2_3 = true;
    if((stufe >= 7 && stufe < 10)     || (stufe >= 16 && stufe < 19)) block2_1 = true;
    if((stufe >= 10 && stufe < 13)     || (stufe >= 19))         block2_2 = true;

    //BLOCK1
    i = stufe;
    while(i > 3) i = i - 3;
    if(i == 1)             block1_3 = true;
    if(i == 2)             block1_1 = true;
    if(i == 3)             block1_2 = true;

    //engine rpm
    if(stufe > 0 && stufe < 4)     spindle_slow = true;
    if(stufe >= 4)             spindle_fast = true;

    //switch gears if necessary
    if(stufe != stufe_alt && speed != 0){
        schalten = !schalten;
        stufe_alt = stufe;
    }

    //send back choosen gear ratio
    speed_out = drehzahl[stufe];

ende:
    return;

}




Thanks a lot for your help and best regards,
Simon
Last edit: 09 Oct 2021 13:00 by Baderbahn.

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

More
09 Oct 2021 13:48 #222639 by db1981
is this the whole component? Then it should not compile....

static hal_bit_t stufe_alt; ?? Why declared in the function, so it newer holds the old value.

Why you are using the hal_types in the normal c function? try to use int for stufe and stufe_alt.

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

More
09 Oct 2021 15:25 - 09 Oct 2021 15:26 #222652 by Baderbahn
Hello db1981,

Nearly...
Below you'll finde the complete component (without english description)
component gearswitch "Switch gears";

option singleton yes;

//Speed Pins
pin in float speed_in "Eingegebene Drehzahl";
pin out float speed_out "Gewählte Getriebedrehzahl";

//Output Pins
pin out bit block1_1 "Block1 Bit1";
pin out bit block1_2 "Block1 Bit2";
pin out bit block1_3 "Block1 Bit3";

pin out bit block2_1 "Block2 Bit1";
pin out bit block2_2 "Block2 Bit2";
pin out bit block2_3 "Block2 Bit3";

pin out bit vorgelege_1 "Vorgelege Bit1";
pin out bit vorgelege_2 "Vorgelege Bit2";
pin out bit vorgelege_3 "Vorgelege Bit3";

pin out bit spindle_fast "Hohe Drehzahl";
pin out bit spindle_slow "Niedrige Drehzahl";

pin out bit schalten "Umschaltsignal";

function _ fp "gearswitch";
license "GPL";
author "-";

;;

FUNCTION (_) {
    hal_float_t speed;
    int drehzahl[22] = {0, 25, 31, 40, 50, 63, 80, 100, 125, 160, 200, 250,
                315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500};
    int i;
    hal_bit_t stufe = 0;
    static hal_bit_t stufe_alt;

    //Betrag bilden
    speed = speed_in;
    if(speed < 0)
        speed = -speed;

    //Stufe berechnen
    for(i = 0; i < 22; i++){
        if(drehzahl[i] <= speed) stufe = i;     //immer nächstkleinere Stufe wählen
    }
    if(speed > 0 && speed <= 25) stufe = 1;     //Sonderfall: zwischen 0 und 25rpm auf 25 schalten

    //Alles Nullen
    block1_1 = FALSE;
    block1_2 = FALSE;
    block1_3 = FALSE;
    block2_1 = FALSE;
    block2_2 = FALSE;
    block2_3 = FALSE;
    vorgelege_1 = FALSE;
    vorgelege_2 = FALSE;
    vorgelege_3 = FALSE;
    spindle_fast = false;
    spindle_slow = false;
    //schalten = false;

    //LEERLAUF
    if(speed == 0){
        //block1_1 = TRUE;
        //block1_2 = TRUE;
        //block1_3 = TRUE;
        //block2_1 = TRUE;
        //block2_2 = TRUE;
        //block2_3 = TRUE;
        //vorgelege_3 = TRUE;
        stufe = stufe_alt;            //Bei Abgeschalteter Spindel nichts verändern
    }

    //VORGELEGE
    if(stufe > 0 && stufe < 13)                    vorgelege_2 = TRUE;
    if(stufe >= 13)                            vorgelege_1 = TRUE;

    //BLOCK2
    if((stufe < 7)             || (stufe >= 13 && stufe < 16))    block2_3 = true;
    if((stufe >= 7 && stufe < 10)     || (stufe >= 16 && stufe < 19)) block2_1 = true;
    if((stufe >= 10 && stufe < 13)     || (stufe >= 19))         block2_2 = true;

    //BLOCK1
    i = stufe;
    while(i > 3) i = i - 3;
    if(i == 1)             block1_3 = true;
    if(i == 2)             block1_1 = true;
    if(i == 3)             block1_2 = true;

    //Motorendrehzahl
    if(stufe > 0 && stufe < 4)     spindle_slow = true;
    if(stufe >= 4)             spindle_fast = true;

    //Getriebe Schalten wenn nötig
    if(stufe != stufe_alt && speed != 0){
        schalten = !schalten;
        stufe_alt = stufe;
    }

    //Eingestellte Drehzahl ausgeben
    speed_out = drehzahl[stufe];

ende:
    return;

}



As mentioned before, I've just get the file from a friend ("It worked for me") long time ago.
I'm not deeply intocomponent syntax, so I just checked for logical issues...

You mean, I should use
 int speed;
.
.
.
  
    int stufe_alt;

instead of

 hal_float_t speed;
.
.
.
    static hal_bit_t stufe_alt;
 
Last edit: 09 Oct 2021 15:26 by Baderbahn.

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

More
09 Oct 2021 16:57 #222664 by db1981
this was the error, hal_bit_t is handled intern as bool. So this could never have worked....

I also moved stufe_alt to instance data, so it is hold over the cycle. This is what you normaly want to do with an "old" variable.

I have tested the comp quickly, selecting the gearstages is now working. The rest can't i test, i don't know how your transmission works. but i am missing the spindle twitch (left/right) during gearchange, and the gearchange is not propably locked again spindle turning....
Attachments:

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

More
09 Oct 2021 21:26 #222694 by Baderbahn
Hello db1981,

yeah! It works perfectly ! Thank you verry much for your quick response!

"alt" means "old" in german ;)

The mentioned spindle twitch (Deckel just turns the spindle towards one direction, but changes the oriantation of the gear-switch motors from time to time) and also locking gearchange aggainst the running spindle is done by the "old-fashioned" rellay- setup as done in the original wiring diagram.

Tomorrow, I also will upload my HAL-file in this thread, than the other Deckel users have the chance to reuse it ;)

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

More
10 Oct 2021 07:57 #222719 by db1981
freut mich...

Ich habe auch ne FP4A 2821 aber noch mit Heidenhain TNC355.....
grüße

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

More
11 Oct 2021 19:13 #222865 by Baderbahn
Leider einiges zu tun, die letzten Tage und keine Zeit gefunden, die Files zu von der Maschine zu ziehen.... kommt noch.

Sadly I had a lot to do during the last days... I'll upload the files within the next few days.

Wußte nicht, daß Du auch Deutscher bist :D
Die 2821 ist ja eine ganz späte FP4A. Meine ist von 81 - eine der ersten voll-CNC- Deckels - die mit dem "Eierkopf"

I didn't know, you're also german.
Your 2821 is a pretty late machine - mine is one of the first Deckel CNC machines from '81

regards,
Simon


P.S. Ich schreib Dir 'ne PN, wenn's i.O. ist. habe ein, zwei andere Dinge, die ich noch bzgl. LinuxCNC abklären muß. Auf Deutsch ist das schneller erklärt, als auf Englisch.

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

More
08 Mar 2022 21:43 #236712 by chili023
Hi, would it be possible to get the gearbox .comp. I have a FP4 that I am switching to Linux CNC and your skript would push me into the right direction.

Danke und Grüße

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

More
11 Mar 2022 14:09 #236935 by chris@cnc
The comp is already post number 3.
Copy and paste this script in a new file and named to gearswitch.comp
load the linuxcnc-dev packet
sudo apt-get install linuxcnc-dev
compile file
halcompile --compile gearswitch.comp
install file 
halcompile --install gearswitch.comp
load new comp in your hal file
loadrt gearswitch
addf gearschwitch servo-thread
now you should see all pins in halshow
 
The following user(s) said Thank You: chili023

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

More
14 Mar 2022 18:23 #237222 by db1981
Hello,

the functional comp file is attached in post 4.
don't take the content of post 3, this is with errors.
The following user(s) said Thank You: chili023

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

Time to create page: 0.087 seconds
Powered by Kunena Forum