◆ AnalogInGet()

virtual int32_t AnalogInGet ( int32_t  analogChannel)
pure virtual

Get the value of an analog input.

ℹ This function is avaliable in RapidCode and RapidSequencer

Part of the IO Members method group.

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