static void Main(string[] args) { // RapidCode objects MotionController controller; // Declare what 'controller' is. Axis axis; // Declare what 'axis' is. // Constants const int AXIS_INDEX = 0; // This is the index of the axis you will use to command motion. const int USER_LIMIT = 0; // Specify which user limit to use. const int USER_LIMIT_COUNT = 1; const int CONDITION = 0; // Specify which condition to use. (0 or 1) ("0" to compare 1 input || "1" to compare 2 inputs) const RSIUserLimitLogic LOGIC = RSIUserLimitLogic.RSIUserLimitLogicGT; // Logic for input value comparison. const double POSITION_TRIGGER_VALUE = 250; // The value to be compared which needs to be set here. const RSIUserLimitTriggerType TRIGGER_TYPE = RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION; // Choose the how the condition (s) should be evaluated. const RSIAction ACTION = RSIAction.RSIActionNONE; // Choose the action you want to cause when the User Limit triggers. const int DURATION = 0; // Enter the time delay before the action is executed after the User Limit has triggered. const double DEFAULT_FEED_RATE = 1.0; const double DESIRED_FEED_RATE = 2.0; // Other Global Variables ulong feedRateAddress; // Initialize RapidCode Objects controller = MotionController.CreateFromSoftware(); // Insert the path location of the RMP.rta (usually the RapidSetup folder) SampleAppsCS.HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialize correctly. // Some Necessary Pre User Limit Configuration controller.UserLimitCountSet(USER_LIMIT_COUNT); // Set the amount of UserLimits that you want to use. SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network. axis = controller.AxisGet(AXIS_INDEX); // Initialize your axis object. SampleAppsCS.HelperFunctions.CheckErrors(axis); try { axis.FeedRateSet(DEFAULT_FEED_RATE); // Restore FeedRate to default value. // USER LIMIT CONDITION controller.UserLimitConditionSet(USER_LIMIT, CONDITION, LOGIC, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION), POSITION_TRIGGER_VALUE); // Set your User Limit Condition (1st step to setting up your user limit) // USER LIMIT CONFIGURATION controller.UserLimitConfigSet(USER_LIMIT, TRIGGER_TYPE, ACTION, axis.NumberGet(), DURATION); // Set your User Limit Configuration. (2nd step to setting up your user limit) // USER LIMIT OUTPUT feedRateAddress = axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeTARGET_FEEDRATE); controller.UserLimitOutputSet(USER_LIMIT, DESIRED_FEED_RATE, feedRateAddress, true); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { // RapidCode objects MotionController controller; // Declare what 'controller' is. Axis axis; // Declare what 'axis' is. // Constants const int INPUT_INDEX = 10; // This is the index of the digital input you will use to trigger the user limit. const int AXIS_INDEX = 0; // This is the index of the axis you will use to command motion. const int AXIS_COUNT = 1; // Axes on the network. const int USER_UNITS = 1048576; // Specify your motor's count per units. const int USER_LIMIT = 1; // Specify which user limit to use. const int CONDITION = 0; // Specify which condition to use. (0 or 1) ("0" to compare 1 input || "1" to compare 2 inputs) const RSIUserLimitLogic LOGIC = RSIUserLimitLogic.RSIUserLimitLogicEQ; // Logic for input value comparison. const int INPUT_MASK = 1; // Decide the bits in an address which need to be used when comparing. Use 0xFFFFFFFF when a long or float comparison is desired. const int LIMIT_VALUE = 1; // The value to be compared which needs to be set here. const RSIUserLimitTriggerType TRIGGER_TYPE = RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION; // Choose the how the condition (s) should be evaluated. const RSIAction ACTION = RSIAction.RSIActionE_STOP_ABORT; // Choose the action you want to cause when the User Limit triggers. const int DURATION = 0; // Enter the time delay before the action is executed after the User Limit has triggered. const int USER_DATA_INDEX = 0; // Other Global Variables ulong inputAddress; // Initialize RapidCode Objects controller = MotionController.CreateFromSoftware(); // Insert the path location of the RMP.rta (usually the RapidSetup folder) SampleAppsCS.HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialize correctly. // Some Necessary Pre User Limit Configuration controller.UserLimitCountSet(1); // Set the amount of UserLimits that you want to use. controller.InterruptEnableSet(true); // Enable User Limit Interrupts. (When a user limit input comparison is met, and interrupt is triggered) SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network. axis = controller.AxisGet(AXIS_INDEX); // Initialize your axis object. SampleAppsCS.HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly. try { // GET AXIS READY & MOVING axis.UserUnitsSet(USER_UNITS); // Specify the counts per unit. (every 1048576 counts my motor does one full turn) (varies per motor) axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger value. (learn more about this on our support page) axis.PositionSet(0); // Ensure the motor starts at position 0 every time. axis.Abort(); // If there is any motion happening, abort it. axis.ClearFaults(); // Clear any faults. axis.AmpEnableSet(true); // Enable the axis. axis.MoveVelocity(1.0, 10.0); // Command a velocity move (Velocity=1.0, Acceleration=10.0). // USER LIMIT CONDITION inputAddress = controller.NetworkInputAddressGet(INPUT_INDEX); // 10 was the index of my 1st input. (To check your IO indexes go to RapidSetup -. controller.UserLimitConditionSet(USER_LIMIT, CONDITION, LOGIC, inputAddress, INPUT_MASK, LIMIT_VALUE); // Set your User Limit Condition (1st step to setting up your user limit) // USER LIMIT CONFIGURATION controller.UserLimitConfigSet(USER_LIMIT, TRIGGER_TYPE, ACTION, AXIS_INDEX, DURATION); // Set your User Limit Configuration. (2nd step to setting up your user limit) // USER LIMIT USER DATA SET controller.UserLimitInterruptUserDataAddressSet(USER_LIMIT, // Specify the user limit you want to add User Data for. USER_DATA_INDEX, // Specify what user data index you would like to use. (must be a value from 0 to 4) axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_POSITION)); // Specify the address of the data value you want to store in your User Data so that you can retrieve it later after the UserLimit limit triggers. // WAIT FOR DIGITAL INPUT TO TRIGGER USER LIMIT EVENT. Console.WriteLine("Waiting for the input bit to go high...\n"); while (controller.InterruptWait((int)RSIWait.RSIWaitFOREVER) != RSIEventType.RSIEventTypeUSER_LIMIT) // Wait until your user limit triggers. { } int triggeredUserLimit = controller.InterruptSourceNumberGet() - AXIS_COUNT; // Check that the correct user limit has triggered. (an extra user limit is allocated for each axis) UInt64 data = controller.InterruptUserDataGet(USER_DATA_INDEX); // Get the data stored in the user data you configured. double interruptPosition = BitConverter.ToDouble(BitConverter.GetBytes(data), 0); // Convert from raw 64-bit memory bytes into 64-bit double. Console.WriteLine("Input bit went HIGH and User Limit {0} triggered!", triggeredUserLimit); // Get the index of the user limit that triggered. Console.WriteLine("User Limit Interrupt Position = " + interruptPosition / USER_UNITS); // Get the position of the axis when it user limit event triggered. Console.WriteLine("\nDoes InterruptSourceNumberGet() - AxisCountGet() == userLimit: " + triggeredUserLimit.Equals(USER_LIMIT)); controller.UserLimitDisable(USER_LIMIT); // Disable User Limit. } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { // Constants const int AXIS_NUMBER = 0; // Specify which axis/motor to control. const int POSITION = 5; // Specify the position to travel to. 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) const int VELOCITY = 1; // Specify your velocity. - units: Units/Sec (it will do 1048576 counts/1 revolution every 1 second.) const int ACCELERATION = 10; // Specify your acceleration. - units: Units/Sec^2 const int DECELERATION = 10; // Specify your deceleration. - units: Units/Sec^2const int POSITION_INDEX = 0; // This is the index of the input you will use to trigger the user limit. const int POSITION_INDEX = 0; // This is the index of the axis actual position that will go active when the user limit triggers. const int OUTPUT_INDEX = 0; // This is the index of the digital output that will go active when the user limit triggers. const int NODE_INDEX = 0; // The EtherCAT Node we will be communicating with // 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 initialize correctly. SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network. Axis axis = controller.AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number) SampleAppsCS.HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly. IOPoint output0 = IOPoint.CreateDigitalOutput(controller.IOGet(NODE_INDEX), OUTPUT_INDEX); // Create IOPoint object. Can be used to automatically get the address of a specified node and input index try { controller.UserLimitCountSet(2); // Set the amount of UserLimits that you want to use. (every connected axis will automatically get 1 user limit) controller.InterruptEnableSet(true); // Enable User Limit Interrupts. (When a user limit input comparison is met, and interrupt is triggered) //-------- PARAMETERS FOR UserLimitConditionSet -------- int userLimit = 1; // Specify which user limit to use. int condition = 0; // Specify which condition to use (0 or 1) ("0" to compare 1 input || "1" to compare 2 inputs) RSIUserLimitLogic logic = RSIUserLimitLogic.RSIUserLimitLogicGE; // Logic for input value comparison. (Greater or equal) ulong inputAddress = controller.NetworkInputAddressGet(POSITION_INDEX); // 0 was the index of tha axis' Position Actual Value. (To check your IO indexes go to RapidSetup -. uint inputMask = 0XFFFFFFFF; uint limitValue = (uint)controller.NetworkInputValueGet(POSITION_INDEX) + (1048576 * POSITION); // Get the current encoder value, then add to it your axis encoder unit count times the number of revolutions you want your motor to do before stopping. // [1] Configure the input's trigger condition. controller.UserLimitConditionSet(userLimit, // (User Limit Index) - Specify which user limit to use condition, // (Condition Number) - Specify how many inputs you want to compare. logic, // (Comparison Logic) - Specify the how the input value(s) will be compared inputAddress, // (Input Address) - Specify the address of the input that will be compared. inputMask, // (Input Mask) - Specify the bits in an address which need to be used when comparing inputs. limitValue); // (Limit Value) - Specify the value to be compared with. //-------- PARAMETERS FOR UserLimitConfigSet -------- RSIUserLimitTriggerType triggerType = RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION; RSIAction action = RSIAction.RSIActionABORT; // Abort move when user limit triggers. int duration = 0; // [2] Configure and Enable the user limit. controller.UserLimitConfigSet(userLimit, // (User Limit Index) - Specify which user limit to use. triggerType, // (Trigger Type) - Specify how your condition should be evalutated. action, // (User Limit Action) - Specify the action you want to cause on the axis when the user limit triggers. AXIS_NUMBER, // (Current Axis) - Specify the axis that the action (defined above) will occur on. duration); // (Output Timer) - Specify the time delay before the action is executed after the User Limit has triggered. //-------- PARAMETERS FOR UserLimitOutputSet -------- uint andMask = (uint)output0.MaskGet(); // Get the appropriate mask from your IOpoint. OR use 0x00010000 for AKD General IO, 1 for Beckhoff IO Terminals uint orMask = (uint)output0.MaskGet();; // Get the appropriate mask from your IOpoint. OR use 0x00010000 for AKD General IO, 1 for Beckhoff IO Terminals ulong outputAddress = output0.AddressGet(); //Alternatively set manually using: controller.NetworkOutputAddressGet(OUTPUT_INDEX); bool enableOutput = true; // [3] Configure what the output will be. (Call this method after UserLimitConfigSet if you want an output to be triggered) (The output will only be triggered if the input conditions are TRUE.) controller.UserLimitOutputSet(userLimit, // (User Limit Index) - Specify which user limit to use. andMask, // (Logic AND Mask) - Specify the value that the digital output will be AND-ed with. orMask, // (Logic OR Mask) - Specify the value that the digital output will be OR-ed with. outputAddress, // (Output Address) - Specify the digital output address. enableOutput); // (Enable Output Set) - If TRUE, the output AND-ing and OR-ing will be executed when the User Limit triggers. Console.WriteLine("Waiting for axis to reach specified position\n"); axis.UserUnitsSet(USER_UNITS); // Specify the counts per Unit. axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page) axis.PositionSet(0); // Make sure motor starts at position 0 everytime. axis.Abort(); // If there is any motion happening, abort it. axis.ClearFaults(); // Clear faults. axis.AmpEnableSet(true); // Enable the motor. axis.MoveTrapezoidal(POSITION, VELOCITY, ACCELERATION, DECELERATION); // Command simple trapezoidal motion. // Wait for user limit to trigger. while (controller.InterruptWait((int)RSIWait.RSIWaitFOREVER) != RSIEventType.RSIEventTypeUSER_LIMIT) { } Console.WriteLine("User Limit {0} triggered!", controller.InterruptSourceNumberGet()); // Get the index of the user limit that triggered. axis.AmpEnableSet(false); // Disable the motor. controller.UserLimitDisable(userLimit); // Disable User Limit. Console.WriteLine("\nPress Any Key To Continue"); // Allow time to read Console. Console.ReadKey(); output0.Set(false); // Set output low so program can run again } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("\nPress Any Key To Exit"); // Allow time to read Console. Console.ReadKey(); }
static void Main(string[] args) { // Constants const int NODE_INDEX = 0; const int INPUT_INDEX0 = 0; // This is the index of the digital input you will use to trigger the user limit. const int INPUT_INDEX1 = 1; // This is the index of the digital input you will use to trigger the user limit. const int OUTPUT_INDEX = 0; // This is the index of the digital output that will go active when the user limit triggers. // 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 initialize correctly. SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network. try { controller.UserLimitCountSet(2); // Set the amount of UserLimits that you want to use. (every connected axis will automatically get 1 user limit) controller.InterruptEnableSet(true); // Enable User Limit Interrupts. (When a user limit input comparison is met, and interrupt is triggered) //-------- PARAMETERS FOR 1st and 2nd UserLimitConditionSet -------- int userLimit = 1; // Specify which user limit to use. RSIUserLimitLogic logic = RSIUserLimitLogic.RSIUserLimitLogicEQ; // Logic for input value comparison. IOPoint input0 = IOPoint.CreateDigitalInput(controller.IOGet(NODE_INDEX), INPUT_INDEX0); // Create IOPoint object. Can be used to automatically get the address of a specified node and input index IOPoint input1 = IOPoint.CreateDigitalInput(controller.IOGet(NODE_INDEX), INPUT_INDEX1); // Create IOPoint object. Can be used to automatically get the address of a specified node and input index IOPoint output0 = IOPoint.CreateDigitalOutput(controller.IOGet(NODE_INDEX), OUTPUT_INDEX); // Create IOPoint object. Can be used to automatically get the address of a specified node and input index SampleAppsCS.HelperFunctions.CheckErrors(input0); SampleAppsCS.HelperFunctions.CheckErrors(input1); SampleAppsCS.HelperFunctions.CheckErrors(output0); int condition0 = 0; // Specify which condition to use (0 or 1) ("0" to compare 1 input || "1" to compare 2 inputs) ulong input0Address = input0.AddressGet(); // 10 was the index of my 1st input. (To check your IO indexes go to RapidSetup -. uint input0Mask = (uint)input0.MaskGet(); uint limitValue0 = (uint)input0.MaskGet(); int condition1 = 1; // Specify which condition to use (0 or 1) ("0" to compare 1 input || "1" to compare 2 inputs) ulong input1Address = input1.AddressGet(); // 11 was the index of my 2nd input. (To check your IO indexes go to RapidSetup -. uint input1Mask = (uint)input1.MaskGet(); uint limitValue1 = (uint)input1.MaskGet(); // [1] Configure the 1st input's trigger condition. (condition 1) controller.UserLimitConditionSet(userLimit, // (User Limit Index) - Specify which user limit to use condition0, // (Condition Number) - Specify how many inputs you want to compare. logic, // (Comparison Logic) - Specify the how the input value(s) will be compared input0Address, // (Input Address) - Specify the address of the input that will be compared. input0Mask, // (Input Mask) - Specify the bits in an address which need to be used when comparing inputs. limitValue0); // (Limit Value) - Specify the value to be compared with. // [2] Configure the 2nd input's trigger condition. (condition 2) controller.UserLimitConditionSet(userLimit, // (User Limit Index) - Specify which user limit to use condition1, // (Condition Number) - Specify how many inputs you want to compare. logic, // (Comparison Logic) - Specify the how the input value(s) will be compared input1Address, // (Input Address) - Specify the address of the input that will be compared. input1Mask, // (Input Mask) - Specify the bits in an address which need to be used when comparing inputs. limitValue1); // (Limit Value) - Specify the value to be compared with. //-------- PARAMETERS FOR UserLimitConfigSet -------- RSIUserLimitTriggerType triggerType = RSIUserLimitTriggerType.RSIUserLimitTriggerTypeCONDITION_AND; RSIAction action = RSIAction.RSIActionNONE; int axis = 0; int duration = 0; // [3] Configure and Enable the user limit. controller.UserLimitConfigSet(userLimit, // (User Limit Index) - Specify which user limit to use. triggerType, // (Trigger Type) - Specify how your condition should be evalutated. action, // (User Limit Action) - Specify the action you want to cause on the axis when the user limit triggers. axis, // (Current Axis) - Specify the axis that the action (defined above) will occur on. duration); // (Output Timer) - Specify the time delay before the action is executed after the User Limit has triggered. //-------- PARAMETERS FOR UserLimitOutputSet -------- uint andMask = (uint)output0.MaskGet(); uint orMask = (uint)output0.MaskGet(); ulong outputAddress = output0.AddressGet(); bool enableOutput = true; // [4] Configure what the output will be. (Call this method after UserLimitConfigSet if you want an output to be triggered) (The output will only be triggered if the input conditions are TRUE.) controller.UserLimitOutputSet(userLimit, // (User Limit Index) - Specify which user limit to use. andMask, // (Logic AND Mask) - Specify the value that the digital output will be AND-ed with. orMask, // (Logic OR Mask) - Specify the value that the digital output will be OR-ed with. outputAddress, // (Output Address) - Specify the digital output address. enableOutput); // (Enable Output Set) - If TRUE, the output AND-ing and OR-ing will be executed when the User Limit triggers. Console.WriteLine("Waiting for the input bit to go high...\n"); // Wait for user limit to trigger. while (controller.InterruptWait((int)RSIWait.RSIWaitFOREVER) != RSIEventType.RSIEventTypeUSER_LIMIT) { } Console.WriteLine("User Limit {0} triggered!", controller.InterruptSourceNumberGet()); // Get the index of the user limit that triggered. controller.UserLimitDisable(userLimit); // Disable User Limit. Console.WriteLine("\nPress Any Key To Continue"); // Allow time to read Console. Console.ReadKey(); output0.Set(false); } catch (Exception e) { Console.WriteLine(e.Message); } }