The RMP Motion Controller APIs
Axis Analog Jogging

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.

1void main()
2{
3 // user sets these values
4 uint32 axis = 0;
5 int32 analogChannel = 0;
6 double analogMidrange = 10000.0;
7 double analogDeadband = 100;
8 double velocityMultiplier = 0.01;
9 double alpha = 0.1;
10
11
12 // internals
13 int32 i = 0;
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;
20
21 AxisClearFaults(axis);
22 AxisAmpEnableSet(axis,true);
23 double acceleration = AxisDefaultAccelerationGet(axis);
24
25 counterStart = ControllerSampleCounterGet();
26 while(AxisAmpEnableGet(axis))
27 {
28 rawAnalogValue = AxisAnalogInGet(axis, analogChannel);
29 scaledAnalogValue = rawAnalogValue - analogMidrange;
30
31 if( abs(scaledAnalogValue) < analogDeadband)
32 {
33 scaledAnalogValue = 0.0;
34 }
35
36 scaledAnalogValue = scaledAnalogValue * velocityMultiplier; // multiplier
37 averageAnalog = (alpha * scaledAnalogValue) + (1.0 - alpha) * averageAnalog; // exponential moving average
38 targetVelocity = averageAnalog * averageAnalog * averageAnalog; // cubic velocity
39
40 AxisMoveVelocity(axis, targetVelocity, acceleration);
41 wait(0.005); // no need to change velocity faster than every 5ms
42
43 //print("analog: " + scaledAnalogValue + " velocity: " + targetVelocity + " loops: " + i);
44 ++i;
45 }
46 print(MethodTiming(counterStart, i) + "ms per loop. total loops = " + i + " loops.");
47}
48
49double MethodTiming(int32 start, int32 loops)
50{
51 int32 end = ControllerSampleCounterGet();
52 return (end - start) / loops;
53}

Learn more in topic page.