APIs, concepts, guides, and more
GearingCamming.cs
1
40using NUnit.Framework;
41using RSI.RapidCode.dotNET; // Import our RapidCode Library.
42
43#if DOXYGEN // RSI internal documentation use only
44using RSI.RapidCode;
45#endif
46
48[TestFixture]
49[Category("Software")]
50class GearingCamming : SampleAppTestBase
51 {
52 [Test, Timeout(Constants.MAX_TEST_TIME)]
53 public void Camming()
54 {
56 //Create RapidCode Objects
57 Axis moving_axis = controller.AxisGet(Constants.MAIN_AXIS_NUMBER);
58 HelperFunctions.CheckErrors(moving_axis);
59 Axis follower_axis = controller.AxisGet(Constants.DRIVEN_AXIS_NUMBER);
60 HelperFunctions.CheckErrors(follower_axis);
61
62 // Constants
63 const double MAIN_VELOCITY = 50; // Specify your Moving Axis's velocity. - units: Units/Sec (it will do 1 counts / (1/104857) of a revolution every 1 second.)
64 const double MAIN_ACCELERATION = 20; // Specify your Moving Axis's acceleration. - units: Units/Sec^2
65
66 // Commanded Positions
67 double[] movingAxisDistances = { 5, 10, 8 }; // This is the RELATIVE Moving Axis distance, every n revolutions it changes its Driven position. (This is the x-axis)
68 double[] followerAxisPositions = { 10, 20, 10 }; // This is the final ABSOLUTE Driven position, for every 5 revolutions one of this positions gets applied. (This is the y-axis)
69
70 // Command motion on the Driven before the Moving Axis starts
71 follower_axis.MoveCamLinear(moving_axis.NumberGet(),
72 RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION, // Use COMMAND for phantoms and ACTUAL for real axis.
73 movingAxisDistances,
74 followerAxisPositions,
75 movingAxisDistances.Length);
76
77 moving_axis.MoveVelocity(MAIN_VELOCITY, MAIN_ACCELERATION); // Command a constant velocity on the master axis, Driven will follow.
78 follower_axis.MotionDoneWait(); // Wait for the cam motion to complet
79 moving_axis.Stop(); // Stop the Moving Axis
81
83 Assert.That(follower_axis.CommandPositionGet(), Is.EqualTo(followerAxisPositions[followerAxisPositions.Length - 1]));
84 }
85 [Test, Timeout(Constants.MAX_TEST_TIME)]
86 public void Gearing()
87 {
89 //Create RapidCode Objects
90 Axis moving_axis = controller.AxisGet(Constants.MAIN_AXIS_NUMBER);
91 HelperFunctions.CheckErrors(moving_axis);
92 Axis follower_axis = controller.AxisGet(Constants.DRIVEN_AXIS_NUMBER);
93 HelperFunctions.CheckErrors(follower_axis);
94
95 int numerator = 2; // Specify the numerator of the gearing ratio.
96 int denominator = 1; // Specify the denominator of the gearing ratio.
97
98 // Configure the 'follower' axis to be a follow to the 'moving' axis at a ratio of 2:1, that is,
99 // for every rotation of the Moving Axis axis, the Driven axis will rotate twice.
100 follower_axis.GearingEnable(moving_axis,
101 RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION, // If NOT using a Phantom Axis, switch to RSIAxisMasterTypeAXIS_ACTUAL_POSITION
102 numerator,
103 denominator);
104
105 // Perform a S-curve motion on the Moving Axis axis.
106 moving_axis.MoveSCurve(Constants.POSITION,
107 Constants.VELOCITY,
108 Constants.ACCELERATION,
109 Constants.DECELERATION,
110 Constants.JERK_PERCENT);
111
112 moving_axis.MotionDoneWait(); // Wait for motion to finish.
114
116 Assert.That(moving_axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
117 Assert.That(follower_axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION * (numerator / denominator)), "The command position should be equal to twice POSITION");
118 }
119 }
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCodeObject has any errors.
Helper Functions for checking logged creation errors, starting the network, etc.
double CommandPositionGet()
Get the current command position.
void MoveCamLinear(int32_t masterAxisNumber, RSIAxisMasterType masterFeedbackSource, const double *const masterDistances, const double *const slavePositions, int32_t pointCount)
Enable this Axis to be linear follower (slave) using an electronic cam.
void MoveVelocity(double velocity)
void GearingEnable(int32_t masterAxisNumber, RSIAxisMasterType masterFeedbackSource, int32_t numerator, int32_t denominator)
Enable this Axis to be follower (slave) using electronic gearing.
void MoveSCurve(double position, double vel, double accel, double decel, double jerkPct)
Command a point-to-point S-Curve motion.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5518
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
int32_t MotionDoneWait()
Waits for a move to complete.
int32_t NumberGet()
Get the axis number.
RSIAxisMasterType
Sources available to a slave Axis for electronic gearing & camming.
Definition rsienums.h:1163