using System.Threading;
Console.WriteLine("📜 Motion: G-Code");
try
{
string gcodeProgram = @"G91; Sets the programming mode to RELATIVE
G64; Turns off exact stop mode (Default)
G1 X1.0 Y0.0 Z0.0 A1.0 F60.0; Move on USERUNIT in positive x direction at 60in/min. Moves Free axis A to position 1.0.
G3 X1 Y1 I0 J1; Counter clockwise arc with a center point of 0,1,0 and end point of 1,1,0 relative to the current position
M80; Show how to use an M-code with GcodeCallback!";
const string xLabel = "X-Axis";
const string yLabel = "Y-Axis";
const string zLabel = "Z-Axis";
const string aLabel = "A-Axis";
Axis xAxis = controller.
AxisGet(Constants.AXIS_0_INDEX);
Axis yAxis = controller.
AxisGet(Constants.AXIS_1_INDEX);
Axis zAxis = controller.
AxisGet(Constants.AXIS_2_INDEX);
Axis aAxis = controller.
AxisGet(Constants.AXIS_3_INDEX);
Axis[] axes = [xAxis, yAxis, zAxis, aAxis];
jointsMultiAxis.
AxesAdd(axes, axes.Length);
const string modelName = "RSI_XYZA";
const double scaling = 1.0;
const double offset = 0.0;
LinearModelBuilder builder = new(modelName);
builder.JointAdd(new LinearJointMapping(0, CartesianAxis.X) { ExpectedLabel = xLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(1, CartesianAxis.Y) { ExpectedLabel = yLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(2, CartesianAxis.Z) { ExpectedLabel = zLabel, Scaling = scaling, Offset = offset });
builder.FreeAxisAdd(new ModelAxisMapping(3) { ExpectedLabel = aLabel, Scaling = scaling, Offset = offset });
robot.Gcode.AccelerationRateSet(1000);
robot.Gcode.FreeAxisLetterSet(gcodeLetter: 'A', freeAxisIndex: 0);
SampleGcodeCallback callback = new();
robot.Gcode.CallbackRegister(callback);
try
{
robot.Gcode.Load(gcodeProgram);
}
catch (Exception e)
{
Console.WriteLine($"Error loading G-Code: {e.Message}");
throw;
}
Console.WriteLine($"G-Code Line Count: {robot.Gcode.LineCountGet()}");
Console.WriteLine($"G-Code Error Log Count: {robot.Gcode.ErrorLogCountGet()}");
Console.WriteLine($"G-code estimated run time: {robot.Gcode.DurationGet()} seconds");
robot.Gcode.Run();
Int64 activeLineNumber = 0;
do
{
Thread.Sleep(200);
if (activeLineNumber != robot.Gcode.ExecutingLineNumberGet())
{
activeLineNumber = robot.Gcode.ExecutingLineNumberGet();
Console.WriteLine($"G-Code Line Number: {activeLineNumber}");
}
} while (robot.Gcode.IsRunning());
Robot.RobotDelete(controller, robot);
Console.WriteLine("✅ G-Code motion completed successfully");
}
finally
{
}
public class SampleGcodeCallback : GcodeCallback
{
public override void Execute(GcodeCallbackData data)
{
Console.WriteLine("G-Code Callback executed: " + data.LineNumber + " " + data.LineText);
}
}
static void ConfigurePhantomAxis(Axis phantomAxis)
Configures a phantom axis on the controller.
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Helpers class provides static methods for common tasks in RMP applications.
void UserLabelSet(const char *const userLabel)
Set the axis User defined Label.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
void DefaultAccelerationSet(double acceleration)
Set the default acceleration in UserUnits.
void DefaultDecelerationSet(double deceleration)
Set the default deceleration in UserUnits.
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static constexpr int32_t AxisFrameBufferSizeDefault
The default value of the AxisFrameBufferSize, also the minimum allowable value.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
void AxesAdd(Axis **axes, int32_t axisCount)
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.