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

More
19 Aug 2018 10:27 #116304 by Hakan
Int and long is not a problem, there is automatic casting as needed.

And in this environment an int is 4 bytes = length of s32.

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

More
19 Aug 2018 11:17 #116305 by rodw
int is 16 bits
long is 32 bits (which is where the 32 comes from in S32)

I'm not really sure how halcompile modifies things with S32 data types. In most computer architectures, the low order 16 bits of a 32 bit variable are usually compatible with a 16 bit variable so its probably OK.

Over the years I've learnt to obsess over getting the typdefs 100% right and use implicit type declarations to convert between types without leaving it to chance as you can get bitten.

The other gotcha is assigning values to longs (hence the L modifier eg 0L) to make sure the compiler gets the full 32 bit value. I have been caught with code where the L is omitted hence my caution. Always treat compiler warnings as potential errors.

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

More
19 Aug 2018 12:47 #116306 by tecno
OK, so I got the comp installed on my milling machine but something is wrong. Can you guys see what is wrong here?
I was off by one digit on my inputs in HAL ;) but now corrected.

In picture below I have higear + input_b but only input pins on 7i76e shows nothing in gearcomp3



component gearcomp3 "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(_) {
  int i;
  int inputs_sum;
  int gearengaged;
  int geartouse;
  
  // 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
  geartouse = -1;
  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.
  inputs_sum = 1*input_a + 2*input_b + 3*input_c + 4*input_d + 5*input_e;
  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;
  }
}
Attachments:

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

More
19 Aug 2018 14:31 #116309 by Hakan
Rod, you must come from the embedded environment because in Intel Linux an int has been 32 bit wide since the beginning and still is today when 64-bit cpus are the norm.
Int doesn't have a standard width one can always rely on. On 8-bits microcomputers they can be 16-bits wide but it is entirely compiler dependent.

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

More
19 Aug 2018 14:38 #116310 by Hakan

OK, so I got the comp installed on my milling machine but something is wrong. Can you guys see what is wrong here?
I was off by one digit on my inputs in HAL ;) but now corrected.

In picture below I have higear + input_b but only input pins on 7i76e shows nothing in gearcomp3



component gearcomp3 "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(_) {
  int i;
  int inputs_sum;
  int gearengaged;
  int geartouse;
  
  // 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
  geartouse = -1;
  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.
  inputs_sum = 1*input_a + 2*input_b + 3*input_c + 4*input_d + 5*input_e;
  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;
  }
}


Looks Ok given the input. The component want you to change gear but doesn't know to which gear, since the speed is zero,
But I see input-as, they are all zero,. Can you show the relevant parts of the hal file with loadrrt, addf and all signals where gearbox3 is involved?

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

More
19 Aug 2018 14:40 #116311 by tecno

File Attachment:

File Name: cb_gearbox...8-19.hal
File Size:17 KB
Attachments:

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

More
19 Aug 2018 14:41 #116312 by tecno
loadrt trivkins
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hostmot2
loadrt hm2_eth board_ip="10.10.10.10"
setp hm2_7i76e.0.watchdog.timeout_ns 5000000
loadrt pid names=pid.x,pid.y,pid.z,pid.a,pid.s
loadrt charge_pump
loadrt timedelay names=brake_delay
loadrt and2 count=4
loadrt xor2 count=2
loadrt or2 count=1
loadrt siggen num_chan=2
loadrt gearcomp3

addf charge-pump servo-thread
addf hm2_7i76e.0.read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf pid.x.do-pid-calcs servo-thread
addf pid.y.do-pid-calcs servo-thread
addf pid.z.do-pid-calcs servo-thread
addf pid.a.do-pid-calcs servo-thread
addf pid.s.do-pid-calcs servo-thread
#addf jogincr servo-thread
addf hm2_7i76e.0.write servo-thread
addf brake_delay servo-thread
addf and2.0 servo-thread
addf and2.1 servo-thread
addf and2.2 servo-thread
addf and2.3 servo-thread
addf xor2.0 servo-thread
addf xor2.1 servo-thread
addf or2.0 servo-thread
addf siggen.0.update servo-thread
addf siggen.1.update servo-thread
addf gearcomp3.0 servo-thread

# gearbox input signals
# gearbox Hi/Lo
net gearcomp3.0.high-gear <= hm2_7i76e.0.7i76.0.0.input-14

# gearbox A - B - C - D - E
net gearcomp3.0.input_a <= hm2_7i76e.0.7i76.0.0.input-09
net gearcomp3.0.input_b <= hm2_7i76e.0.7i76.0.0.input-10
net gearcomp3.0.input_c <= hm2_7i76e.0.7i76.0.0.input-11
net gearcomp3.0.input_d <= hm2_7i76e.0.7i76.0.0.input-12
net gearcomp3.0.input_e <= hm2_7i76e.0.7i76.0.0.input-13

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

More
19 Aug 2018 14:43 - 19 Aug 2018 14:44 #116313 by tecno
Found a typo
net gearcomp3.0.high-gear >>>> net gearcomp3.0.higear
Last edit: 19 Aug 2018 14:44 by tecno.

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

More
19 Aug 2018 14:43 #116314 by tecno

Found a typo
net gearcomp3.0.high-gear >>>> net gearcomp3.0.higear

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

More
19 Aug 2018 14:45 - 19 Aug 2018 14:47 #116315 by Hakan
As far as I can see this is wrong
# gearbox input signals
# gearbox Hi/Lo
net gearcomp3.0.high-gear  <=  hm2_7i76e.0.7i76.0.0.input-14

# gearbox A - B - C - D - E
net gearcomp3.0.input_a  <=  hm2_7i76e.0.7i76.0.0.input-09
net gearcomp3.0.input_b  <=  hm2_7i76e.0.7i76.0.0.input-10
net gearcomp3.0.input_c  <=  hm2_7i76e.0.7i76.0.0.input-11
net gearcomp3.0.input_d  <=  hm2_7i76e.0.7i76.0.0.input-12
net gearcomp3.0.input_e  <=  hm2_7i76e.0.7i76.0.0.input-13

You think you use the gearbox3 names, but in fact you are naming signals gearbox3.0.something
Do like this
# gearbox input signals
# gearbox Hi/Lo
net high-gear-signal => gearcomp3.0.high-gear  <=  hm2_7i76e.0.7i76.0.0.input-14

# gearbox A - B - C - D - E
net input-a-signal => gearcomp3.0.input_a  <=  hm2_7i76e.0.7i76.0.0.input-09
net input-b-signal => gearcomp3.0.input_b  <=  hm2_7i76e.0.7i76.0.0.input-10
net input-c-signal => gearcomp3.0.input_c  <=  hm2_7i76e.0.7i76.0.0.input-11
net input-d-signal => gearcomp3.0.input_d  <=  hm2_7i76e.0.7i76.0.0.input-12
net input-e-signal => gearcomp3.0.input_e  <=  hm2_7i76e.0.7i76.0.0.input-13

Name them according to your taste and watch out for any spelling errors on my part.
Last edit: 19 Aug 2018 14:47 by Hakan.

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

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