APIs, concepts, guides, and more

◆ 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.

Part of the IO Members method group.

Sample Code:
📜 Velocity Motion via Analog Input
/* This sample demonstrates how to control axis velocity dynamically using an analog input value.
The analog input value (0 to 65536 for a 16-bit input) is mapped to a velocity range.
This was created using the EL3002 Analog Input module but works with many other modules.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
using System.Threading;
Console.WriteLine("📜 Axis Motion: Velocity via Analog Input");
int exitCode = 0;
// set sample config params
const double ACCELERATION = 100;
const double MAX_VEL = 10;
const double MAX_ANALOG = 65536; // 16-bit analog input
const int RUN_TIME_SECONDS = 20; // how long to run the velocity control loop
// get rmp objects
MotionController controller = MotionController.Get();
try
{
Helpers.CheckErrors(controller);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
// check is network is started
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network not started. Please start it before running this app.");
}
// get phantom axis
Axis axis = controller.AxisGet(Constants.AXIS_1_INDEX);
Helpers.CheckErrors(axis);
// get node
var node = controller.NetworkNodeGet(nodeNumber: 0);
Helpers.CheckErrors(node);
// configure axis
Helpers.PhantomAxisReset(axis);
// print sample info
Console.WriteLine($"Max Speed = {MAX_VEL}");
Console.WriteLine($"Running for {RUN_TIME_SECONDS} seconds...\n");
// control velocity based on analog input
var startTime = DateTime.Now;
while ((DateTime.Now - startTime).TotalSeconds < RUN_TIME_SECONDS)
{
// get analog input value and normalize to 0.0 - 1.0
double analogValue = node.AnalogInGet(analogChannel: 0);
double normalizedValue = analogValue / MAX_ANALOG;
/*
┌────────────────────────────────────────────────────┐
│ Analog Input Value Maps Linearly to Velocity │
│ │
│ Analog: 0 ............................ 65,536 │
│ Velocity: 0 ............................ MAX_VEL │
└────────────────────────────────────────────────────┘
*/
// map analog input linearly to velocity (0 to MAX_VEL)
double velocity = normalizedValue * MAX_VEL;
axis.MoveVelocity(velocity, ACCELERATION);
Thread.Sleep(1); // prevent cpu spin
}
// cleanup
Helpers.AbortMotionObject(axis);
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
Constants used in the C# sample apps.
Definition _constants.cs:3
const int EXIT_FAILURE
Exit code for failed execution.
Definition _constants.cs:69
const int AMP_ENABLE_MS
Default: 750.
Definition _constants.cs:35
const int EXIT_SUCCESS
Exit code for successful execution.
Definition _constants.cs:68
const int AXIS_1_INDEX
Default: 1.
Definition _constants.cs:21
void MoveVelocity(double velocity)
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5921
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
RSINetworkState
State of network.
Definition rsienums.h:573
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21
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.