stella.util
Class SCurve

java.lang.Object
  extended by stella.util.SCurve

public class SCurve
extends Object

A class that simulates the movement of most modern motors, the S-curve movement. This movement is characterized by four different pulses in the jerk (time-derivative of the acceleration), positive, negative, negative, and positive that advances the motor in a very smooth fashion. Accelaration, velocity, and displacement follow curves like

. The s-curve has an analytical solution. This class allows querying of current jerk, acceleration, velocity and distance, as soon as the jerk constant, the α and β time fractions and the distance to travel have been set. For overlaying two S-curve movements, consider that the jerk is the prescribed function, thus from the previous S-curve the acceleration, velocity, and displacement are the boundary conditions to the differential equations. For non-zero BC, the time of the movement gets a cubic equation with non-vanishing quadratic and linear terms. Set non-zero BC with a call to setZero(double, double, double).


Nested Class Summary
static class SCurve.Offset
          A test class that reads d, j0, alpha, and beta from the command line and then splits the time into 10000 steps, where current values of the jerk, the acceleration, the velocity, and the distance are printed to system.out.
 
Field Summary
private static double ACCURACY
          For recursive lengthen/shortening of intervals, accuracy to reach.
private  double aend
          The acceleration at end time.
private  double aiterate
          During iteration this gets to alpha.
private  double alpha
          The current value of the jerk time fraction.
static double ALPHA
          A default value for the jerk time fraction, α.
private  double az
          The acceleration at starting time.
private  double beta
          The current value of the constant speed time fraction.
static double BETA
          A default value for the constant speed time fraction, β.
private static double BETAMIN
          The minimum beta, if everything fails.
private  double biterate
          During iteration this gets to beta.
private  double d
          The distance to travel.
private  double delta
          The relative change of the constant-acceleration period due to vz.
private  double gamma
          The relative change of the constant-jerk periods to compensate az.
private static int ITERATION
          For recursive lengthen/shortening of intervals, maximum iterations
private  double j0
          The jerk constant, i.e.
private  double titerate
          During iteration this gets to travel time.
private  double tm
          The time needed for traveling d, calculated.
private  double ts
          Starting time for arbitrary offsets.
private  double vend
          The velocity at end time.
private  double vz
          The velocity at starting time.
private  double xz
          The displacement at starting time.
 
Constructor Summary
SCurve()
          Constructs a new s-curve object.
SCurve(double a, double b)
          Constructs a new s-curve object specifying the jerk time fraction and the constatn-speed time fraction.
 
Method Summary
private  double deriveTravelTime(double j, double al, double be)
          Calculates the travel time for non-vanishing BC.
 double getAcceleration(double tnow)
          Gets the current acceleration in rad/s^2.
 double getAccMax()
          Returns the maximum acceleration excerted within the motor.
 double getDistance(double tnow)
          Gets the current distance travelled since the start of the movement, in rad.
 double getJerk(double tnow)
          Gets the current jerk.
private  int getRegion(double t)
          Returns the index of the region where t is located.
 double getTravelTime()
          Return the time required for the offset to complete in seconds.
 double getVelMax()
          Returns the maximum speed encountered during the movement.
 double getVelocity(double tnow)
          Gets the current speed in rad/s.
private  boolean iterateGammaDelta(double tinit, double j, double al, double be)
          Tries to get a solution for gamma, delta that satisfy a=0 & v=0 at end of movement.
 void setConstantSpeedTime(double b)
          Specifies a new contant-speed time fraction.
 void setDistance(double dist)
          Sets the distance to travel in rad.
 void setJerkConstant(double j)
          Sets the jerk constant in rad/s^3.
 void setJerkTime(double a)
          Specifies a new jerk-time fraction.
 void setZero(double a0, double v0, double x0)
          Sets the boundary condition.
 void startMovement(double start)
          Starts the s-curve movement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALPHA

public static final double ALPHA
A default value for the jerk time fraction, α.

See Also:
Constant Field Values

BETA

public static final double BETA
A default value for the constant speed time fraction, β.

See Also:
Constant Field Values

ACCURACY

private static final double ACCURACY
For recursive lengthen/shortening of intervals, accuracy to reach.

See Also:
Constant Field Values

BETAMIN

private static final double BETAMIN
The minimum beta, if everything fails.

See Also:
Constant Field Values

ITERATION

