Modbus input for absolute encoder position?
13 Dec 2019 15:52 - 13 Dec 2019 15:55 #152606
by 0x2102
Replied by 0x2102 on topic Modbus input for absolute encoder position?
Ran a test qModMaster to see the RAW data and they are not signed. I can not adjust the range.
RAW Capture:
Positive values
[TCP]>Tx > 16:35:10:639 - 00 A3 00 00 00 06 01 03 08 44 00 01
[TCP]>Rx > 16:35:10:644 - 00 A3 00 00 00 05 01 03 02 00 06
Value: 00 06 = 6
Negative values:
[TCP]>Tx > 16:30:28:065 - 00 88 00 00 00 06 01 03 08 44 00 01
[TCP]>Rx > 16:30:28:070 - 00 88 00 00 00 05 01 03 02 FF FC
Value: FF FC = 65532 (65535 -65532= -3)
Found this note below that might explain why some ModBus implementations like ModPoll interpret the number differently - in my case correct.
Quote from MinimalModBus Website:
Negative numbers (INT16 = short)
Some manufacturers allow negative values for some registers. Instead of an allowed integer range 0-65535, a range -32768 to 32767 is allowed. This is implemented as any received value in the upper range (32768-65535) is interpreted as negative value (in the range -32768 to -1).
I did set up something that somehow works but not great yet.
MB2MAL axis load data -> Mux2.in0
MB2MAL axis load data -> Offset (-65535) -> Mux2.in1
stepgen.00.velocity-fb -> Abs.in to determine if X is going positive or negative direction -> used as selection pin for Mux2
This is working but when changing directions I get spikes in the 65000 range - instead of 20 - 100 for normal load. Especially with short moves I get spike all the time. Probably a timing issue between ModBus data (too slow) and the direction change signal.
RAW Capture:
Positive values
[TCP]>Tx > 16:35:10:639 - 00 A3 00 00 00 06 01 03 08 44 00 01
[TCP]>Rx > 16:35:10:644 - 00 A3 00 00 00 05 01 03 02 00 06
Value: 00 06 = 6
Negative values:
[TCP]>Tx > 16:30:28:065 - 00 88 00 00 00 06 01 03 08 44 00 01
[TCP]>Rx > 16:30:28:070 - 00 88 00 00 00 05 01 03 02 FF FC
Value: FF FC = 65532 (65535 -65532= -3)
Found this note below that might explain why some ModBus implementations like ModPoll interpret the number differently - in my case correct.
Quote from MinimalModBus Website:
Negative numbers (INT16 = short)
Some manufacturers allow negative values for some registers. Instead of an allowed integer range 0-65535, a range -32768 to 32767 is allowed. This is implemented as any received value in the upper range (32768-65535) is interpreted as negative value (in the range -32768 to -1).
I did set up something that somehow works but not great yet.
MB2MAL axis load data -> Mux2.in0
MB2MAL axis load data -> Offset (-65535) -> Mux2.in1
stepgen.00.velocity-fb -> Abs.in to determine if X is going positive or negative direction -> used as selection pin for Mux2
This is working but when changing directions I get spikes in the 65000 range - instead of 20 - 100 for normal load. Especially with short moves I get spike all the time. Probably a timing issue between ModBus data (too slow) and the direction change signal.
Last edit: 13 Dec 2019 15:55 by 0x2102.
Please Log in or Create an account to join the conversation.
13 Dec 2019 16:02 #152608
by andypugh
Replied by andypugh on topic Modbus input for absolute encoder position?
Use the "bitslice" component to detect when bit15 is set instead. (and make sure that the bitslice is earlier in the thread list than the mux2 is)
You could probably use "comp" instead. Though really this feels like it should be configurable inside mb2hal
You could probably use "comp" instead. Though really this feels like it should be configurable inside mb2hal
Please Log in or Create an account to join the conversation.
13 Dec 2019 16:59 #152611
by 0x2102
Replied by 0x2102 on topic Modbus input for absolute encoder position?
You made my day Andy. Working, with bitslice as the input select pin.
Agree, it would be great if MB2HAL would allow configuration for that.
Thanks!
Agree, it would be great if MB2HAL would allow configuration for that.
Thanks!
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 5000
- Thank you received: 1409
13 Dec 2019 18:11 #152612
by Todd Zuercher
Replied by Todd Zuercher on topic Modbus input for absolute encoder position?
Mb2hal, is a rather crude tool. I found myself running much of what it reads through Classicladder to deal with similar issues.
Please Log in or Create an account to join the conversation.
15 Dec 2019 19:45 #152695
by andypugh
Should it be a config thing, in the INI, or would it be as good to add extra HAL pins that present the data as signed values?
I am also curious about the scale and offset pins that exist in the source-code for MB2HAL, but are commented out.
Replied by andypugh on topic Modbus input for absolute encoder position?
Agree, it would be great if MB2HAL would allow configuration for that.
Should it be a config thing, in the INI, or would it be as good to add extra HAL pins that present the data as signed values?
I am also curious about the scale and offset pins that exist in the source-code for MB2HAL, but are commented out.
Please Log in or Create an account to join the conversation.
15 Dec 2019 20:57 #152697
by 0x2102
Replied by 0x2102 on topic Modbus input for absolute encoder position?
I think for me personally it wouldn't matter and both options would be fine. As long as there is a way to configure it per transaction.
I am still looking into the absolute encoder position with MB2HAL but I will wait until I have my new milling machine next week. Initial tests were just on my bench. Funny thing for the absolute encoder trial, MB2HAL behaved in my favor this time - as it counts 0-65536. Tools like ModPoll would read 32768 to 0 (half turn) and then -32768 to 0 again for the other half turn.
I am still looking into the absolute encoder position with MB2HAL but I will wait until I have my new milling machine next week. Initial tests were just on my bench. Funny thing for the absolute encoder trial, MB2HAL behaved in my favor this time - as it counts 0-65536. Tools like ModPoll would read 32768 to 0 (half turn) and then -32768 to 0 again for the other half turn.
Please Log in or Create an account to join the conversation.
18 Feb 2020 21:33 #157762
by 0x2102
Hello,
wanted to provide a quick update and ask a question. I did exactly as suggested by Andy. All working but there is one remaining issue.
The sum2.M.in1 (encoder.N.position) or in my case (stepgen.00.position-fb) is "0" when I start LinuxCNC for the first time. Machine on triggers the sample hold. Then I jog the machine in X +50mm and set machine to off. When I turn it back on the position is off by 50mm.
The encoder.N.position or stegen.00.position-fb counters remains at 50.00000mm or whatever value it has and does not reset to 0 between machine off and on. Sum2.M adds the actual absolute encoder position + the encoder.N.position stored for the new absolute position.
Example:
Turn on machine: x-pos = 200mm + 0 = 200mm, jog X+ 50mm, turn off machine -> new x-pos = 250 + 50 = 300 but the real position is 250.
I might be able to add a mux2 or use an offset to subtract the encoder value but maybe someone has another idea. I already have to use quite a # of rt modules: offset, abs, conv_float_s32, sample_hold, conv_s32_float, 2 x sum2 to make it work and I am starting to see "Insufficient memory for pin.." warnings.
Replied by 0x2102 on topic Modbus input for absolute encoder position?
...
full-turns -> convert to float
initial counts -> convert to float
turns and counts -> sum2, turns scaled by 65536
sum2.N.out -> sample-hold.0.in
(Magic here to latch the sample-hold)
sample-hold.0.out -> sum2.M.in0 (gain 1)
encoder.N.position -> sum2.M.in1 (gain 1)
sum2.M.out -> PID feedback, axis position feedback, etc.
Then specify HOME_ABSOLUTE_ENCODER in the INI.
Hello,
wanted to provide a quick update and ask a question. I did exactly as suggested by Andy. All working but there is one remaining issue.
The sum2.M.in1 (encoder.N.position) or in my case (stepgen.00.position-fb) is "0" when I start LinuxCNC for the first time. Machine on triggers the sample hold. Then I jog the machine in X +50mm and set machine to off. When I turn it back on the position is off by 50mm.
The encoder.N.position or stegen.00.position-fb counters remains at 50.00000mm or whatever value it has and does not reset to 0 between machine off and on. Sum2.M adds the actual absolute encoder position + the encoder.N.position stored for the new absolute position.
Example:
Turn on machine: x-pos = 200mm + 0 = 200mm, jog X+ 50mm, turn off machine -> new x-pos = 250 + 50 = 300 but the real position is 250.
I might be able to add a mux2 or use an offset to subtract the encoder value but maybe someone has another idea. I already have to use quite a # of rt modules: offset, abs, conv_float_s32, sample_hold, conv_s32_float, 2 x sum2 to make it work and I am starting to see "Insufficient memory for pin.." warnings.
![:) :)](/media/kunena/emoticons/smile.png)
Please Log in or Create an account to join the conversation.
24 Feb 2020 19:18 #158413
by andypugh
I am surprised that you are that close to the pin memory limit.
One answer might be a custom HAL component. If you can write C code at all then this fairly easy.
linuxcnc.org/docs/2.7/html/hal/comp.html
Or you could try just not turning off the machine![:-) :-)](/media/kunena/emoticons/smile.png)
Actually, it sounds like you need to trigger the sample-hold with something other than machine-on. Maybe a timedelay component?
Set up a timedelay for a few mS (as long as it takes to get the initial position read) and trigger that in the HAL file at load time.
(ie setp timedelay.0.in 1)
Replied by andypugh on topic Modbus input for absolute encoder position?
I might be able to add a mux2 or use an offset to subtract the encoder value but maybe someone has another idea. I already have to use quite a # of rt modules: offset, abs, conv_float_s32, sample_hold, conv_s32_float, 2 x sum2 to make it work and I am starting to see "Insufficient memory for pin.." warnings.
I am surprised that you are that close to the pin memory limit.
One answer might be a custom HAL component. If you can write C code at all then this fairly easy.
linuxcnc.org/docs/2.7/html/hal/comp.html
Or you could try just not turning off the machine
![:-) :-)](/media/kunena/emoticons/smile.png)
Actually, it sounds like you need to trigger the sample-hold with something other than machine-on. Maybe a timedelay component?
Set up a timedelay for a few mS (as long as it takes to get the initial position read) and trigger that in the HAL file at load time.
(ie setp timedelay.0.in 1)
Please Log in or Create an account to join the conversation.
24 Feb 2020 20:55 #158420
by 0x2102
Replied by 0x2102 on topic Modbus input for absolute encoder position?
I will take your advise and never turn the machine off ![:) :)](/media/kunena/emoticons/smile.png)
I am at a point where I can't turn it back on due to following error warning in LinuxCNC. This is actually better than having the actual position all wrong.
I think in closed-loop setup I would be able to reset the encoder feedback to 0 before I turn the machine back on. I found a reset bit in the hostmot2 manual. I might give that a try later, when I have glass scales on the machine.
I could use the servo encoder feedback but when I set them up in closed-loop (with the servo's auto-tuning on) I have some strange behavior in LinuxCNC PID tuning. Might need to turn auto-tuning off.
Anyway, thanks for all your help so far. I will provide an update, if things change.
![:) :)](/media/kunena/emoticons/smile.png)
I am at a point where I can't turn it back on due to following error warning in LinuxCNC. This is actually better than having the actual position all wrong.
I think in closed-loop setup I would be able to reset the encoder feedback to 0 before I turn the machine back on. I found a reset bit in the hostmot2 manual. I might give that a try later, when I have glass scales on the machine.
I could use the servo encoder feedback but when I set them up in closed-loop (with the servo's auto-tuning on) I have some strange behavior in LinuxCNC PID tuning. Might need to turn auto-tuning off.
Anyway, thanks for all your help so far. I will provide an update, if things change.
The following user(s) said Thank You: besriworld
Please Log in or Create an account to join the conversation.
- besriworld
- Offline
- Elite Member
-
Less
More
- Posts: 228
- Thank you received: 59
07 Apr 2023 04:09 #268482
by besriworld
Replied by besriworld on topic Modbus input for absolute encoder position?
Hello, any progress here? I have servo motors with 24bit absolute encoder. I want to read the current starting position and axle load when the machine is moving .Again, communication is modbus. Can you share your config files . I am new to LinuxCNC. Thanks!
Please Log in or Create an account to join the conversation.
Time to create page: 0.118 seconds