Motor Motion Profiling (Android Studio)

advanced60 min

What is Motion Profiling?

A motion profile plans how fast the mechanism should move over time—ramp up, cruise, ramp down—instead of jumping straight to full power. That reduces wheel slip, tipping, and overshoot on arms and drivetrains.

Types of Motion Profiles

  • Trapezoidal: Accelerates to a constant speed, maintains it, then decelerates.
  • S-curve: Smooths out acceleration and deceleration for even less jerk.
  • Custom: You can design your own profiles for special tasks.

Generating a Trapezoidal Profile in Java

Trapezoidal profile: compute accel, cruise, and decel phases for a target distance:

double maxVel = 30; // inches/sec
double maxAccel = 60; // inches/sec^2
double distance = 48; // inches

double accelTime = maxVel / maxAccel;
double accelDist = 0.5 * maxAccel * accelTime * accelTime;
double cruiseDist = distance - 2 * accelDist;
double cruiseTime = cruiseDist / maxVel;
double totalTime = 2 * accelTime + cruiseTime;

// At each time step, calculate target velocity and position
for (double t = 0; t < totalTime; t += 0.02) {
    double vel, pos;
    if (t < accelTime) {
        vel = maxAccel * t;
        pos = 0.5 * maxAccel * t * t;
    } else if (t < accelTime + cruiseTime) {
        vel = maxVel;
        pos = accelDist + maxVel * (t - accelTime);
    } else {
        double dt = t - (accelTime + cruiseTime);
        vel = maxVel - maxAccel * dt;
        pos = accelDist + cruiseDist + maxVel * dt - 0.5 * maxAccel * dt * dt;
    }
    // Use vel and pos as setpoints for your PID controller
}

Combining Motion Profiling with PID and Feedforward

Each profile sample gives a target position and velocity. PID closes position error; feedforward adds expected voltage from velocity and acceleration so PID does less work. gm0: Feedforward control

Following a Profile with PID and Feedforward

PID plus velocity/acceleration feedforward on each profile point:

double kV = 1.0 / maxVel; // Velocity gain
double kA = 0.1; // Acceleration gain

for (ProfilePoint pt : profile) {
    double error = pt.position - getCurrentPosition();
    double pidOut = pid.calculate(error);
    double ffOut = kV * pt.velocity + kA * pt.acceleration;
    double output = pidOut + ffOut;
    motor.setPower(Range.clip(output, -1, 1));
    // Wait for next time step
}

Practical FTC Examples

  • Profile auto drives and large arm moves where jerk causes slip or bounce.
  • Road Runner and similar libraries generate profiles and followers for FTC drivetrains.

Troubleshooting and Tuning

  • If motion is jerky, lower max acceleration or tune PID gains.
  • If the robot overshoots, increase deceleration or tune PID/FF gains.
  • Use telemetry to plot position, velocity, and error for debugging.

Additional Resources