The RMP Motion Controller APIs

◆ AnalogInGet()

int32_t AnalogInGet ( int32_t  analogChannel)
Description:
AnalogInGet returns the value of an analog input. It is passed a starting channel ID relative to the Node (not Segment).
Parameters
analogChannelThe analog input number on the node, starts from 0.
Returns
(int32_t) Value of the analog input.
Remarks
This function is also available in RapidSequencer.

Part of the IO Members method group.

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