The RMP Motion Controller APIs
Velocity Set by Analog Input

Learn how to set the velocity based on an analog input value.

Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.


📜 Velocity Set by Analog Input Value
This Sample App was created using the EL3002 Analog Input module. Please note that some variable values might changed based on your analog input module.
The functionality used with many other Analog Input modules, not only Beckhoff's.
Learn more about the EL3XXX analog input modules from beckhoff. (https://www.beckhoff.com/english/ethercat/analog.htm)

35 // GLOBAL VARIABLES
36 double analogMaxValue = 65536; // The analog inputs used are 16 bit wide.
37 double currentVelocity = 0; // Used to update velocity based on analog input value.
38 double analogCurrentValue = 0; // Used to store current analog input value.
39 double analogValuePrecentage = 0; // analogCurrentValue/anlogMaxValue.
40 double velocityAbsoluteSum = 0; // Absolute sum of min and max velocities.
41
42 // CONSTANTS
43 const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
44 const int NODE_NUMBER = 0; // Specify which IO Terminal/Node to control. 0 for RSI AKD DemoBench
45 const int ANALOG_INPUT_0 = 0; // Specify which Analog Input to read.
46 const int MIN_VEL = -10; // Specify Min Velocity.
47 const int MAX_VEL = 10; // Specify Max Velocity.
48 const int ACC = 100; // Specify Acceleration/Deceleration value.
49 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)
50
51 // Initialize RapidCode Objects
52 MotionController controller = MotionController.CreateFromSoftware(/*@"C:\RSI\X.X.X\"*/); // Insert the path location of the RMP.rta (usually the RapidSetup folder)
53 HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialized correctly.
54 HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network.
55
56 Axis axis = controller.AxisGet(AXIS_NUMBER); // Initialize the axis.
57 HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialized correctly.
58
59 IO ioNode = controller.IOGet(NODE_NUMBER); // Initialize the axis.
60 HelperFunctions.CheckErrors(ioNode); // [Helper Function] Check that the axis has been initialized correctly.
61
62 try
63 {
64 // CONSOLE OUT
65 Console.WriteLine("Velocity Move Initialized.");
66 Console.WriteLine("Max Speed = " + MAX_VEL);
67 Console.WriteLine("Min Speed = " + MIN_VEL);
68 Console.WriteLine("\nPress SPACEBAR to exit.");
69
70 // READY AXIS
71 axis.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
72 axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
73 axis.PositionSet(0); // Make sure motor starts at position 0 everytime.
74 axis.DefaultAccelerationSet(ACC); // Set Acceleration.
75 axis.DefaultDecelerationSet(ACC); // Set Deceleration.
76 axis.Abort(); // If there is any motion happening, abort it.
77 axis.ClearFaults(); // Clear faults.
78 axis.AmpEnableSet(true); // Enable the motor.
79
80 do
81 {
82 while (!Console.KeyAvailable)
83 {
84 velocityAbsoluteSum = Math.Abs(MIN_VEL) + Math.Abs(MAX_VEL);
85 analogCurrentValue = (double)ioNode.AnalogInGet(ANALOG_INPUT_0); // Get analog in value.
86 analogValuePrecentage = analogCurrentValue / analogMaxValue; // Get percentage of analog voltage.
87
88 /*
89 * REPRESENTATION OF ANALOG INPUT VALUE BASED ON DIGITAL OUTPUT VOLTAGE
90 *
91 * AI Value --> 0 ............ 32,769 ............ 65,536
92 * DO Voltage --> 0 ........8 9 10 -10 -9 -8...... 0
93 */
94
95 if (analogValuePrecentage * 100 > 99 || analogValuePrecentage * 100 < 1) // If the Analog Input value is close to 0 or 65,536 then velocity is ZERO.
96 currentVelocity = 0;
97
98 else if (analogValuePrecentage * 100 < 50) // If the Analog Input value is less than 50% of 65,536 then velocity varies from 0 to 10.
99 currentVelocity = velocityAbsoluteSum * analogValuePrecentage;
100
101 else // If the Analog Input value is greater than 50% of 65,536 then velocity varies from 0 to -10.
102 currentVelocity = -velocityAbsoluteSum + (velocityAbsoluteSum * analogValuePrecentage);
103
104 axis.MoveVelocity(currentVelocity); // Update Velocity.
105
106 }
107 } while (Console.ReadKey(true).Key != ConsoleKey.Spacebar); // If the Spacebar key is pressed, exit.
108
109 axis.Abort(); // Abort Motion.
110 }
111 catch (Exception e)
112 {
113 Console.WriteLine(e.Message); // If there are any exceptions/issues this will be printed out.
114 }

Learn more in topic page.