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

More
17 Aug 2018 20:31 #116219 by Hakan

Hmmm looking at .comp we have this

case 1: // Gear E
gear = (high_gear != 0) ? 5 : 10;
break;

Should it not be like this then? Hi gear is 5 and Lo gear is 10 right?

setp gearblocker.0.gear.10.min-speed 80

Sure somebody will correct us ;)

Think you found a bug there.
This is one of those areas where it is soo easy to make a problem. Index starting at 0 or 1.
Uhhm. I think you can replace the whole case-switch block with
gear = input_1 + 2*input_B + 3*input_C + 4*input_D + 5*input_E + 5*high_gear -1;
This will directly calculate the engaged gear. You promise only one of the input_ABCDE is engaged at any given time?
The -1 is to make the indexing into speed_max, etc zero-based.

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

More
17 Aug 2018 20:32 #116220 by Hakan

Is this correct?
#GearShift Lo
# E gear
setp gearblocker.0.gear-E.min-speed 80
setp gearblocker.0.gear-E.max-speed 160
setp gearblocker.0.gear-E.ratio 0.064  
# D gear
setp gearblocker.0.gear-D.min-speed 160
setp gearblocker.0.gear-D.max-speed 270
setp gearblocker.0.gear-D.ratio 0.108 
# C gear
setp gearblocker.0.gear-C.min-speed 270
setp gearblocker.0.gear-C.max-speed 450
setp gearblocker.0.gear-C.ratio 0.18 
# B gear
setp gearblocker.0.gear-B.min-speed 450
setp gearblocker.0.gear-B.max-speed 750
setp gearblocker.0.gear-B.ratio 0.3 
# A gear
setp gearblocker.0.gear-A.min-speed 750
setp gearblocker.0.gear-A.max-speed 1250
setp gearblocker.0.gear-A.ratio 0.5 

#GearShift Hi
#B gear
setp gerablocker.0.high_gear.gear-B.min-speed 1250
setp gerablocker.0.high_gear.gear-B.max-speed 11500
setp gearblocker.0.high_gear.gear-B.ratio 0.6
#A gear
setp gerablocker.0.high_gear.gear-A.min-speed 1250
setp gerablocker.0.high_gear.gear-A.max-speed 11500
setp gearblocker.0.high_gear.gear-A.ratio 1


You can test in a hal file to see if the syntax is correct.
But there are no pins called what you write above. Didn't it work in the way I wrote it?

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

More
18 Aug 2018 00:29 #116228 by andypugh
On holiday and on the phone, so quoting is difficult.

The gears probably are switched,yes. As i explained I did it at lunchtime in a widows pc at work. It is entirely untested.

There are other ways to do it. I chose the switch block to explicitly reject invalid gear selections.
The single line calculation returns gear 5 if both B and C are selected. And that seems something to reject.

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

More
18 Aug 2018 10:42 #116242 by tecno
Relax and have fun on your holiday.

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

More
18 Aug 2018 10:44 #116243 by tecno
So down in my shop and trying to install linuxcnc-dev but no-go in my Mint installation. Need to get my comp file working.

Any clues what can be wrong?

sudo apt-get install linuxcnc-dev is what I try to use

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

More
18 Aug 2018 11:10 #116246 by tecno
Hmmm appears o be installed but again errors

bengt@CombiMll ~/linuxcnc/configs/CM_GEARBOX $ sudo halcompile --compile gearbox3.comp
Traceback (most recent call last):
File "/usr/bin/halcompile", line 1353, in <module>
main()
File "/usr/bin/halcompile", line 1322, in main
process(f, mode, outfile)
File "/usr/bin/halcompile", line 1192, in process
a, b = parse(filename)
File "/usr/bin/halcompile", line 417, in parse
a, b = f.split("\n;;\n", 1)
ValueError: need more than 1 value to unpack


Can you guys see what is wrong in the comp file

File Attachment:

File Name: gearbox3.comp
File Size:2 KB


Cheers
Bengt
Attachments:

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

More
18 Aug 2018 16:30 #116276 by tecno
Some progress, fixed some typos and now it complaints about this on line 12. We are making progress

pin out int wantedgear "Shift to this gear if told so";

Something with int
component gearbox3 "LinuxCNC HAL component for Tecno's gearbox";
author "Rod Webster Håkan Båstedt";

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 higear       "true if in high gear";
pin   in float speed      "Spindle speed in RPM as in Sxxx";
pin   out bit gearshift   "Need to shift gear, true if high";
pin   out int wantedgear  "Shift to this gear if told so";
pin   out float speedratio "max RPM for machine divided by maximum RPM for gear";
param rw  float maxrpm     "maximum RPM for machine";


function _;
license "GPL";
;;

#include <rtapi_math.h>


