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

More
8 years 2 months ago #116291 by tecno
Hi Rod,
Still hangs on 'for'

Please Log in to join the conversation.

More
8 years 2 months ago #116292 by tecno

rodw wrote: 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:

Code:
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.


After your edit
Line 46 = mixed declarations
gearengaded is undeclared

Please Log in to join the conversation.

More
8 years 2 months ago #116293 by Hakan
I added the ratios here and started with a very rudimentary error check on the inputs. Also the enable_in/out signal added.
It compiles fine here on "master".
Code:
component gearbox3 "LinuxCNC HAL component for Tecno's gearbox"; author "Rod Webster Hakan Bastedt"; 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 bit enable_in "Enable signal. Input"; pin out bit enable_out "Enable signal. Output"; pin in float speed "Spindle speed in RPM as in Sxxx"; pin out bit gearshift "Need to shift gear, true if high"; pin out s32 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(_) { // Gears are number from 1 (lowest) to 7 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}, }; static double ratios[7] = { 0.064, 0.108, 0.18, 0.3, 0.5, 0.6, 1.0}; // Check which gear to use with this speed Sxxx int geartouse = -1; int i; for (i=0; i<7; i++) { if (speed <= speeds[i][0] && speed > speeds[i][1]) geartouse = i+1; } // Is at least one of the inputs active? Calculate gear from inputs. int inputs_sum = 1*input_a + 2*input_b + 3*input_c + 4*input_d + 5*input_e; int gearengaged; if (higear) gearengaged = inputs_sum + 2; // inputs_sum 4,5 => gear 6,7 else gearengaged = inputs_sum; // inputs_sum 1,2,3,4,5 => gear 1,2,3,4,5 if (inputs_sum > 0 && geartouse == gearengaged) { // Everything ok gearshift = 0; wantedgear = gearengaged; speedratio = ratios[gearengaged-1]; enable_out = enable_in; } else { // Should change gear gearshift = 1; wantedgear = geartouse; speedratio = ratios[geartouse-1]; enable_out = 0; } }
Code:
$ halcompile --compile gearbox3.comp Compiling realtime gearbox3.c Linking gearbox3.so $

Please Log in to join the conversation.

More
8 years 2 months ago #116294 by tecno
Does not compile here on 2.7.14
Code:
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 bit enable_in "Enable signal. Input"; pin out bit enable_out "Enable signal. Output"; pin in float speed "Spindle speed in RPM as in Sxxx"; pin out bit gearshift "Need to shift gear, true if high"; pin out s32 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(_) { // Gears are number from 1 (lowest) to 7 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}, }; static double ratios[7] = { 0.064, 0.108, 0.18, 0.3, 0.5, 0.6, 1.0}; // Check which gear to use with this speed Sxxx int geartouse = -1; int i; for (i=0; i<7; i++) { if (speed <= speeds[i][0] && speed > speeds[i][1]) geartouse = i+1; } // Is at least one of the inputs active? Calculate gear from inputs. int inputs_sum = 1*input_a + 2*input_b + 3*input_c + 4*input_d + 5*input_e; int gearengaged; if (higear) gearengaged = inputs_sum + 2; // inputs_sum 4,5 => gear 6,7 else gearengaged = inputs_sum; // inputs_sum 1,2,3,4,5 => gear 1,2,3,4,5 if (inputs_sum > 0 && geartouse == gearengaged) { // Everything ok gearshift = 0; wantedgear = gearengaged; speedratio = ratios[gearengaged-1]; enable_out = enable_in; } else { // Should change gear gearshift = 1; wantedgear = geartouse; speedratio = ratios[geartouse-1]; enable_out = 0; } }
Code:
bengt@debian:~/linuxcnc/configs/sim.gmoccapy$ halcompile --compile gearbox3.comp make 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/tmpQ__mt1/gearbox3.o gearbox3.comp: In function ‘_’: gearbox3.comp:48:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] Building modules, stage 2. MODPOST 1 modules CC /tmp/tmpQ__mt1/gearbox3.mod.o LD [M] /tmp/tmpQ__mt1/gearbox3.ko make[1]: Leaving directory `/usr/src/linux-headers-3.4-9-rtai-686-pae' bengt@debian:~/linuxcnc/configs/sim.gmoccapy$

Please Log in to join the conversation.

More
8 years 2 months ago #116295 by Hakan
Ok, I think i am a bit C++-centric.

Change
Code:
int geartouse = -1;
to
Code:
int geartouse; geartouse = -1;

Also change the line with inputs_sum.

Please Log in to join the conversation.

More
8 years 2 months ago #116296 by tecno
bengt@debian:~/linuxcnc/configs/sim.gmoccapy$ halcompile --compile 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/tmpMfZqkR/gearbox3.o
gearbox3.comp: In function ‘_’:
gearbox3.comp:42:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
gearbox3.comp:49:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
Building modules, stage 2.
MODPOST 1 modules
CC /tmp/tmpMfZqkR/gearbox3.mod.o
LD [M] /tmp/tmpMfZqkR/gearbox3.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.4-9-rtai-686-pae'
bengt@debian:~/linuxcnc/configs/sim.gmoccapy$

Please Log in to join the conversation.

More
8 years 2 months ago #116299 by Hakan
And move declarations of
Code:
inputs_sum gearengaged
to before the for loop, together with the other declarations.

Please Log in to join the conversation.

More
8 years 2 months ago #116300 by tecno
Now it compiled, did move int i;
FUNCTION(_) {
int i;
Code:
bengt@debian:~/linuxcnc/configs/sim.gmoccapy$ halcompile --compile 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/tmpWxGYMf/gearbox3.o Building modules, stage 2. MODPOST 1 modules CC /tmp/tmpWxGYMf/gearbox3.mod.o LD [M] /tmp/tmpWxGYMf/gearbox3.ko make[1]: Leaving directory `/usr/src/linux-headers-3.4-9-rtai-686-pae' bengt@debian:~/linuxcnc/configs/sim.gmoccapy$

Attachment not found

Please Log in to join the conversation.

More
8 years 2 months ago #116301 by rodw
You guys have still got a type mismatch on this line
Code:
wantedgear = geartouse;
assigning an int to an s32 which is a long. Refer my earlier post.
I've never had a problem with this style in components.
Code:
int geartouse = -1;
IF its not compiling or its generating compiler warnings that a syntax error in your code

Please Log in to join the conversation.

More
8 years 2 months ago #116302 by tecno
But it compiled as per last edits.

Please Log in to join the conversation.

Time to create page: 0.102 seconds
Powered by Kunena Forum