using RSI.RapidCode.dotNET;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading;
using System.IO;
using System.Runtime.InteropServices;
#if DOXYGEN
#endif
{
{
}
}
[TestFixture]
[Category("Software")]
public class GcodeMotion : SampleAppTestBase
{
[SetUp]
public void Setup()
{
}
[TearDown]
public void Teardown()
{
robot = null;
jointsMultiAxis?.
Abort();
Thread.Sleep(50);
}
{
var actualUnits = model.
UnitsGet();
Assert.That(actualUnits, Is.EqualTo(expectedUnits), $"Expected model units to be '{expectedUnits}' but was '{actualUnits}' instead!");
var actualName = model.
NameGet();
Assert.That(actualName, Is.EqualTo(expectedName), $"Expected model name to be '{expectedName}' but was '{actualName}' instead!");
}
[Test]
public void GcodeBasic()
{
string gcodeProgram = "G91; Sets the programming mode to RELATIVE\n" +
"G64; Turns off exact stop mode(Default)\n" +
"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.\n" +
"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\n" +
"M80; Show how to use an M-code with GcodeCallback!\n";
const string xLabel = "X-Axis";
const string yLabel = "Y-Axis";
const string zLabel = "Z-Axis";
const string aLabel = "A-Axis";
Axis[] axes =
new Axis[] { x_axis, y_axis, z_axis, a_axis };
jointsMultiAxis.
AxesAdd(axes, axes.Length);
const string modelName = "RSI_XYZA";
const double scaling = 1.0, offset = 0.0;
try
{
robot.
Gcode.
Load(gcodeProgram);
}
catch (Exception e)
{
{
}
else
{
Console.WriteLine("Error: " + e.Message);
}
}
Console.WriteLine(
"G-code estimated run time: " + robot.
Gcode.
DurationGet() +
" seconds");
Int64 activeLineNumber = 0;
do
{
Thread.Sleep(200);
{
Console.WriteLine("G-Code Line Number: " + activeLineNumber);
}
Assert.AreEqual(gcodeProgram.Count(c => c.Equals(
'\n')), robot.
Gcode.
LineCountGet());
VerifyModel(robot.
ModelGet(), modelName);
}
[Test]
public void ChangingUnits()
{
const string xLabel = "X-Axis";
const string yLabel = "Y-Axis";
const string zLabel = "Z-Axis";
const string aLabel = "A-Axis";
const string bLabel = "B-Axis";
const string cLabel = "C-Axis";
Axis[] axes =
new Axis[] { x_axis, y_axis, z_axis, a_axis, b_axis, c_axis };
jointsMultiAxis.
AxesAdd(axes, axes.Length);
const string modelName = "RSI_XYZABC_Centimeters";
const double scaling = 1.0, offset = 0.0;
VerifyModel(robot.
ModelGet(), modelName, units);
}
}
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCodeObject has any errors.
Helper Functions for checking logged creation errors, starting the network, etc.
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,...
int32_t LineCountGet()=0
Get the number of lines in the last loaded G-Code program.
int32_t SyntaxErrorLineNumberGet()=0
Gets the line number of any errors in the G-Code syntax.
int32_t ExecutingLineNumberGet()=0
Get the currently executing line number.
LinearUnits UnitsGet()=0
Get the currently active unit as set by G20/G21.
void AccelerationRateSet(double programmingUnitsPerMinuteSquared)=0
Sets the target acceleration for the machine (units/minute^2). Should be set apprpriately based on yo...
void UnitsSet(LinearUnits units)=0
Set the currently active unit (same as calling G20/G21)
double DurationGet()=0
Get the time duration required to run the loaded G-Code program in seconds.
void FreeAxisLetterSet(const char gcodeLetter, const int freeAxisIndex)=0
Map a letter in a Gcode file to a free axis. It will be used to specify the free axis' motion.
void FeedRateSet(double programmingUnitsPerMinute)=0
Sets the target feed rate for the machine (units/minute).
void Run()=0
Run the loaded G-Code file (or string). The behavior is non-blocking. Use Robot.MotionDoneWait() to b...
Handles callbacks for M-codes within a G-code file.
void CallbackRegister(Cartesian::GcodeCallback *callback)=0
G-code callback register.
bool IsRunning()=0
Returns true if a Gcode program is executing, false otherwise.
void UnitsSet(LinearUnits units)
Set the units the built model will use.
void FreeAxisAdd(const ModelAxisMapping &freeAxis)
Map a free-axis in the kinematic model.
Describes the mathematical kinematic model of a robot.
The Builder for a linear kinematic model. Constructs a single Linear Kinematic Model to use when crea...
void JointAdd(const LinearJointMapping &joint)
adds a joint to the model using the configuration specified within the LinearJoint structure.
uint64_t MotionDoneWait()=0
Waits for a move to complete.
static Robot * RobotCreate(MotionController *controller, MultiAxis *multiAxis, KinematicModelBuilder *builder, uint32_t motionFrameBufferSize)
Create a Robot object to use G-Code, path motion, etc.
void EStop()=0
Commands a joint EStop and clears the loaded moves.
Represents a collection of joints in Cartesian space with forward and inverse kinematics....
void ClearFaults()=0
Clears the MultiAxis fault then the Robot's error bit.
const KinematicModel & ModelGet()=0
Get the model this robot was created with Visit our Topic Page for more information.
static void RobotDelete(MotionController *controller, Robot *robot)
Delete a Robot.
RSI::RapidCode::Cartesian::Gcode * Gcode
An object to load and run Gcode files.
static constexpr int32_t AxisFrameBufferSizeDefault
The default value of the AxisFrameBufferSize, also the minimum allowable value.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
void AxisRemoveAll()
Remove all axes from a MultiAxis group.s.
void AxesAdd(Axis **axes, int32_t axisCount)
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
const RsiError *const ErrorLogGet()
Get the next RsiError in the log.
int32_t ErrorLogCountGet()
Get the number of software errors in the error log.
make a Callback class and register it with the Gcode object
CartesianAxis
This enum specifies which Cartesian axis a LinearJointMapping maps a robot joint to.
LinearUnits
Unit types. For G-code use.
const char * LineText
The actual line content from the G-code file.
int32_t LineNumber
The line number in the G-code file where the M-code is encountered.
Holds data for the G-code M-code callback mechanism.
Data for adding joint or free-axis mappings when building a kinematic model.