How to get tool offset in linuxcncrsh?

More
20 Jul 2014 03:29 #48950 by billooms
I use linuxcncrsh to capture the position of linuxcnc from another computer. I'm having trouble getting the relative coordinates when there is a tool offset in place. Here's a simple example that I ran on my office computer using the "simulator" version 2.5.4 with the provided "lathe" configuration:

Load the tool table and manually enter an X offset of 0.5 for Tool 2, save the file, and re-read.
Type in the MDI command: "t2 m6 g43"
Type in the MDI command: "g0 x0 z0"
At this point, the axis display and DRO shows the tool at x=0, z=0.

From a terminal window, I manually start linuxcncrsh.
From a second terminal window, I connect to linuxcncrsh and try various commands:

get tool
TOOL 2
get tool_offset
TOOL_OFFSET 0
get abs_cmd_pos
ABS_CMD_POS 0.500000 0.000000 0.000000 0.000000 0.000000 0.000000
get abs_act_pos
ABS_ACT_POS 0.500000 0.000000 0.000000 0.000000 0.000000 0.000000
get rel_cmd_pos
REL_CMD_POS 0.500000 0.000000 0.000000 0.000000 0.000000 0.000000
get rel_act_pos
REL_ACT_POS 0.500000 0.000000 0.000000 0.000000 0.000000 0.000000
get joint_pos
JOINT_POS 0.500000 0.000000 0.000000 0.000000 0.000000 0.000000
get pos_offset
POS_OFFSET 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

So no matter how I try to get the coordinates, it returns x=0.5. From reading the manual pages, I would have expected the relative positions to be different from the absolute positions by the tool offset. Also, would expect that the "get tool_offset" command would have returned the offset of the tool with all values (why does it only return one value and that value is zero?)

So how can I get the relative position that shows in the DRO of the axis display? Alternately, how can I get the tool offset and make the correction myself?

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

More
20 Jul 2014 06:01 #48956 by andypugh
Can you read the result of MDI commands? (I haven't used linuxcncrsh)

One dodge I used a while ago was to use G92 X0 Y0 Z0 to store the current location in #5211 onwards, then G92.2 to remove the effect.

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

More
20 Jul 2014 16:20 - 20 Jul 2014 16:22 #48967 by ArcEye
Hi Bill

I have a partial answer about the offset

It looks like linuxcncrsh assumes everyone uses only 3 axis mills

It will always return the Z tool offset
static cmdResponseType getToolOffset(char *s, connectionRecType *context)
{
  const char *pToolOffsetStr = "TOOL_OFFSET %d";
  
  sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.z);
  return rtNoError; 
}

The code for the various positions is interesting.
It appears the commands take an argument of the axis number eg get abs_cmd_pos 0, which I had not realised.

If no argument is given, it returns all axes.

getPosOffset takes an argument of a capital letter for the axis too eg get pos_offset X

This business of the offsets being wrong or wrongly returned vaguely rings a bell.
I seem to recall Andy found a basic error in the calculation, but I could be confusing it with something else.

regards
Last edit: 20 Jul 2014 16:22 by ArcEye.

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

More
20 Jul 2014 21:48 #48975 by billooms

This business of the offsets being wrong or wrongly returned vaguely rings a bell.
I seem to recall Andy found a basic error in the calculation, but I could be confusing it with something else.


You recall correctly -- it was about 2 years ago that you found some incorrect calculations rel_act_pos and abs_act_pos. Here's the link to the old thread:
www.linuxcnc.org/emc2/index.php/english/...-values?limitstart=0

Whether I use "get pos_offset" or "get pos_offset X" I still get a value of 0.0 where I'm expecting a value of 0.5 for the tool offset.

I understand what you are saying about the "get tool_offset" always returning only the Z offset. I edited the tool table and put 0.3 for z offset. Now in linuxchcrsh I get:

get tool_offset
TOOL_OFFSET 858993459

It looks like something is wrong with the formatting because its not giving a floating point value.

How hard would it be to fix this?

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

More
20 Jul 2014 22:21 #48976 by ArcEye

You recall correctly -- it was about 2 years ago that you found some incorrect calculations rel_act_pos and abs_act_pos. Here's the link to the old thread:
www.linuxcnc.org/emc2/index.php/english/...-values?limitstart=0


Glad my memory wasn't playing tricks, it all comes back to be now.
You are probably still the only person using linuxcncrsh though B)

It looks like something is wrong with the formatting because its not giving a floating point value.
How hard would it be to fix this?


The more I look at this the worse it gets

There are 2 things wrong with this code
static cmdResponseType getToolOffset(char *s, connectionRecType *context)
{
  const char *pToolOffsetStr = "TOOL_OFFSET %d";
  
  sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.z);
  return rtNoError; 
}

You could simply change the code to display the X offset, just change that line to
sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.x);

But the format specifier being passed to sprintf is %d, which is an int value.
It should be %f which covers float / double, because the offset is a double

So, if you are in a position to recompile your sources (only need to recompile emcrsh.cc)

Then substitute this function for the one above and see where that gets you
static cmdResponseType getToolOffset(char *s, connectionRecType *context)
{
  const char *pToolOffsetStr = "TOOL_OFFSET %f";
  
  sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.x);
  return rtNoError; 
}

regards

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

More
20 Jul 2014 22:41 - 20 Jul 2014 22:48 #48977 by ArcEye
Or even better substitute this and it will give you Z offset by default, but allow you to specify X Y or Z
static cmdResponseType getToolOffset(char *s, connectionRecType *context)
	{
	const char *pToolOffsetStr = "TOOL_OFFSET %f";
  	
	switch (s[0]) 
		{
        case 'X': 	sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.x); 
					break;

        case 'Y': 	sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.y); 
					break;


        case 'Z':   
		default:	sprintf(context->outBuf, pToolOffsetStr, emcStatus->task.toolOffset.tran.z); 		
					break;
      }
	
  	return rtNoError; 
	}

Not tested but builds OK

regards
Last edit: 20 Jul 2014 22:48 by ArcEye.
The following user(s) said Thank You: billooms

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

More
21 Jul 2014 04:39 #48986 by billooms
Thank you very much for pointing the direction.

It's been many years since I did any amount of C programming (I mostly do Java now) but it will come back to me quick enough. I'll need to download the source and stuff and then play with it. You may be correct in saying I'm probably the only one using linuxcncrsh, so I probably should get used to taking some ownership to understand the code and make fixes.

Dewey Garrett now lives in the same town as I and he should be able to help me if I get stuck.

Thanks,
Bill

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

More
21 Jul 2014 04:44 #48987 by andypugh

Dewey Garrett now lives in the same town as I


The world centre of ornamental turning?

www.billooms.com
www.deweygarrett.com

Lots of lovely stuff on both sites.

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

More
21 Jul 2014 04:59 #48988 by billooms

The world centre of ornamental turning?


That's what we call it! It's fun getting together and generating new ideas together.

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

Time to create page: 0.095 seconds
Powered by Kunena Forum