MotionController Axis MultiAxis IO IOPoint NetworkNode RsiError
Sample Apps Changelog

RapidCode API

PTmotionWhileStopping.cs
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using RSI.RapidCode.dotNET.Enums;
using System;
namespace SampleAppsCS
{
class PTmotionWhileStopping
{
static void Main(string[] args)
{
// Constants
const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
const int POINTS = 1; // Specify how many points per streaming motion method call.
const int USER_UNITS = 1048576; // Specify your counts per unit / user units. (the motor used in this sample app has 1048576 encoder pulses per revolution)
double[] first = { 10.0 }; // specify the array with position(s) that will go in the first MovePT call.
double[] second = { 20.0 }; // specify the array with position(s) that will go in the second MovePT call
double[] third = { 7.0 }; // specify the array with position(s) that will go in the third MovePT call
double[] time1 = { 5.0 }; // specify the array with time(s) that will go in the first MovePT call.
double[] time2 = { 2.0 }; // specify the array with time(s) that will go in the second MovePT call.
double[] time3 = { 5.0 }; // specify the array with time(s) that will go in the third MovePT call.
// Initialize RapidCode Objects
MotionController controller = MotionController.CreateFromSoftware(/*@"C:\RSI\X.X.X\"*/); // Insert the path location of the RMP.rta (usually the RapidSetup folder)
SampleAppsCS.HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialized correctly.
SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network.
Axis axis = controller.AxisGet(AXIS_NUMBER); // Initialize the axis.
SampleAppsCS.HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialized correctly.
try
{
axis.UserUnitsSet(USER_UNITS);
axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
axis.PositionSet(0);
axis.Abort(); // If there is any motion happening, abort it.
axis.ClearFaults(); // Clear faults.
axis.AmpEnableSet(true); // Enable the motor.
axis.MovePT(RSIMotionType.RSIMotionTypePT, first, time1, POINTS, -1, false, false); // Start motion and stream a point.
axis.MovePT(RSIMotionType.RSIMotionTypePT, second, time2, POINTS, -1, false, false); // Append a point.
// After you stop a streaming motion, you can do 2 things.
// 1. You can either RESUME motion and continue to append.
// 2. Or you can DISCARD the points before the stop and start new motion.
axis.Stop(); // Calling Stop() after streaming motion will put you in an STOPPED state.
//axis.EStop(); // Calling EStop() after streaming motion will put you in an ERROR state.
// Therefore, you must ClearFaults() before taking any action.
//axis.Abort(); // Calling Abort() after streaming motion will put you in an ERROR state and trigger an AmpEnable(false).
// Therefore, you must call AmpEnable(true) before taking action.
axis.MotionDoneWait(); // Wait for axis to come to a stop.
axis.Resume(); // Resume() is the key here.
// If you include Resume() you will append all next streaming points to the old ones.
// If you do not include Resume() you will discard all previous points and start with new motion with the new points.
axis.MovePT(RSIMotionType.RSIMotionTypePT, third, time3, POINTS, -1, false, true); // Depending on whether you include Resume() or not this point will be appended or will be starting motion.
}
catch (Exception e)
{
Console.WriteLine(e.Message); // If there are any exceptions/issues this will be printed out.
}
Console.WriteLine("\nPress Any Key To Exit"); // Allow time to read Console.
Console.ReadKey();
}
}
}