Page 4 of 4
Re: Remotely trigger jobs using the API?
Posted: Thu Dec 12, 2024 1:41 pm
by johannes
In the API, is there an equivalent to setting a part position with a numerical input?
I have an ultrasonic sensor that will detect X distance to the part along the track. So for each job segment, I will have an updated distance measurement in X (e.g. + 1.72 mm), and I want to set this as the new part position.
Perhaps an oversight from me on using SetWorkPieceOrigin, since it only zeros the WCS, it doesn't seem to accept a part position value input?
Re: Remotely trigger jobs using the API?
Posted: Thu Dec 12, 2024 2:41 pm
by Centroid_Jacob
johannes wrote: ↑Thu Dec 12, 2024 1:41 pm
In the API, is there an equivalent to setting a part position with a numerical input?
Screenshot 2024-12-12 at 18.36.56.png
I have an ultrasonic sensor that will detect X distance to the part along the track. So for each job segment, I will have an updated distance measurement in X (e.g. + 1.72 mm), and I want to set this as the new part position.
Perhaps an oversight from me on using SetWorkPieceOrigin, since it only zeros the WCS, it doesn't seem to accept a part position value input?
Currently there is no method or function for setting a part position using the API, we will try to add this functionality for the next release.
However, you can use Job.RunCommand to call G92 and pass it your axis values. (Note: G92 sets the currently active WCS to the specified values)
Code: Select all
public bool SetAbsolutePosition(double? X = null, double? Y = null, double? Z = null)
{
string cmdText = "G92";
if(X.HasValue)
cmdText += $" X{X.Value}";
if (Y.HasValue)
cmdText += $" Y{Y.Value}";
if (Z.HasValue)
cmdText += $" Z{Z.Value}";
var cncJob = new Job (m_pipe);
if (cncJob.RunCommand(cmdText, GetCNC12WorkingDirectory(), false) == ReturnCode.SUCCESS)
{
return true;
}
return false;
}
Called like so, to set X's absolute position to 1.72:
Code: Select all
SetAbsolutePosition(1.72,null,null);
Alternatively, you can use a similar approach and use RunCommand to set the system variables to the value if you need to change other WCS locations.
Code: Select all
cncJob.RunCommand("#2501 = 1.72; WCS #1 X val set to 1.72", GetCNC12WorkingDirectory(), false)
Let me know if I misunderstood your request.
Re: Remotely trigger jobs using the API?
Posted: Sat Dec 14, 2024 1:50 pm
by johannes
Centroid_Jacob wrote: ↑Thu Dec 12, 2024 2:41 pm
Alternatively, you can use a similar approach and use RunCommand to set the system variables to the value if you need to change other WCS locations.
WCS Vars.png
Code: Select all
cncJob.RunCommand("#2501 = 1.72; WCS #1 X val set to 1.72", GetCNC12WorkingDirectory(), false)
I went for this, it was clean and simple and worked fine. Thanks for sharing! This is exactly what I was looking for.