FUNCTION(_) {

    static double speeds[7][2] = {
        { 160.0, 80.0}
        { 270.0, 160.0},
        { 450.0, 270.0},
        { 750.0, 450.0},
        {1250.0, 750.0},
        {1500.0, 1250.0},
        {2500.0, 1500.0},
    };
    // Gears are number from 1 (lowest) to 7
    
    // Check which gear to use with this speed Sxxx
    int geartouse = -1;
    for (int i=0; i<7; i++) {
       if (speed <= speeds[i][0] && speed > speeds[i][1])
     geartouse = i+1;
    }

    // Which gear is engaged
    int gearengaged = 1*input_a + 2*input_b + 3*input_c + 4*inpud_d + 5*input_e + 5*higear;

    if (geartouse == gearengaged) { // Everything ok
      gearshift = 0;
      wantedgear = gearengaged;
      speedratio = speed/speeds[gearenaged-1][0];
    } else {                        // Should change gear
      gearshift = 1;
      wantedgear = geartouse;
      speedratio = speed/speeds[geartouse-1][0];
    }
}

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

More
18 Aug 2018 21:50 - 18 Aug 2018 21:58 #116283 by Hakan
I also want to claim the holiday reason :)
I think it is the "int" that is wrong, There seems to be no such datatype for hal pins.
Either "s32" or "u32" for signed or unsigned integer.
Chose "s32" so you can have -1 for "no suitable gear found".

Regarding the gear calculation. The one-line way doesn't add any
failure protection. If that is important, you need to expand on that.
Andy's way may be better. You have to see and judge what is important
for you.
Last edit: 18 Aug 2018 21:58 by Hakan.

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

More
19 Aug 2018 05:57 #116288 by tecno
No worries here Håkan, I appreciate all the help I can get. Made some progress now for loop error.

File Attachment:

File Name: gearbox3_2...-19.comp
File Size:2 KB

bengt@debian:~/linuxcnc/configs/sim.gmoccapy$ halcompile --install gearbox3.compmake KBUILD_EXTRA_SYMBOLS=/usr/realtime-3.4-9-rtai-686-pae/modules/linuxcnc/Module.symvers -C /usr/src/linux-headers-3.4-9-rtai-686-pae SUBDIRS=`pwd` CC=gcc V=0 modules
make[1]: Entering directory `/usr/src/linux-headers-3.4-9-rtai-686-pae'
  CC [M]  /tmp/tmpxFPQ1m/gearbox3.o
gearbox3.comp: In function ‘_’:
gearbox3.comp:39:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
gearbox3.comp:39:5: note: use option -std=c99 or -std=gnu99 to compile your code
gearbox3.comp:45:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
gearbox3.comp:50:33: error: ‘gearenaged’ undeclared (first use in this function)
gearbox3.comp:50:33: note: each undeclared identifier is reported only once for each function it appears in
make[4]: *** [/tmp/tmpxFPQ1m/gearbox3.o] Fel 1
make[3]: *** [_module_/tmp/tmpxFPQ1m] Fel 2
make[2]: *** [sub-make] Fel 2
make[1]: *** [all] Fel 2
make[1]: Leaving directory `/usr/src/linux-headers-3.4-9-rtai-686-pae'
make: *** [modules] Fel 2
bengt@debian:~/linuxcnc/configs/sim.gmoccapy$ 
Attachments:

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

More
19 Aug 2018 06:33 - 19 Aug 2018 06:36 #116290 by rodw
Its best practice to define variables at the head of the function. The exception might be if you have a low memory environment.
I don't think the halcompile environment likes a definition of the loop variable in the for statement. Also you are mixing types by assigning an int (geartouse) to a long (eg. S32) so try this:
FUNCTION(_) {

    static double speeds[7][2] = {
        { 160.0, 80.0},
        { 270.0, 160.0},
        { 450.0, 270.0},
        { 750.0, 450.0},
        {1250.0, 750.0},
        {1500.0, 1250.0},
        {2500.0, 1500.0},
    };
    // Gears are number from 1 (lowest) to 7
    
    // Check which gear to use with this speed Sxxx
    long geartouse = -1;
    int i;
    for (i=0; i<7; i++) {
       if (speed <= speeds[i][0] && speed > speeds[i][1])
     geartouse = (long) i+1L;
    }

    // Which gear is engaged
    int gearengaged = 1*input_a + 2*input_b + 3*input_c + 4*input_d + 5*input_e + 5*higear;

    if (geartouse == gearengaged) { // Everything ok
      gearshift = 0;
      wantedgear = gearengaged;
      speedratio = speed/speeds[gearenaged-1][0];
    } else {                        // Should change gear
      gearshift = 1;
      wantedgear = geartouse;
      speedratio = speed/speeds[(int)geartouse-1][0];
    }
}

I'm not sure if halcompile will like 1L which signifies 1 is a long type. If it complains, try "(long) 1" instead

OOPS just edited as an explicit typedef is required on the line where speedratio is defined.
Last edit: 19 Aug 2018 06:36 by rodw. Reason: OOPS just edited as an explicit typedef is required on the line where speedratio is defined.

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

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