public class SCurve extends Object
.
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).
| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public static final double ALPHA
public static final double BETA
private static final double ACCURACY
private static final double BETAMIN
private static final int ITERATION
private double alpha
private double beta
private double gamma
private double delta
private double j0
private double d
private double az
private double vz
private double xz
private double aend
private double vend
private double tm
private double ts
private double titerate
private double aiterate
private double biterate
public SCurve()
public SCurve(double a,
double b)
public void setJerkTime(double a)
public void setConstantSpeedTime(double b)
public void setJerkConstant(double j)
public void setDistance(double dist)
public void setZero(double a0,
double v0,
double x0)
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.public void startMovement(double start)
start - The start time in seconds, used as an offset.public double getJerk(double tnow)
tnow - Time in second. Start time is subtracted.public double getAcceleration(double tnow)
tnow - Time in second. Start time is subtracted.public double getVelocity(double tnow)
tnow - Time in second. Start time is subtracted.public double getDistance(double tnow)
tnow - Time in second. Start time is subtracted.public double getAccMax()
public double getVelMax()
v_max=2./(1+β)ċv_av.
public double getTravelTime()
private int getRegion(double t)
private double deriveTravelTime(double j,
double al,
double be)
private boolean iterateGammaDelta(double tinit,
double j,
double al,
double be)