The RMP Motion Controller APIs
InputOutput.cs
1
48using RSI.RapidCode.dotNET; // Import our RapidCode Library.
49using NUnit.Framework;
50using System;
51
52#if DOXYGEN // RSI internal documentation use only
53using RSI.RapidCode;
54#endif
55
57[TestFixture]
58[Category("Software")]
59class InputOutput : SampleAppTestBase
60 {
61 [Test, Timeout(Constants.MAX_TEST_TIME)]
62 public void DedicatedIO()
63 {
65 // Retrieve dedicated inputs with generic and specific function.
66 Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_NEG: {0} and {1}",
67 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInLIMIT_HW_NEG),
68 axis.NegativeLimitGet());
69
70 Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_POS: {0} and {1}",
71 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInLIMIT_HW_POS),
72 axis.PositiveLimitGet());
73
74 Console.WriteLine("RSIMotorDedicatedInHOME: {0} and {1}",
75 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInHOME),
76 axis.HomeSwitchGet());
77
78 Console.WriteLine("RSIMotorDedicatedInAMP_FAULT: {0} and {1}",
79 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInAMP_FAULT),
80 axis.AmpFaultGet());
81
82 Console.WriteLine("RSIMotorDedicatedInAMP_ACTIVE: {0} and {1}",
83 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInAMP_ACTIVE),
84 axis.AmpEnableGet());
86 }
87
88 [Test, Timeout(Constants.MAX_TEST_TIME)]
89 public void NetworkInputsAndOutputs()
90 {
92 // Get Input Values
93 int inputCount = controller.NetworkInputCountGet(); // Get number of Network Inputs (PDOs)
94
95 for (int i = 0; i < inputCount; i++)
96 {
97 int size = controller.NetworkInputBitSizeGet(i); // Read Input BitSize
98 int offset = controller.NetworkInputBitOffsetGet(i); // Read Input BitOffset
99 string name = controller.NetworkInputNameGet(i); // Read Input Name
100 UInt64 value = controller.NetworkInputValueGet(i); // Read Input Value
101 }
102
103 // Get Output Values
104 int outputCount = controller.NetworkOutputCountGet(); // Get number of Network Outputs (SDOs)
105
106 for (int i = 0; i < outputCount; i++)
107 {
108 int size = controller.NetworkOutputBitSizeGet(i); // Read Output BitSize
109 int offset = controller.NetworkOutputBitOffsetGet(i); // Read Output BitOffset
110 string name = controller.NetworkOutputNameGet(i); // Read Output Name
111 UInt64 value = controller.NetworkOutputSentValueGet(i); // Read Output Value
112 controller.NetworkOutputOverrideValueSet(i, value);
113 }
115 }
116
117
118 //TODO expand examples once iopoint is expanded.
119 [Test]
120 public void IOPoints()
121 {
124 const int NODE_INDEX = 0; // The EtherCAT Node we will be communicating with
125 //const int INPUT_INDEX = 0; // The PDO Index in that Node
126 const int OUTPUT_INDEX = 0; // The PDO Index in that Node
127
128 IOPoint output0 = IOPoint.CreateDigitalOutput(controller.NetworkNodeGet(NODE_INDEX), OUTPUT_INDEX); // Automatically gets the memory index of a specified node and input index
129
131 output0.Set(false);
132
134 controller.SampleWait(1);
135 Assert.False(output0.Get(), "The getter function should return a value equal to false");
137 }
138
139 //TODO expand examples once iopoint is expanded.
140 [Test]
141 public void IOPointUserBuffer()
142 {
145 const int INPUT_INDEX = 0;
146 const int OUTPUT_INDEX = 1; // The PDO Index in that Node
147
148 UInt64 userBufferAddress = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 0); // Grabing an memory address to store a simulated IO point.
149
150 IOPoint input0 = IOPoint.CreateDigitalInput(controller, userBufferAddress, INPUT_INDEX); // Automatically gets the memory index of a specified node and input index
151 IOPoint output0 = IOPoint.CreateDigitalOutput(controller, userBufferAddress, OUTPUT_INDEX); // Automatically gets the memory index of a specified node and input index
152
153 //---ACT/ASSERT---
154 output0.Set(false);
155 Assert.False(output0.Get(), "The getter function should return a value equal to false");
156 output0.Set(true);
157 Assert.True(output0.Get(), "The getter function should return a value equal to true");
158 controller.MemorySet(input0.AddressGet(), 0);
159 Assert.False(input0.Get(), "The getter function should return a value equal to false");
160 controller.MemorySet(input0.AddressGet(), 1);
161 Assert.True(input0.Get(), "The getter function should return a value equal to true");
163 }
164
165 [Test]
166 public void SingleAxisSyncOutputs()
167 {
169 const int TOTAL_POINTS = 4; // total number of points
170 const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
171 const int OUTPUT_INDEX = 0; // This is the index of the digital output that will go active when the user limit triggers.
172 const int NODE_INDEX = 0; // The EtherCAT Node we will be communicating with
173
174 double[] positions = { 1.0, 2.0, 3.0, 4.0 }; // These will be the streaming motion 5 positions.
175 double[] times = { 0.5, 0.1, 0.2, 0.4 }; // These will be the streaming motion 5 positions' time.
176 int outputEnableID = 2; // The motion element ID at which to set the output
177 int outputDisableID = 3; // The motion element ID at which to set the output
178
179 // Set up the inputs
180 // IOPoint output0 = IOPoint.CreateDigitalOutput(axis, RSIMotorGeneralIo.RSIMotorGeneralIo16); // Retrieve DOUT 1, Method 1: requires you know the io adress in memory, slightly faster
181 IOPoint output0 = IOPoint.CreateDigitalOutput(controller.NetworkNodeGet(NODE_INDEX), OUTPUT_INDEX); // Retrieve DOUT 1 Method 2: only need to know node index
182 output0.Set(false); // Set the output low
183
184 // Set up Sync Outputs
185 axis.StreamingOutputsEnableSet(true); // Enable streaming output.
186
187 // ENABLE the Sync Output(s)
188 axis.StreamingOutputAdd(output0, true, outputEnableID); // This will turn DOUT1 High when the streaming motion reaches its 3rd motion point.
189 axis.StreamingOutputAdd(output0, false, outputDisableID); // This will turn DOUT1 Low when the streaming motion reaches its 4th motion point.
190
191 // DISABLE the Sync Output(s)
192 // axis.StreamingOutputAdd(output0, false, outPutEnableID);
193
194 axis.MovePT(RSIMotionType.RSIMotionTypePT, positions, times, TOTAL_POINTS, EMPTY_CT, false, true); // Start Streaming Motion
195
196 while (!axis.MotionDoneGet())
197 {
198 if (axis.MotionIdExecutingGet() > outputEnableID && axis.CommandPositionGet() < outputEnableID)
199 {
200 Assert.AreEqual(output0.Get(), true, "The output should be triggered");
201 }
202 else
203 {
204 Assert.AreEqual(output0.Get(), false, "The output should NOT be triggered");
205 }
206 }
207
208 axis.StreamingOutputsEnableSet(false); // Disable Sync Outputs.
209 axis.AmpEnableSet(false); // Disable the motor.
211 }
212 }
double CommandPositionGet()
Get the current command position.
bool AmpEnableGet()
Get the state of the Amp Enable Output.
bool HomeSwitchGet()
Get the current state of the Home switch input.
bool PositiveLimitGet()
Get the state of the Hardware Positive Limit input.
uint16_t MotionIdExecutingGet()
bool NegativeLimitGet()
Get the state of the Hardware Negative Limit input.
bool AmpFaultGet()
Get the current state of the Amp Fault input.
bool DedicatedInGet(RSIMotorDedicatedIn motorDedicatedInNumber)
Read a digital input.
uint64_t AddressGet()
Get the Host Address for the I/O point.
void Set(bool state)
Set the state of a Digital Output.
static IOPoint * CreateDigitalInput(Axis *axis, RSIMotorDedicatedIn motorDedicatedInNumber)
Create a Digital Input from an Axis' Dedicated Input bits.
static IOPoint * CreateDigitalOutput(Axis *axis, RSIMotorDedicatedOut motorDedicatedOutNumber)
Create a Digital Output from an Axis' Dedicated Output bits.
bool Get()
Get the state of Digital Input or Output.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:11319
NetworkNode * NetworkNodeGet(int32_t nodeNumber)
NetworkNodeGet returns a pointer to a RapidCodeNetworkNode object using its node number and initializ...
void NetworkOutputOverrideValueSet(int32_t index, uint64_t outputValue)
Sets a PDO output directly.
int32_t NetworkInputBitOffsetGet(int32_t index)
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
uint64_t NetworkInputValueGet(int32_t index)
uint64_t NetworkOutputSentValueGet(int32_t index)
Gets the value sent out over EtherCAT.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
const char *const NetworkOutputNameGet(int32_t index)
Get the name of a PDO output.
int32_t NetworkOutputBitSizeGet(int32_t index)
Get the size (in bits) of a PDO output.
int32_t NetworkOutputBitOffsetGet(int32_t index)
Get the raw PDO offset for an output.
int32_t NetworkInputCountGet()
Get the number of PDO inputs found on the network.
int32_t NetworkInputBitSizeGet(int32_t index)
Get the size (in bits) of a network input.
const char *const NetworkInputNameGet(int32_t index)
Get the name of a PDO network input.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void StreamingOutputAdd(int32_t onMask, int32_t offMask, uint64_t address)
void StreamingOutputsEnableSet(bool enable)
Sets whether Streaming Output is enabled (true) or disabled (false).
void MovePT(RSIMotionType type, const double *const position, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
A move commanded by a list of position and time points.
bool MotionDoneGet()
Check to see if motion is done and settled.
RSIControllerAddressType
Used to get firmware address used in User Limits, Sequencers, etc.
Definition rsienums.h:404
RSIMotionType
Streaming motion types.
Definition rsienums.h:979
RSIMotorDedicatedIn
Dedicated Input bits per motor.
Definition rsienums.h:834