Learn how to jog an axis with RapidScript.
- Warning
- This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.
The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
- Precondition
- This sample application requires:
1. At least one axis (can be a phantom)
2. At least one analog input
📜 Axis Analog Jogging Sample App
A sample application that jogs an axis based on an exponential moving average of an analog input value.
5 int32 analogChannel = 0;
6 double analogMidrange = 10000.0;
7 double analogDeadband = 100;
8 double velocityMultiplier = 0.01;
14 int32 counterStart = 0;
15 double position = 0.0;
16 double averageAnalog = 0;
17 double rawAnalogValue = 0.0;
18 double scaledAnalogValue = 0.0;
19 double targetVelocity = 0;
21 AxisClearFaults(axis);
22 AxisAmpEnableSet(axis,
true);
23 double acceleration = AxisDefaultAccelerationGet(axis);
25 counterStart = ControllerSampleCounterGet();
26 while(AxisAmpEnableGet(axis))
28 rawAnalogValue = AxisAnalogInGet(axis, analogChannel);
29 scaledAnalogValue = rawAnalogValue - analogMidrange;
31 if( abs(scaledAnalogValue) < analogDeadband)
33 scaledAnalogValue = 0.0;
36 scaledAnalogValue = scaledAnalogValue * velocityMultiplier;
37 averageAnalog = (alpha * scaledAnalogValue) + (1.0 - alpha) * averageAnalog;
38 targetVelocity = averageAnalog * averageAnalog * averageAnalog;
40 AxisMoveVelocity(axis, targetVelocity, acceleration);
46 print(MethodTiming(counterStart, i) +
"ms per loop. total loops = " + i +
" loops.");
49double MethodTiming(int32 start, int32 loops)
51 int32 end = ControllerSampleCounterGet();
52 return (end - start) / loops;
Learn more in topic page.