Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: cd_edwards on June 16, 2018, 04:13:22 PM
-
axis = Y_AXIS;
rc = mcAxisGetInfoStruct(xh->mInst, axis, &ainf);
if (rc)
send_to_diag("mcAxisGetInfoStruct returned an error");
this is always returning -16 which is axis not found. I'm using the Sim plugin for a motion controller. Doesn't seem to matter what I send as an axis though, they all return -16.
xh->mInst is 0 and the structure is axisinfo_t. I'm using this function to gain access to both Work coordinate's and machine coordinates.
I'm using build 3805 of Mach4. This is C++ code, not lua as i'm writing a plugin.
-
part of the issue here is that if Mach4 is not in an enabled state, this function returns -16. Not sure how to work around this, since I need to access the DRO position's in order to update my pendant display. This is because the state of the DRO's is saved and reloaded at Mach4 restart. The DRO's should be available at any time you request it. Setting them would be another story.
-
If all you want is the axis position:
val, rc = mc.mcAxisGetPos(number mInst, number axisId)
HTH
RT
-
mcAxisGetInfoStruct returns a table.
This is how I would get work and machine coords in lua.
local inst = mc.mcGetInstance()
local val, rc = mc.mcAxisGetPos(inst, mc.X_AXIS)
local xInfo, rc = mc.mcAxisGetInfoStruct(inst, mc.X_AXIS)
local xMpos = xInfo.Mpos --Machine position in user units.
-
mcAxisGetInfoStruct returns a table.
This is how I would get work and machine coords in lua.
local inst = mc.mcGetInstance()
local val, rc = mc.mcAxisGetPos(inst, mc.X_AXIS)
local xInfo, rc = mc.mcAxisGetInfoStruct(inst, mc.X_AXIS)
local xMpos = xInfo.Mpos --Machine position in user units.
unfortunately though, if the machine is not enabled then you get a -16 error saying the AXIS does not exist. I'd prefer to use the structure myself since I get both work and machine coords.
-
Hi,
is it possible that until the machine is enabled the info-structure/table is incomplete,
ie even if you could read the table it would not hold the info you require?
Craig
-
it's possible. but then mcAxisGetMachinePos and mcAxisGetPos shouldn't work either then.
I have it working now with the above two functions.. I just would have prefered the other way for cleanliness
-
Hi,
good point, the info must be there somewhere.
How does this sound for an explanation....pure guess of course...ALL the required data is held in Registers, aka
the pound variables, but the info structure is only ever populated when the machine is enabled. If the structure is
not formed, or complete, or current it effectively does not exist.
Craig
-
Works fine here (enabled or disabled). I do not get the -16 in either case.
I think another issue is the AxisInfoStruct.Pos does not return the value you think. I spoke to Steve today and he is going to change it so Pos returns work coords. That is not what it does right now. As it is should be override axis + Mpos. If you don't have an override axis with some value assigned, it will return the same as Mpos. In the next release Pos should return work coords.
-
that would have been an issue for sure. I was going by the .chm helpfile. This looks definitely like it should have returned what i needed. but I have what I need now, so I'm good on this issue. Now I just need to find out why I never get a MSG_HOME_AXIS or a MSG_DREF_AXIS
double Pos; // Position in user units.
double Mpos; // Machine position in user units.