The unsigned integer question #4526
Replies: 3 comments 4 replies
|
With respect to Modbus, any system that uses 64-bit (flag) registers cannot be read using floating point or important information will be lost. It may currently be rare to find these systems, but it is not unheard of in implementations that use read/write-in-depth instead of classic modbus register addressing. Do we distinguish between the sets ℕ and ℤ? Normally, ℕ is a subset of ℤ. But in computers that is not the case with distinct ranges. If we are to abandon unsigned (ℕ), then we should also remove all use of unsigned types in the rest of the code. Arguing that the distinction is immaterial in one case but not the other would be inconsistent IMO. |
|
hal and code are 2 different things. It is called hardware abstraction layer, not hardware access layer. I dont understand where the idea comes from that having hardware registers exposed as hal pins is useful for anything. It is the drivers job to abstract the hardware. in the case with encoders, it scales it to machine units, so it becomes useful. for a vfd, it converts rpm to whatever the vfd needs. linuxcnc does not even have a setting for scaling anything, it is always scaled in the driver. so far, lut5 is the only answer that came up. I am talking about HAL, not about the code. Of course integer types are needed in the code. |
|
Conceding the two examples first: ilowpass and eoffset_per_angle are indeed scale-hack artifacts and would be better as float. I am not defending integer pins where a physical quantity is involved. If the list of integer pins were only those two, I would agree with you. But the original question, "is there any integer pin that can't be a float", still has concrete cases on the table, so let me ask about those directly.
My actual position is narrower than "keep everything": physical quantities should be float, counts and register images should stay integer, and bit patterns should stay unsigned. That gives us float + signed + unsigned, which is what we have. The two-type proposal (float + s64) answers cases 1 through 3 with either lost information or silent truncation, so I am asking: what does it buy that justifies that? |
Uh oh!
There was an error while loading. Please reload this page.
@rene-dev about the signed and unsigned integer use, these are what I found.
encoder.N.counts => joint.N.jog-counts(s32 to s32): every MPG pendant configuration. In-tree alone: woodpecker mpg.hal, touchy, shuttle, xhc-hb04, and pico pendant.hal (rawcounts via ilowpass, s32 throughout). Motion's jog protocol is an exact per-cycle count delta (control.c:1066).iocontrol.0.tool-prep-number: axis_manualtoolchange.hal is pulled in by 50 in-tree inis, and smithy/924.hal nets it into classicladder s32 word logic on shipped commercial machines.Unsigned: hm2_modbus (in 2.9) maps raw device registers to pins, including 64-bit unsigned compounds (
hal_pin_u64_newf, plus a u64.offsettare doing modulo-2^64 subtraction). A totalizer register above 2^53 loses bits on a float pin; the range [2^63, 2^64) reads negative on s64. The pin is the user-facing register image, so "keep it driver-internal" does not apply.Bit patterns: hm2
raw.write-dataand bitwise (u32 pins), plus lut5 (stepconf generatessetp lut5.0.function 0x10000, a u32 param). On an integer pin, NaN and 2.5 are unrepresentable; todaysetp <int-pin> nanis rejected whilesetp <float-pin> nansucceeds, and(int32_t)NaNis 0x80000000 straight into an FPGA register. No driver checks isnan; the type is the guard.All reactions