- Posts: 137
- Thank you received: 0
Spindle speed in Counterclockwise Wrong
3 years 6 months ago #269990
by Donno
Spindle speed in Counterclockwise Wrong was created by Donno
I am setting and getting the spindle speed using Modbus. I use to get the spingde speed from Encoder A and Encoder B but need more input pins so i decided to get spindle speed using Modbus. Clockwise works as expected :
When doing counterclockwise :
It seems to get a signed int and displays an unsigned int
How could i convert/change to correct value ? Here is my current code
Hal File
mb2hal.ini
Thanks for your attention. I'm looking forward to your reply.
Attachment not found
When doing counterclockwise :
Attachment not found
Attachment not found
Attachment not found
It seems to get a signed int and displays an unsigned int
How could i convert/change to correct value ? Here is my current code
Hal File
Code:
...
loadusr -W mb2hal config=mb2hal.ini
...
loadrt limit1 count=1
addf limit1.0 servo-thread
setp limit1.0.min -2500
setp limit1.0.max 2500
...
net spindle-cmd-rpm => limit1.0.in
net spindle-speed-limit limit1.0.out => mb2hal.SetSpeed.00
net spindle-cmd-rpm-abs <= mb2hal.GetSpeed.00.float
...
mb2hal.ini
Code:
[MB2HAL_INIT]
INIT_DEBUG=3
HAL_MODULE_NAME=mb2hal
SLOWDOWN=0.0
TOTAL_TRANSACTIONS=2
[TRANSACTION_00]
LINK_TYPE=serial
SERIAL_PORT=/dev/ttyUSB0
SERIAL_BAUD=19200
SERIAL_BITS=8
SERIAL_PARITY=even
SERIAL_STOP=1
SERIAL_DELAY_MS=10
MB_SLAVE_ID=1
FIRST_ELEMENT=321
NELEMENTS=1
MB_TX_CODE=fnct_16_write_multiple_registers
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=SetSpeed
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_01]
MB_TX_CODE=fnct_03_read_holding_registers
FIRST_ELEMENT=449
NELEMENTS=1
HAL_TX_NAME=GetSpeed
MAX_UPDATE_RATE=0.0
DEBUG=1
Please Log in to join the conversation.
3 years 6 months ago #269993
by JPL
Replied by JPL on topic Spindle speed in Counterclockwise Wrong
I'm pretty sure that the problem is about how (negative) numbers are internally formatted. If I remember correctly you need to send 2s complement signed numbers. I've had the same problem a while ago with an HMI via modbus but in my case this was easily solved since the HMI was able to 'read' 2s complement directly.
You then have 2 options: Either see if your VFD can directly send 2s complement values or find a way to convert the formatting. Sadly I cannot help much with the later.
Some info here: www.electronics-tutorials.ws/binary/signed-binary-numbers.html
You then have 2 options: Either see if your VFD can directly send 2s complement values or find a way to convert the formatting. Sadly I cannot help much with the later.
Some info here: www.electronics-tutorials.ws/binary/signed-binary-numbers.html
Please Log in to join the conversation.
3 years 6 months ago #269994
by JPL
Replied by JPL on topic Spindle speed in Counterclockwise Wrong
This could work:
linuxcnc.org/docs/html/man/man9/conv_u32_s32.9.html
If not have a look at the others components starting with 'conv' here: linuxcnc.org/docs/html/man/man9/
If not have a look at the others components starting with 'conv' here: linuxcnc.org/docs/html/man/man9/
Please Log in to join the conversation.
3 years 6 months ago #269996
by Donno
Replied by Donno on topic Spindle speed in Counterclockwise Wrong
When I
I get following error
I also tried conv_float_s32 :
with no luck
Code:
setp conv-u32-s32.0.in mb2hal.GetSpeed.00.float
Code:
value 'mb2hal.GetSpeed.00.float' invalid for U32
I also tried conv_float_s32 :
Code:
setp conv-float-s32.0.in mb2hal.GetSpeed.00.float
Code:
setp failed setting parameter 'conv-float-s32.0.in' to 'mb2hal.GetSpeed.00.float' value 'mb2hal.GetSpeed.00.float' invalid for float
Please Log in to join the conversation.
3 years 6 months ago #270006
by JPL
Replied by JPL on topic Spindle speed in Counterclockwise Wrong
For some reason sometimes you have to create a new signal (or use an existing one) instead of using setp when connecting pins. (This is somewhere in the HAL doc)
For example: setp conv-u32-s32.0.in mb2hal.GetSpeed.00.float Does NOT work
Try instead
net speed-u32 <= mb2hal.GetSpeed.00.float
net speed-u32 => conv-u32-s32.0.in
net speed-s32 <= conv-u32-s32.0.out
likewise for conv-float-s32
For example: setp conv-u32-s32.0.in mb2hal.GetSpeed.00.float Does NOT work
Try instead
net speed-u32 <= mb2hal.GetSpeed.00.float
net speed-u32 => conv-u32-s32.0.in
net speed-s32 <= conv-u32-s32.0.out
likewise for conv-float-s32
Please Log in to join the conversation.
3 years 6 months ago #270007
by JPL
Replied by JPL on topic Spindle speed in Counterclockwise Wrong
Or the short version
net speed-u32 mb2hal.GetSpeed.00.float => conv-u32-s32.0.in
net speed-u32 mb2hal.GetSpeed.00.float => conv-u32-s32.0.in
Please Log in to join the conversation.
3 years 6 months ago #270034
by Donno
I still get an error
This is the code how i added the component
Replied by Donno on topic Spindle speed in Counterclockwise Wrong
Code:
net speed-u32 mb2hal.GetSpeed.00.float => conv-u32-s32.0.in
Code:
Signal 'speed-u32' of type 'float' cannot add pin 'conv-u32-s32.0.in' of type 'u32'
This is the code how i added the component
Code:
loadrt conv_u32_s32 count=1
Please Log in to join the conversation.
3 years 6 months ago #270037
by Donno
Replied by Donno on topic Spindle speed in Counterclockwise Wrong
I manage to get the linuxcnc going with
But it did not manage to solve my problem
Is there a way to do math in .hal file. So If mb2hal.GetSpeed.00.float > 32 000 then -1(mb2hal.GetSpeed.00.float-65,535) that will solve my problem
Code:
loadrt conv_float_s32 count=1
net speed-u32 mb2hal.GetSpeed.00.float => conv-float-s32.0.in
But it did not manage to solve my problem
Attachment not found
Is there a way to do math in .hal file. So If mb2hal.GetSpeed.00.float > 32 000 then -1(mb2hal.GetSpeed.00.float-65,535) that will solve my problem
Please Log in to join the conversation.
3 years 6 months ago #270055
by Donno
Replied by Donno on topic Spindle speed in Counterclockwise Wrong
I started working on a formula So If mb2hal.GetSpeed.00.float > 32767 then -1(mb2hal.GetSpeed.00.float-65,535)
but i am getting stuck at
Pin 'comp.0.in1' was already linked to signal 'compare'
Code:
setp sum2.0.in1 -65536
net sum-speed mb2hal.GetSpeed.00.float => sum2.0.in0
setp mult2.0.in1 -1
net multi-speed mult2.0.in0 => sum2.0.out
setp comp.0.in0 32767
net compare comp.0.in1 => mult2.0.out
net neg-speed mux2.0.in0 => comp.0.in1
net pos-speed mux2.0.in1 => mb2hal.GetSpeed.00.float
net sel-speed mux2.0.sel => comp.0.out
net spindle-cmd-rpm-abs <= mux2.0.out
but i am getting stuck at
Code:
net neg-speed mux2.0.in0 => comp.0.in1
net pos-speed mux2.0.in1 => mb2hal.GetSpeed.00.float
Pin 'comp.0.in1' was already linked to signal 'compare'
Please Log in to join the conversation.
3 years 6 months ago #270058
by 0x2102
Replied by 0x2102 on topic Spindle speed in Counterclockwise Wrong
Hallo Donno,
attached is a simple component that should do exactly what you need.
1.) Download and copy to your config folder
2.) Open terminal and cd to your config folder
3.) "sudo halcompile --install spindle_speed.comp" (linuxcnc-dev apt package required for this)
4.) add the following to your machine.hal
loadrt spindle_speed names=spindle-speed
addf spindle-speed servo-thread
5.) Create your net connections
attached is a simple component that should do exactly what you need.
1.) Download and copy to your config folder
2.) Open terminal and cd to your config folder
3.) "sudo halcompile --install spindle_speed.comp" (linuxcnc-dev apt package required for this)
4.) add the following to your machine.hal
loadrt spindle_speed names=spindle-speed
addf spindle-speed servo-thread
5.) Create your net connections
Please Log in to join the conversation.
Time to create page: 0.106 seconds
