Custom M-Codes dont work

More
10 May 2011 18:35 - 10 May 2011 18:49 #9698 by goaran
Hello,

i made a custom M-Code which will send some data over the RS232.

when i execute the file in the terminal with
python ./M104 100
where 100 is the value of the P word it works like it should.
I made the file executable and put it in the nc_files folder that is specified in the ini-file at [DISPLAY]PROGRAM_PREFIX

Now the file somehow seems to be found because the error "Unknowen M-Word" does not appear any more when i execute it with M104 P100
But nothing happens.

Edit:

i now found out that the problem is EMC2 does not send the value specified at P but the value with lots of zeros like this: 100.000000 instead of 100
is there any way to change this?
Last edit: 10 May 2011 18:49 by goaran.

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

More
10 May 2011 22:50 #9706 by BigJohnT
I assume it is passed as a float so converting it to an int in your custom M1xx file would fix that if that is possible.

There is no configuration to specify what type of number is passed, however EMC is open source and your free to modify the code...

John

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

More
11 May 2011 08:02 #9717 by ArcEye
Replied by ArcEye on topic Re:Custom M-Codes dont work
Hi

Yes this is a pain in the proverbial, which I discovered when writing a M101 script to change spindle scaling to account for gear ratio changes.

You must use the M1xx Pnn Qnn syntax or you will get 'unknown M code' errors.
If you do not use the Q parameter, EMC will still pass 2 values, albeit the second is -1.000000, something you might have to bear in mind when testing returns.

The below is my solution, I found a way in bash scripting to convert float to int.

I know squat about python, if you can't easily find a way to do the same, you could call your python program from the script and pass it the converted parameters.

Hope it helps you

regards
#!/bin/bash

## sets scale gain to make output speed accurate
## for each of 4 pulley settings

if [ ! $# -ge 1 ]; then
  echo "Usage: M101 Pn - where n is speed range 1 - 4"
  exit 1
fi

##echo "param 2 is $2"
## emc takes the M101 P3 for example and passes 
## $1 as 3.000000 and $2 as -1.000000 (because Q was not set)
## to this script!!!
## need to convert to int first

float=$1
int=${float/\.*}
# DEBUG	echo "$float converted to $int"


case $int in

    1 ) halcmd setp scale.0.gain 0.595;;
#       accurate at 1200 in M4 for turning

    2 ) halcmd setp scale.0.gain 1.16;;
#       accurate at 600 in M4 for turning

    3 ) halcmd setp scale.0.gain 2.175;;
#       accurate at 300 in M3 for threading

    4 ) halcmd setp scale.0.gain 4.3;;
#       accurate at 150 in M3 for threading
esac

exit 0

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

More
11 May 2011 10:43 #9719 by BigJohnT
Doesn't the gearchange comp do this?

John

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

More
11 May 2011 11:09 #9721 by ArcEye
Replied by ArcEye on topic Re:Custom M-Codes dont work
Hi John

The gearchange component I have seen only caters for 2 speeds, unless you re-write it.
It was probably intended for hi - lo ratio boxes rather than 4 speeds through stepped pulleys that I have.

I didn't see the point in writing a real time component, attached to the servo thread and being polled countless times a minute, for something I would only want to do once, right at the start of a process.

This script works fine for my requirements

regards

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

More
11 May 2011 20:17 #9729 by goaran
Replied by goaran on topic Re:Custom M-Codes dont work
Ok, thanks, i did the stuff in the python script now. Everything is working

here is what i built: www.thingiverse.com/thing:6480

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

Time to create page: 0.119 seconds
Powered by Kunena Forum