private static final int ITERATION
For recursive lengthen/shortening of intervals, maximum iterations

See Also:
Constant Field Values

alpha

private double alpha
The current value of the jerk time fraction.


beta

private double beta
The current value of the constant speed time fraction.


gamma

private double gamma
The relative change of the constant-jerk periods to compensate az.


delta

private double delta
The relative change of the constant-acceleration period due to vz.


j0

private double j0
The jerk constant, i.e. the total jerk in the four jerk times.


d

private double d
The distance to travel.


az

private double az
The acceleration at starting time.


vz

private double vz
The velocity at starting time.


xz

private double xz
The displacement at starting time.


aend

private double aend
The acceleration at end time.


vend

private double vend
The velocity at end time.


tm

private double tm
The time needed for traveling d, calculated.


ts

private double ts
Starting time for arbitrary offsets.


titerate

private double titerate
During iteration this gets to travel time.


aiterate

private double aiterate
During iteration this gets to alpha.


biterate

private double biterate
During iteration this gets to beta.

Constructor Detail

SCurve

public SCurve()
Constructs a new s-curve object.


SCurve

public SCurve(double a,
              double b)
Constructs a new s-curve object specifying the jerk time fraction and the constatn-speed time fraction.

Method Detail

setJerkTime

public void setJerkTime(double a)
Specifies a new jerk-time fraction. Must be positive and smaller than 0.25.


setConstantSpeedTime

public void setConstantSpeedTime(double b)
Specifies a new contant-speed time fraction. Must be positive and smaller than one.


setJerkConstant

public void setJerkConstant(double j)
Sets the jerk constant in rad/s^3. This jerk is exerted on the motor on four different times, starting with positive jerk, then negative, negative, and positive jerk again.


setDistance

public void setDistance(double dist)
Sets the distance to travel in rad.


setZero

public void setZero(double a0,
                    double v0,
                    double x0)
Sets the boundary condition. This is the acceleration, the velocity and the displacement at start time.

Parameters:
a0 - The acceleration at start time from previous movement.
v0 - The velocity at start time from previous movement.
x0 - The displacement at start time from previous movement.

startMovement

public void startMovement(double start)
Starts the s-curve movement. This method throws an exception if the jerk constant or the distance-to-travel are not set. Additionally, if the sign of the jerk is not equal to the sign of the distance, an exception is thrown as in this case the required distance will not be reached in a meaningful way.
After a start to this method, current distance travelled, speed, acceleration and jerk can be queried.

Parameters:
start - The start time in seconds, used as an offset.

getJerk

public double getJerk(double tnow)
Gets the current jerk.

Parameters:
tnow - Time in second. Start time is subtracted.

getAcceleration

public double getAcceleration(double tnow)
Gets the current acceleration in rad/s^2.

Parameters:
tnow - Time in second. Start time is subtracted.

getVelocity

public double getVelocity(double tnow)
Gets the current speed in rad/s.

Parameters:
tnow - Time in second. Start time is subtracted.

getDistance

public double getDistance(double tnow)
Gets the current distance travelled since the start of the movement, in rad. Note that formulars are for antisymmetric x, thus the half offset is added at each region.

Parameters:
tnow - Time in second. Start time is subtracted.

getAccMax

public double getAccMax()
Returns the maximum acceleration excerted within the motor. This acceleration is experienced two times, shortly after the start of the movement and again close to the end of the movement.


getVelMax

public double getVelMax()
Returns the maximum speed encountered during the movement. This speed occurs around the middle of the movement, its length fraction equals β. Note that this maximum velocity has an alpha-independant relation to the average velocity according to
       v_max=2./(1+β)ċv_av.
       


getTravelTime

public double getTravelTime()
Return the time required for the offset to complete in seconds.


getRegion

private int getRegion(double t)
Returns the index of the region where t is located. -1 and 7 denote regions outside the main movement.


deriveTravelTime

private double deriveTravelTime(double j,
                                double al,
                                double be)
Calculates the travel time for non-vanishing BC. Uses Newton approximation, starting value is the solution of the cubic equation in travel time. Takes primary time fraction as arguments.


iterateGammaDelta

private boolean iterateGammaDelta(double tinit,
                                  double j,
                                  double al,
                                  double be)
Tries to get a solution for gamma, delta that satisfy a=0 & v=0 at end of movement.