samples.c File Reference

Introduction

Implementation of the auxiliary functions to deal with sets of samples.

See also
samples.h

Definition in file samples.c.

Macros

#define DISPERSION   1
 Evenly distribute points on the path. More...
 
#define REMOVE_POINTS   ((DISPERSION)&&(1))
 To remove points when optimizint paths via gradient. More...
 
#define APPROXIMATED_CHARTS_IN_GRADIENT   1
 Speed up gradient smooth by using approximated charts. More...
 

Functions

double StepDispersion (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xp, double *x, double *xn, unsigned int current, Tchart *cp, Tchart *c, Tchart *cn, Tworld *w)
 Dispersion path step. More...
 
boolean StepDispersionGradient (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Gradient of the step dispersion penalty term. More...
 
double StepLength (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xp, double *x, double *xn, unsigned int current, Tchart *cp, Tchart *c, Tchart *cn, Tworld *w)
 Length path step. More...
 
boolean StepLengthGradient (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Gradient of the length of a path step. More...
 
double StepEffort (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xp, double *x, double *xn, unsigned int current, Tchart *cp, Tchart *c, Tchart *cn, Tworld *w)
 Control effort of a path step. More...
 
boolean StepEffortGradient (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Gradient of the control effort of a path step. More...
 
boolean StepCostNumericalGradient (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Generic numerical gradient. More...
 
double CombineCosts (TStepCost c1, TStepCost c2, Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xp, double *x, double *xn, unsigned int current, Tchart *cp, Tchart *c, Tchart *cn, Tworld *w)
 Combines two cost functions. More...
 
boolean CombineGradients (TStepCostGradient g1, TStepCostGradient g2, Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Combines two gradients. More...
 
double LengthAndDispersion (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xp, double *x, double *xn, unsigned int current, Tchart *cp, Tchart *c, Tchart *cn, Tworld *w)
 Combines length and dispersion cost functions. More...
 
boolean LengthAndDispersionGradient (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Gradient of the length and dispersion. More...
 
double EffortAndDispersion (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xp, double *x, double *xn, unsigned int current, Tchart *cp, Tchart *c, Tchart *cn, Tworld *w)
 Combines control effort and dispersion cost functions. More...
 
boolean EffortAndDispersionGradient (Tparameters *p, unsigned int *tp, boolean *sv, unsigned int m, double *xpp, double *xp, double *x, double *xn, double *xnn, Tchart *cpp, Tchart *cp, Tchart *c, Tchart *cn, Tchart *cnn, TJacobian *sJ, TStepCost cost, double *u, Tworld *w)
 Gradient of the effort and dispersion. More...
 
int cmpUInt (const void *a, const void *b)
 Compares two unsigned in integers. More...
 
void ShortcutSmooth (Tparameters *pr, boolean *sv, Tstatistics *stime, unsigned int *np, double ***point, TAtlasBase *w)
 Fixed-cut based smoothing. More...
 
void RandomSmooth (Tparameters *pr, unsigned int nCores, unsigned int maxIterations, boolean *sv, Tstatistics *stime, unsigned int *np, double ***point, TAtlasBase *w)
 Random-based path smoothing. More...
 
void GradientSmooth (Tparameters *pr, unsigned int nCores, unsigned int maxIterations, boolean *sv, Tstatistics *stime, unsigned int *np, double ***point, TStepCost stepCost, TStepCostGradient stepCostGradient, TAtlasBase *w)
 Gradient-based path smoothing. More...
 
void SaveSamplesInt (Tfilename *fpath, unsigned int nvs, unsigned int ns, double **path, unsigned int da, double **action, double *time)
 Internal function to save a set of samples to a file. More...
 
void InitSamples (unsigned int *ms, unsigned int *ns, double ***path)
 Initializes a set of samples. More...
 
void InitSamplesReplay (unsigned int *ms, unsigned int *ns, double ***path, boolean **newChart, double **time, double **cost)
 Initializes a set of samples with flag. More...
 
void InitTrajectory (unsigned int *ms, unsigned int *ns, double ***path, unsigned int da, double ***actions, double **times)
 Initializes a trajectory. More...
 
void AddSample2Samples (unsigned int nv, double *sample, unsigned int nvs, boolean *systemVars, unsigned int *ms, unsigned int *ns, double ***path)
 Adds a sample to a set of samples. More...
 
void AddSample2SamplesReplay (unsigned int nv, double *sample, boolean nc, double h, double c, unsigned int nvs, boolean *systemVars, unsigned int *ms, unsigned int *ns, double ***path, boolean **newChart, double **time, double **cost)
 Adds a sample to a set of samples for replay. More...
 
void AddStep2Trajectory (unsigned int nv, double *sample, unsigned int nvs, boolean *systemVars, double *action, double time, unsigned int *ms, unsigned int *ns, double ***path, unsigned int da, double ***actions, double **times)
 Adds a step to a trajectory. More...
 
double ConnectDynamicStatesID (Tparameters *pr, unsigned int *tp, Tbox *ambient, boolean collision, unsigned int m, unsigned int k, unsigned int da, double *state, double *action, double time, double *goal, unsigned int *ns, double ***path, double ***actions, double **times, TJacobian *J, TDynamicSpace *ds, TAtlasBase *w)
 Forwarnd integration of the equations of motion. More...
 
double ConnectDynamicStates (Tparameters *pr, unsigned int *tp, Tbox *ambient, boolean collision, unsigned int m, unsigned int k, unsigned int da, double *state, double *action, double time, double *goal, unsigned int *ns, double ***path, double ***actions, double **times, TJacobian *J, TDynamicSpace *ds, TAtlasBase *w)
 Forwarnd integration of the equations of motion. More...
 
double ConnectSamplesChart (Tparameters *pr, unsigned int *tp, boolean *sv, Tbox *domain, unsigned int m, unsigned int n, double *s1, double *s2, double md, boolean checkCollisions, TJacobian *sJ, boolean *reached, boolean *collision, double *lastSample, unsigned int *ns, double ***path, TAtlasBase *w)
 Determines the connection between two points on the manifold. More...
 
double ConnectSamples (Tparameters *pr, unsigned int *tp, boolean *sv, Tbox *domain, unsigned int m, unsigned int n, double *s1, double *s2, double md, boolean checkCollisions, TJacobian *sJ, boolean *reached, boolean *collision, double *lastSample, unsigned int *ns, double ***path, TAtlasBase *w)
 Determines the connection between two points on the manifold. More...
 
double PathLength (unsigned int *tp, boolean *sv, unsigned int m, unsigned int np, double **point)
 Length of a path formed by a set of samples. More...
 
double PathEffort (Tparameters *p, unsigned int m, unsigned int np, double **point, Tworld *w)
 Approximated control effort of a path. More...
 
void SmoothSamples (Tparameters *pr, boolean parallel, int mode, unsigned int maxIterations, unsigned int ns, double **path, unsigned int *sns, double ***spath, TAtlasBase *w)
 Path smoothing. More...
 
void ConcatSamples (unsigned int nvs, unsigned int ns1, double **path1, unsigned int ns2, double **path2, unsigned int *ns, double ***path)
 Concats two path. More...
 
void ReverseConcatSamples (unsigned int nvs, unsigned int ns1, double **path1, unsigned int ns2, double **path2, unsigned int *ns, double ***path)
 Reverses and concats a path. More...
 
void ReverseConcatTrajectories (unsigned int nvs, unsigned int da, unsigned int ns1, double **path1, double **action1, double *time1, unsigned int ns2, double **path2, double **action2, double *time2, unsigned int *ns, double ***path, double ***action, double **time)
 Reverses and concats a trajectory. More...
 
void ReverseSamples (unsigned int ns, double **path)
 Reverses a set of samples. More...
 
unsigned int ReadOneSample (Tparameters *p, char *fname, unsigned int nvs, double **s)
 Reads one sample from a file. More...
 
unsigned int ReadTwoSamples (Tparameters *p, char *fname, unsigned int nvs, double **s1, double **s2)
 Reads two samples from a file. More...
 
void SaveSamples (char *fname, char *suffix, unsigned int nvs, unsigned int ns, double **path)
 Saves a set of samples to a file. More...
 
void SaveTrajectory (char *fname, char *suffix, unsigned int nvs, unsigned int ns, double **path, unsigned int da, double **action, double *time)
 Saves a set of samples to a file including action and timing information. More...
 
void SaveSamplesN (char *fname, boolean smooth, unsigned int n, unsigned int nvs, unsigned int ns, double **path)
 Saves a set of samples to a file. More...
 
boolean LoadSamples (Tfilename *fname, unsigned int *nvs, unsigned int *ns, double ***path)
 Reads a set of samples from file. More...
 
boolean LoadTrajectory (Tfilename *fname, unsigned int *nvs, unsigned int *ns, double ***path, unsigned int *da, double ***action, double **time)
 Reads a trajectory from file. More...
 
void SparsifyTrajectory (double tm, unsigned int **id, unsigned int *ns, double **path, double **action, double *time)
 Ensures a mininum time between two consecutive trajectory steps. More...
 
void PlotSamples (Tparameters *p, Tplot3d *p3d, unsigned int xID, unsigned int yID, unsigned int zID, unsigned int ns, double **path)
 Plots a 3D projection of a path. More...
 
void PlotForceField (Tparameters *p, Tplot3d *p3d, unsigned int xID, unsigned int yID, unsigned int zID, Tworld *w, unsigned int ns, double **sols)
 Plots the force-field on a set of points. More...
 
void DeleteSamples (unsigned int ns, double **path)
 Deletes the space used by a set of samples. More...
 
void DeleteSamplesReplay (unsigned int ns, double **path, boolean *newChart, double *time, double *cost)
 Deletes the space used by a set of samples with flags. More...
 
void DeleteTrajectory (unsigned int ns, double **path, double **action, double *time)
 Deletes the space used by a trajectory. More...
 

Macro Definition Documentation

◆ DISPERSION

#define DISPERSION   1

If set, the cost and the gradient are complemented with a penalty term that penalized path steps with different lengths. In other words, we try to evenly distribute the steps along the path.

Long steps are too far from the manifold and, thus, they introduce large errors, but they are shorter that paths that closely follow the manifold. This is way long steps often appear when minimizing the path length (and related measures) since the error with respect to the manifold is not taken into account.

Long steps appear more often if we remove steps along the paths (if we remove the points that are very close the its neightours). In this case the minimization of the dispersion is a must

See also
REMOVE_POINTS.

See StepDispersion and StepDispersionGradient.

Definition at line 46 of file samples.c.

◆ REMOVE_POINTS

#define REMOVE_POINTS   ((DISPERSION)&&(1))

If set, we remove the points that are too close each other during the path gradient optimization.

It can only be set if DISPERSION is also set.

Definition at line 56 of file samples.c.

◆ APPROXIMATED_CHARTS_IN_GRADIENT

#define APPROXIMATED_CHARTS_IN_GRADIENT   1

When displacing a point along a gradient we have to compute the chart at this point. Howerver, this chart is very close to the chart at the original point (the point before the gradient displacement. If this flag is set, we use the already computed chart as an approximation of the chart at the new point.

Todo:
Verify that this results in actual speed up.

Definition at line 71 of file samples.c.

Function Documentation

◆ StepDispersion()

double StepDispersion ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xp,
double *  x,
double *  xn,
unsigned int  current,
Tchart cp,
Tchart c,
Tchart cn,
Tworld w 
)

Penalizes path steps that have different length. This is used to evenly distribute the path step along the path.

For a path sequence (x_1,x_2,x_3), the formula to optimize is

  • (|x_2-x_1|-|x_3-x_2|)^2

i.e., penalizes the difference in length of the two path steps around x_2. This is applied for all points on the path (except for 'stalled' points, i.e., points that can not be moved due to collision, for instance).

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xpFirst point in the path (simplified).
xSecond point along the path. This is the point used to compute the cost.
xnThird point along the path.
currentWhich of the three points is the current (i.e., the point for which we evaluate the cost).
cpChart on c1. Atually not used. Can be NULL.
cChart on c2. Atually not used. Can be NULL.
cnChart on c3. Atually not used. Can be NULL.
wThe world structure.

Definition at line 1380 of file samples.c.

References DistanceTopologySubset().

Referenced by CombineGradients(), EffortAndDispersion(), LengthAndDispersion(), and SmoothSamples().

◆ StepDispersionGradient()

boolean StepDispersionGradient ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)

Gradient of the StepDispersion cost funtion.

Note that the actual position of a point (say x_3) affects the cost of different triplets of points

  • (x_1,x_2,x_3)
  • (x_2,x_3,x_4)
  • (x_3,x_4,x_5)

We have to accumulate the gradient in the three cases. This is why this function consideres sequences of 5 points (x_1,x_2,x_3,x_4,x_5), but returns the derivative w.r.t x_3.

Note that the step dispersion is orthogonal ot any other cost to evaluate on the path. Thus it can be applied on the top of different cost functions (path length, path effort, ...).

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppFirst point in the sequence. NULL at the beginning of the path.
xpSecond point in the sequence.
xThird point in the sequence.
xnFourth point in the sequence.
xnnFith point in the sequence. NULL at the end of the path.
cppChart at xpp.
cpChart at xp.
cChart at x.
cnChart at xn.
cnnChart at xnn.
sJThe symbolic Jacobian of the constraints. Not used. Can be NULL.
costCost function. Not used. Can be NULL.
uThe resulting gradient (in tangent space!) of the cost function w.r.t. x_3.
wThe world structure.
Returns
TRUE if the gradient could be computed.

Definition at line 1403 of file samples.c.

References CT_EPSILON, CT_N_DOF, DifferenceVectorTopologySubset(), DistanceTopologySubset(), FALSE, GetChartTangentSpace(), GetParameter(), NEW, Norm(), ScaleVector(), SumVectorScale(), TMatrixVectorProduct(), and TRUE.

Referenced by EffortAndDispersionGradient(), LengthAndDispersionGradient(), and SmoothSamples().

◆ StepLength()

double StepLength ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xp,
double *  x,
double *  xn,
unsigned int  current,
Tchart cp,
Tchart c,
Tchart cn,
Tworld w 
)

Auxiliary function used to compute the path length.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xpFist poinnt in the path. Not used. Can be NULL.
xSecond point in the path (simplified).
xnpoint along the path. Not used. Can be NULL.
currentWhich of the three points is the current (i.e., the point for which we evaluate the cost).
cpA chart on xp
cA chart defined on x.
cnA chart defined on xn. Not used. Cam be NULL.
wThe world structure.

Definition at line 1471 of file samples.c.

References DistanceTopologySubset(), and Error().

Referenced by CombineGradients(), EffortAndDispersionGradient(), LengthAndDispersion(), LengthAndDispersionGradient(), and SmoothSamples().

◆ StepLengthGradient()

boolean StepLengthGradient ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)

Auxiliary function used to compute the gradient of a path step length (see StepLength).

It is used also when smoothing a path via gradient descent.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppPrevious of the previous point in the path. Not used. Can be NULL.
xpPrevious point in the path.
xCurrent point. We compute the gradient with respect to this point.
xnNext point in the path.
xnnNext of the next point in the path. Not used. Can be NULL.
cppChart at xpp. Not used. Can be NULL.
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn.
cnnChart at xnn. Not used. Can be NULL.
sJThe symbolic Jacobian of the constraints.
costCost function.
uThe output gradient (in tangent space!)
wThe world structure.
Returns
TRUE if the gradient can be actually computed.

Definition at line 1492 of file samples.c.

References CT_EPSILON, CT_N_DOF, DifferenceVectorTopologySubset(), FALSE, GetChartTangentSpace(), GetParameter(), NEW, Norm(), ScaleVector(), SumVectorScale(), TMatrixVectorProduct(), and TRUE.

Referenced by LengthAndDispersionGradient(), and SmoothSamples().

◆ StepEffort()

double StepEffort ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xp,
double *  x,
double *  xn,
unsigned int  current,
Tchart cp,
Tchart c,
Tchart cn,
Tworld w 
)

Auxiliary function used to compute the path control effort (see PathEffort).

Computes the control effort of moving from x1 to x2 taking into account the drift introduced by the potential energy gradient. If there is no such a gradient, the output is close to the step length.

Note that we actually compute and approximation of the control effort. The shorter the steps in the path, the closer the approximation.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xpPrevious point in the path. Actually not used. Can be NULL.
xCurrent point in the path (simplified).
xnNext point along the path.
currentWhich of the three points is the current (i.e., the point for which we evaluate the cost).
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn. Actually not used. Can be NULL.
wThe world structure.

Definition at line 1543 of file samples.c.

References CT_EPSILON, CT_N_DOF, DifferenceVector(), DifferenceVectorTopologySubset(), Error(), GeneralDotProduct(), GetChartTangentSpace(), GetParameter(), KINEMATIC_SUBSPACE, NEW, Norm(), ScaleVector(), TMatrixVectorProduct(), TRUE, and WorldForceField().

Referenced by EffortAndDispersion(), PathEffort(), and SmoothSamples().

◆ StepEffortGradient()

boolean StepEffortGradient ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)

Auxiliary function used to compute the gradient of a path step control effort (see StepEffort).

This is also used to smooth a path via gradient descent.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppPrevious of the previous point in the path. Not used. Can be NULL.
xpPrevious point in the path.
xCurrent point. We compute the gradient with respect to this point.
xnNext point in the path.
xnnNext of the next point in the path. Not used. Can be NULL.
cppChart at xpp. Not used. Can be NULL.
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn.
cnnChart at xnn. Not used. Can be NULL.
sJThe symbolic Jacobian of the constraints.
costCost function.
uThe output gradient (in tangent space!)
wThe world structure.
Returns
TRUE if the gradient can be actually computed.

Definition at line 1612 of file samples.c.

References CT_EPSILON, CT_N_DOF, DifferenceVector(), DifferenceVectorTopologySubset(), Error(), FALSE, GeneralDotProduct(), GetChartTangentSpace(), GetParameter(), MatrixVectorProduct(), NEW, Norm(), ScaleVector(), SumVectorScale(), TMatrixVectorProduct(), TRUE, WorldForceField(), and WorldForceFieldProjectedGradient().

Referenced by EffortAndDispersionGradient(), and SmoothSamples().

◆ StepCostNumericalGradient()

boolean StepCostNumericalGradient ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)

Numerical gradient. Works for any cost function but it is slower than a specific gradient.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppPrevious of the previous point in the path. Not used. Can be NULL.
xpPrevious point in the path.
xCurrent point. We compute the gradient with respect to this point.
xnNext point in the path.
xnnNext of the next point in the path. Not used. Can be NULL.
cppChart at xpp. Not used. Can be NULL.
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn.
cnnChart at xnn. Not used. Can be NULL.
sJThe symbolic Jacobian of the constraints.
costCost function.
uThe output gradient (in tangent space!)
wThe world structure.
Returns
TRUE if the gradient can be actually computed.

Definition at line 1826 of file samples.c.

References Chart2Manifold(), CT_EPSILON, CT_N_DOF, FALSE, GetParameter(), INF, NEW, and TRUE.

Referenced by GradientSmooth().

◆ CombineCosts()

double CombineCosts ( TStepCost  c1,
TStepCost  c2,
Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xp,
double *  x,
double *  xn,
unsigned int  current,
Tchart cp,
Tchart c,
Tchart cn,
Tworld w 
)
inline

Adds two cost functions.

Parameters
c1The first cost function to add.
c2The second cost function to add.
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xpPrevious point in the path. Actually not used. Can be NULL.
xCurrent point in the path (simplified).
xnNext point along the path.
currentWhich of the three points is the current (i.e., the point for which we evaluate the cost).
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn. Actually not used. Can be NULL.
wThe world structure.

Definition at line 1879 of file samples.c.

Referenced by EffortAndDispersion(), and LengthAndDispersion().

◆ CombineGradients()

boolean CombineGradients ( TStepCostGradient  g1,
TStepCostGradient  g2,
Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)
inline

Gradient of CombineCosts (if called with the right set of parameters).

Parameters
g1The first gradient to add.
g2Teh second gradient to add.
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppPrevious of the previous point in the path. Not used. Can be NULL.
xpPrevious point in the path.
xCurrent point. We compute the gradient with respect to this point.
xnNext point in the path.
xnnNext of the next point in the path. Not used. Can be NULL.
cppChart at xpp. Not used. Can be NULL.
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn.
cnnChart at xnn. Not used. Can be NULL.
sJThe symbolic Jacobian of the constraints.
costCost function.
uThe output gradient (in tangent space!)
wThe world structure.
Returns
TRUE if the gradient can be actually computed.

Definition at line 1890 of file samples.c.

References CT_N_DOF, GetParameter(), NEW, StepDispersion(), StepLength(), and SumVector().

Referenced by EffortAndDispersionGradient(), and LengthAndDispersionGradient().

◆ LengthAndDispersion()

double LengthAndDispersion ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xp,
double *  x,
double *  xn,
unsigned int  current,
Tchart cp,
Tchart c,
Tchart cn,
Tworld w 
)
inline

Adds the length and dispersion cost functions. See CombineCosts.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xpPrevious point in the path. Actually not used. Can be NULL.
xCurrent point in the path (simplified).
xnNext point along the path.
currentWhich of the three points is the current (i.e., the point for which we evaluate the cost).
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn. Actually not used. Can be NULL.
wThe world structure.

Definition at line 1926 of file samples.c.

References CombineCosts(), StepDispersion(), and StepLength().

Referenced by SmoothSamples().

◆ LengthAndDispersionGradient()

boolean LengthAndDispersionGradient ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)
inline

Gradient of LengthAndDispersion.

See CombineGradients.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppPrevious of the previous point in the path. Not used. Can be NULL.
xpPrevious point in the path.
xCurrent point. We compute the gradient with respect to this point.
xnNext point in the path.
xnnNext of the next point in the path. Not used. Can be NULL.
cppChart at xpp. Not used. Can be NULL.
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn.
cnnChart at xnn. Not used. Can be NULL.
sJThe symbolic Jacobian of the constraints.
costCost function.
uThe output gradient (in tangent space!)
wThe world structure.
Returns
TRUE if the gradient can be actually computed.

Definition at line 1936 of file samples.c.

References CombineGradients(), StepDispersionGradient(), StepLength(), and StepLengthGradient().

Referenced by SmoothSamples().

◆ EffortAndDispersion()

double EffortAndDispersion ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xp,
double *  x,
double *  xn,
unsigned int  current,
Tchart cp,
Tchart c,
Tchart cn,
Tworld w 
)
inline

Adds the control effort and dispersion cost functions.

See CombineCosts.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xpPrevious point in the path. Actually not used. Can be NULL.
xCurrent point in the path (simplified).
xnNext point along the path.
currentWhich of the three points is the current (i.e., the point for which we evaluate the cost).
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn. Actually not used. Can be NULL.
wThe world structure.

Definition at line 1951 of file samples.c.

References CombineCosts(), StepDispersion(), and StepEffort().

Referenced by SmoothSamples().

◆ EffortAndDispersionGradient()

boolean EffortAndDispersionGradient ( Tparameters p,
unsigned int *  tp,
boolean sv,
unsigned int  m,
double *  xpp,
double *  xp,
double *  x,
double *  xn,
double *  xnn,
Tchart cpp,
Tchart cp,
Tchart c,
Tchart cn,
Tchart cnn,
TJacobian sJ,
TStepCost  cost,
double *  u,
Tworld w 
)
inline

Gradient of EffortAndDispersion.

See CombineGradients.

Parameters
pThe set of parameters.
tpThe topology of the variables (in simplified system).
svThe selected variables to compute the path length component of the effort.
mThe size of the points (in simplified system!)
xppPrevious of the previous point in the path. Not used. Can be NULL.
xpPrevious point in the path.
xCurrent point. We compute the gradient with respect to this point.
xnNext point in the path.
xnnNext of the next point in the path. Not used. Can be NULL.
cppChart at xpp. Not used. Can be NULL.
cpA chart defined on xp.
cA chart defined on x.
cnA chart defined on xn.
cnnChart at xnn. Not used. Can be NULL.
sJThe symbolic Jacobian of the constraints.
costCost function.
uThe output gradient (in tangent space!)
wThe world structure.
Returns
TRUE if the gradient can be actually computed.

Definition at line 1961 of file samples.c.

References CombineGradients(), StepDispersionGradient(), StepEffortGradient(), and StepLength().

Referenced by SmoothSamples().

◆ cmpUInt()

int cmpUInt ( const void *  a,
const void *  b 
)

Auxiliary function used for qsort inside RandomSmooth when we exploit parallelism to speed up the smoothing.

Parameters
aPointer to the first unsigned integer.
bPointer to the second unsigned integer.
Returns
-1 if a<b, 0 if a==b, or 1 if a>b.

Definition at line 2071 of file samples.c.

Referenced by RandomSmooth().

◆ ShortcutSmooth()

void ShortcutSmooth ( Tparameters pr,
boolean sv,
Tstatistics stime,
unsigned int *  np,
double ***  point,
TAtlasBase w 
)

This is like the RandomSmooth but the tentative shortcuts are selected systematically: from the first sample as far as possible and so on.

Parameters
prThe set of parameters.
svThe variables to use in the distance computations.
stimeStatistics initilized at the beginning of the smoothing process.
npNumber of points defining the path.
pointThe points defining the path.
wThe world/cuiksystem on which the sample is defined.

Definition at line 2087 of file samples.c.

References CS_WD_GENERATE_SIMP_INITIAL_BOX, CS_WD_GET_SIMP_JACOBIAN, CS_WD_GET_SIMP_TOPOLOGY, CS_WD_INIT_CD, CT_N_DOF, DEFAULT_CONNECT, DeleteBox(), DeleteJacobian(), DeleteSamples(), FALSE, GetElapsedTime(), GetParameter(), PathLength(), and TRUE.

Referenced by SmoothSamples().

◆ RandomSmooth()

void RandomSmooth ( Tparameters pr,
unsigned int  nCores,
unsigned int  maxIterations,
boolean sv,
Tstatistics stime,
unsigned int *  np,
double ***  point,
TAtlasBase w 
)

Tries to reduce the lenght of a path by ramdomly selecting points on the path and verifying if a direct collision free path between them exists. If so, the new path replaces a segment of the previous path.

IMPORTANT: this is a sub-process of SmoothSamples and it is intended for internal use only and the points are defined in the simplified system and not in the original system as most of the functions on samples.

Parameters
prThe set of parameters.
nCoresNumber of computing cores available.
maxIterationsMaximum number of iterations. To be scaled by the number of steps in the path.
svArray with the components to use distance computations.
stimeStatistics initilized at the beginning of the smoothing process.
npNumber of points defining the path.
pointThe points defining the path.
wThe world/cuiksystem on which the sample is defined.

Definition at line 2195 of file samples.c.

References cmpUInt(), CS_WD_GENERATE_SIMP_INITIAL_BOX, CS_WD_GET_SIMP_JACOBIAN, CS_WD_GET_SIMP_TOPOLOGY, CS_WD_INIT_CD, CT_N_DOF, DEFAULT_CONNECT, DeleteBox(), DeleteJacobian(), DeleteSamples(), FALSE, GetElapsedTime(), GetParameter(), NEW, PathLength(), randomMax(), and TRUE.

Referenced by SmoothSamples().

◆ GradientSmooth()

void GradientSmooth ( Tparameters pr,
unsigned int  nCores,
unsigned int  maxIterations,
boolean sv,
Tstatistics stime,
unsigned int *  np,
double ***  point,
TStepCost  stepCost,
TStepCostGradient  stepCostGradient,
TAtlasBase w 
)

Reduces the length of a path by applying a movement to the points forming the path according the the gradient of the path lenght for w.r.t. the parameters of this points.

IMPORTANT: this is a sub-process of SmoothSamples and it is intended for internal use only and the points are defined in the simplified system and not in the original system as most of the functions on samples.

Parameters
prThe set of parameters.
nCoresNumber of computing cores available. Up to now this is not used.
maxIterationsMaximum number of iterations. To be scaled by the number of steps in the path.
svArray with the components to use distance computations.
stimeStatistics initilized at the beginning of the smoothing process.
npNumber of points defining the path.
pointThe points defining the path.
stepCostFunction giving the cost of moving between two path steps See TStepCost
stepCostGradientFunction giving the gradient of the cost when moving a point in between two other points along the path. See TStepCostGradient If NULL a numerical gradient is used.
wThe world/cuiksystem on which the sample is defined.
Todo:
Implement a parallel version of the GradientSmooth function.

Definition at line 2419 of file samples.c.

References Chart2Manifold(), CopyChart(), CS_WD_GENERATE_SIMP_INITIAL_BOX, CS_WD_GET_SIMP_JACOBIAN, CS_WD_GET_SIMP_TOPOLOGY, CS_WD_IN_COLLISION, CS_WD_INIT_CD, CT_CE, CT_DELTA, CT_E, CT_EPSILON, CT_N_DOF, CT_R, DeleteBox(), DeleteChart(), DeleteJacobian(), DistanceTopology(), Error(), FALSE, GeneralDotProduct(), GET_WORLD, GetElapsedTime(), GetJacobianSize(), GetParameter(), INF, InitTrustedChart(), NEW, NEWZ, PointInBoxTopology(), ScaleVector(), StepCostNumericalGradient(), and TRUE.

Referenced by SmoothSamples().

◆ SaveSamplesInt()

void SaveSamplesInt ( Tfilename fpath,
unsigned int  nvs,
unsigned int  ns,
double **  path,
unsigned int  da,
double **  action,
double *  time 
)

Internal function to save a set of samples to a file. This includes code shared by SaveSamples and SaveSamplesN.

Parameters
fpathName of the file where to store the samples.
nvsThe dimensionality of each sample.
nsThe number of samples defining the path.
pathThe collection of samples defining the path.
daDimension of the action space.
actionAction executed at each time step. Optional. NULL if not given.
timeExecution time for each action. Optional. NULL if not given.

Definition at line 3194 of file samples.c.

References DeleteBox(), Error(), GetFileFullName(), InitBoxFromPoint(), and PrintBox().

Referenced by SaveSamples(), SaveSamplesN(), and SaveTrajectory().

◆ InitSamples()

void InitSamples ( unsigned int *  ms,
unsigned int *  ns,
double ***  path 
)

Initializes the space where to store the samples.

Parameters
msMax number of samples in the set. This will be automatically enlarged in AddSample2Samples if necessary.
nsNumber of samples in the set. 0 after initialization.
pathThe sample set.

Definition at line 672 of file samples.c.

References INIT_NUM_SAMPLES, and NEW.

Referenced by ConnectSamples(), ConnectSamplesChart(), InitSamplesReplay(), InitTrajectory(), MinimizeOnAtlas(), ReconstructAtlasPath(), ReconstructAtlasRRTPath(), Steps2PathinAtlasRRT(), and Steps2PathinRRT().

◆ InitSamplesReplay()

void InitSamplesReplay ( unsigned int *  ms,
unsigned int *  ns,
double ***  path,
boolean **  newChart,
double **  time,
double **  cost 
)

Initializes the space where to store the samples used to reply a simulation (e.g., to re-grow an RRT branch without the computational burden of re-generating the samples, which is particularly expensive in problems with dynamics).

Parameters
msMax number of samples in the set. This will be automatically enlarged in AddSample2Samples if necessary.
nsNumber of samples in the set. 0 after initialization.
pathThe sample set.
newChartTRUE if a chart is generated at the corresponding step. If this is NULL, it is not used.
timeTime lapse from the previous step. If NULL, it is not used.
costCost of the transition. If NULL, it is not used.

Definition at line 679 of file samples.c.

References InitSamples(), and NEW.

Referenced by AddBranchToAtlasRRT().

◆ InitTrajectory()

void InitTrajectory ( unsigned int *  ms,
unsigned int *  ns,
double ***  path,
unsigned int  da,
double ***  actions,
double **  times 
)

Initializes the space where to store the trajectory.

Parameters
msMax number of samples in the set. This will be automatically enlarged in AddSample2Samples if necessary.
nsNumber of samples in the set. 0 after initialization.
pathThe sample set.
daDimesion of the action space (of the action vectors).
actionsThe action executed at each step.
timesThe time for each step.

Definition at line 691 of file samples.c.

References InitSamples(), and NEW.

Referenced by AddBranchToAtlasRRT(), AtlasRRTSimulate(), ConnectDynamicStates(), ConnectDynamicStatesID(), NumericIntegration(), RefineTrajectory(), Simulate(), and Steps2PathinRRT().

◆ AddSample2Samples()

void AddSample2Samples ( unsigned int  nv,
double *  sample,
unsigned int  nvs,
boolean systemVars,
unsigned int *  ms,
unsigned int *  ns,
double ***  path 
)

Adds a sample to a set of samples. The sample is given in full form (including all variables) but we only store the system variables.

Parameters
nvNumber of variables.
sampleThe sample to add.
nvsNumber of system variables.
systemVarsArray to identify the system variables. Use NULL if all variables are to be included in the sample.
msMax number of samples in the set. This will be automatically enlarged in AddSample2Samples if necessary.
nsNumber of samples in the set. 0 after initialization.
pathThe sample set.

Definition at line 699 of file samples.c.

References MEM_DUP, and NEW.

Referenced by ConnectSamples(), ConnectSamplesChart(), MinimizeOnAtlas(), PathInChart(), ReconstructAtlasPath(), ReconstructAtlasRRTPath(), SmoothSamples(), Steps2PathinAtlasRRT(), and Steps2PathinRRT().

◆ AddSample2SamplesReplay()

void AddSample2SamplesReplay ( unsigned int  nv,
double *  sample,
boolean  nc,
double  h,
double  c,
unsigned int  nvs,
boolean systemVars,
unsigned int *  ms,
unsigned int *  ns,
double ***  path,
boolean **  newChart,
double **  time,
double **  cost 
)

Adds a sample to a set of samples used to reply simulations (i.e., to re-simulate a brach without the expensive process to generate the samples). See InitSamplesReplay

Parameters
nvNumber of variables.
sampleThe sample to add.
ncTRUE if a chart is created at the new sample.
hThe time from the previous sample.
cThe cost of the transition.
nvsNumber of system variables.
systemVarsArray to identify the system variables. Use NULL if all variables are to be included in the sample.
msMax number of samples in the set. This will be automatically enlarged in AddSample2Samples if necessary.
nsNumber of samples in the set. 0 after initialization.
pathThe sample set.
newChartTRUE if a chart is created at this step. May be NULL and then it is not used.
timeTime lapse from the previous step. May be NULL and then it is not used.
costCost of the transition. May be NULL and then it is not used.

Definition at line 721 of file samples.c.

References MEM_DUP, MEM_EXPAND, and NEW.

Referenced by AddBranchToAtlasRRT().

◆ AddStep2Trajectory()

void AddStep2Trajectory ( unsigned int  nv,
double *  sample,
unsigned int  nvs,
boolean systemVars,
double *  action,
double  time,
unsigned int *  ms,
unsigned int *  ns,
double ***  path,
unsigned int  da,
double ***  actions,
double **  times 
)

Adds a step to a trajectory.

Parameters
nvNumber of variables.
sampleThe sample to add.
nvsNumber of system variables.
systemVarsArray to identify the system variables. Use NULL if all variables are to be included in the sample.
actionThe executed action. Vector of size da.
timeThe duration of the action.
msMax number of samples in the set. This will be automatically enlarged in AddSample2Samples if necessary.
nsNumber of samples in the set. 0 after initialization.
pathThe sample set.
daThe dimension of the action space. The size of the action vectors
actionsThe action executed at each time step.
timesThe duration of each action.

Definition at line 758 of file samples.c.

References MEM_DUP, MEM_EXPAND, and NEW.

Referenced by AddBranchToAtlasRRT(), AtlasRRTSimulate(), ConnectDynamicStates(), ConnectDynamicStatesID(), NumericIntegration(), RefineTrajectory(), Simulate(), and Steps2PathinRRT().

◆ ConnectDynamicStatesID()

double ConnectDynamicStatesID ( Tparameters pr,
unsigned int *  tp,
Tbox ambient,
boolean  collision,
unsigned int  m,
unsigned int  k,
unsigned int  da,
double *  state,
double *  action,
double  time,
double *  goal,
unsigned int *  ns,
double ***  path,
double ***  actions,
double **  times,
TJacobian J,
TDynamicSpace ds,
TAtlasBase w 
)

Version of ConnectDynamicStates where the action is adjusted at each step using inverse dynamics.

Parameters
prThe set of parameters.
tpThe topology of the variables.
ambientThe ambient space limits.
collisionTRUE if collisions have to be avoided.
mThe size of each sample. IMPORTANT: here samples are suposed to be given in the simplified form and not in the non-simplified one, as it is the case of many of the functions on samples.
kThe dimension of the tangent space.
daThe dimension of the action space.
stateThe state from where to start the simulation.
actionThe action to execute.
timeThe time to execute the action.
goalThe goal to be reached.
nsThe number of stats of the integrated trajectory.
pathThe states in the integrated trajectory.
actionsThe action in the integrated trajectory. This is just a repetition of the input action.
timesThe integration step of each step.
JThe Jacobian of the system of equations.
dsThe dynamics space (memory space used during integration).
wThe world/cuiksystem on which the sample is defined.
Returns
The distance to the goal or INF if the integration fails for any reason (for instance if a collision is detected).

Definition at line 793 of file samples.c.

References AddStep2Trajectory(), ComputeInverseDynamics(), CS_WD_IN_COLLISION, CT_DELTA, DeleteChart(), DistanceTopology(), FALSE, GetParameter(), INF, InitChart(), InitTrajectory(), Local2Global(), Manifold2Chart(), NEWZ, NextDynamicState(), ScaleVector(), START2GOAL, and TRUE.

Referenced by RefineTrajectory().

◆ ConnectDynamicStates()

double ConnectDynamicStates ( Tparameters pr,
unsigned int *  tp,
Tbox ambient,
boolean  collision,
unsigned int  m,
unsigned int  k,
unsigned int  da,
double *  state,
double *  action,
double  time,
double *  goal,
unsigned int *  ns,
double ***  path,
double ***  actions,
double **  times,
TJacobian J,
TDynamicSpace ds,
TAtlasBase w 
)

Integrates the dynamic constraints with the aim of reaching a particular goal This is the dynamic version of ConnectSamples.

Parameters
prThe set of parameters.
tpThe topology of the variables.
ambientThe ambient space limits.
collisionTRUE if collisions have to be avoided.
mThe size of each sample. IMPORTANT: here samples are suposed to be given in the simplified form and not in the non-simplified one, as it is the case of many of the functions on samples.
kThe dimension of the tangent space.
daThe dimension of the action space.
stateThe state from where to start the simulation.
actionThe action to execute.
timeThe time to execute the action.
goalThe goal to be reached.
nsThe number of stats of the integrated trajectory.
pathThe states in the integrated trajectory.
actionsThe action in the integrated trajectory. This is just a repetition of the input action.
timesThe integration step of each step.
JThe Jacobian of the system of equations.
dsThe dynamics space (memory space used during integration).
wThe world/cuiksystem on which the sample is defined.
Returns
The distance to the goal or INF if the integration fails for any reason (for instance if a collision is detected).

Definition at line 887 of file samples.c.

References AddStep2Trajectory(), CS_WD_IN_COLLISION, CT_DELTA, DeleteChart(), DistanceTopology(), FALSE, GetParameter(), INF, InitChart(), InitTrajectory(), NEWZ, NextDynamicState(), START2GOAL, and TRUE.

Referenced by RefineTrajectory().

◆ ConnectSamplesChart()

double ConnectSamplesChart ( Tparameters pr,
unsigned int *  tp,
boolean sv,
Tbox domain,
unsigned int  m,
unsigned int  n,
double *  s1,
double *  s2,
double  md,
boolean  checkCollisions,
TJacobian sJ,
boolean reached,
boolean collision,
double *  lastSample,
unsigned int *  ns,
double ***  path,
TAtlasBase w 
)

Determines if two points on the manifold can be connected with a path of length below a given threshold.

This is the same as ConnectSamples but using a chart-based way to move over the manifold from s1 to s2.

As in the case of ConnectSamples the connection can fail depending on the shape of the manifold. However, for close samples it typically works fine.

This can be seen as a simple version of AddBranchToAtlasRRT. The main difference is that here we do not maintain an atlas: we generate charts as we advance over the manifold but we release them when they are not any longer useful.

IMPORTANT: here samples are suposed to be given in the simplified form and not in the non-simplified one, as it is the case of many of the functions on samples.

Parameters
prThe set of parameters.
tpThe topology for the variables.
svComponents of the configuration to use to compute the length of the connection. If NULL all components are used. Up to now, it is only used for path smoothing purposes.
domainThe domain for the variables.
mThe size of each sample. IMPORTANT: here samples are suposed to be given in the simplified form and not in the non-simplified one, as it is the case of many of the functions on samples.
nThe number of equations in the problem. This is actually not used in this function but we keep this parameter for compatibility with ConnectSamples.
s1The first sample to connect.
s2The second sample to connect.
mdMaximum displacement between the two samples (along the components selected by 'sv').
checkCollisionsTRUE if the path has to be collision free.
sJThe symbolic Jacobian.
reached(output) TRUE if s2 can be reached form s1.
collision(output) TRUE if the connection can not be established due to a collision.
lastSampleBuffer to store the last sample generated along the path from s1 to s2. Set to NULL if this sample is not requiered.
nsNumber of steps of the path connecting the two samples.
pathSamples along the path connecting the two samples. Set ns or path to NULL if you are not interested in the path but only in verifying that the two samples can be connected. Note that the two given samples are NOT included in this output path.
wThe world/cuiksystem on which the sample is defined.
Returns
The maximum distance travelled form s1 to s2. The distance from s1 to the sample stored in 'lastSample', if any.

Definition at line 961 of file samples.c.

References AccumulateVector(), AddSample2Samples(), ArrayPi2Pi(), Chart2Manifold(), CS_WD_IN_COLLISION, CS_WD_SIMP_INEQUALITIES_HOLD, CT_CE, CT_DELTA, CT_E, CT_EPSILON, CT_N_DOF, CT_R, DeleteChart(), DeleteSamples(), DifferenceVector(), DifferenceVectorTopology(), DistanceTopology(), DistanceTopologySubset(), Error(), FALSE, GetJacobianSize(), GetParameter(), InitChart(), InitSamples(), Manifold2Chart(), NEW, Norm(), PointInBoxTopology(), ScaleVector(), SumVectorScale(), and TRUE.

Referenced by WireAtlasRRTstar().

◆ ConnectSamples()

double ConnectSamples ( Tparameters pr,
unsigned int *  tp,
boolean sv,
Tbox domain,
unsigned int  m,
unsigned int  n,
double *  s1,
double *  s2,
double  md,
boolean  checkCollisions,
TJacobian sJ,
boolean reached,
boolean collision,
double *  lastSample,
unsigned int *  ns,
double ***  path,
TAtlasBase w 
)

Determines if two points on the manifold can be connected with a path of length below a given threshold.

The method used to determine the path does not return the sortest path and it can fail in many cases, specially when the samples are far away.

IMPORTANT: here samples are suposed to be given in the simplified form and not in the non-simplified one, as it is the case of many of the functions on samples.

Parameters
prThe set of parameters.
tpThe topology for the variables.
svComponents of the configuration to use to compute the length of the connection. If NULL all components are used. Up to now, it is only used for path smoothing purposes.
domainThe domain for the variables.
mThe size of each sample. IMPORTANT: here samples are suposed to be given in the simplified form and not in the non-simplified one, as it is the case of many of the functions on samples.
nThe number of equations in the problem.
s1The first sample to connect.
s2The second sample to connect.
mdMaximum displacement between the two samples (along the components selected by 'sv').
checkCollisionsTRUE if the path has to be collision free.
sJThe symbolic Jacobian. It is actually not used in this function but the parameter is keep for compatibility with ConnectSamplesChart. You can safely set it to NULL in this case.
reached(output) TRUE if s2 can be reached form s1.
collision(output) TRUE if the connection can not be established due to a collision.
lastSampleBuffer to store the last sample generated along the path from s1 to s2. Set to NULL if this sample is not requiered.
nsNumber of steps of the path connecting the two samples.
pathSamples along the path connecting the two samples. Set ns or path to NULL if you are not interested in the path but only in verifying that the two samples can be connected. Note that the two given samples are NOT included in this output path.
wThe The world/cuiksystem on which the sample is defined.
Returns
The maximum distance travelled form s1 to s2. The distance from s1 to the sample stored in 'lastSample', if any.

Definition at line 1234 of file samples.c.

References AddSample2Samples(), ArrayPi2Pi(), CS_WD_IN_COLLISION, CS_WD_NEWTON_IN_SIMP, CS_WD_SIMP_INEQUALITIES_HOLD, CT_DELTA, CT_EPSILON, DeleteSamples(), DifferenceVectorTopology(), DistanceTopology(), DistanceTopologySubset(), DIVERGED, FALSE, GetParameter(), InitSamples(), NEW, Norm(), PointInBoxTopology(), SumVectorScale(), and TRUE.

Referenced by AddStepToRRTstar(), BiRRTstar(), ReWireRRTstar(), Steps2PathinRRT(), and WireRRTstar().

◆ PathLength()

double PathLength ( unsigned int *  tp,
boolean sv,
unsigned int  m,
unsigned int  np,
double **  point 
)

Computes the length of a path defined by a set of points. IMPORTANT: this is for internal use only and the points are defined in the simplified system and not in the original system as most of the functions on samples.

Parameters
tpThe topology of the variables.
svThe components to use in the distance computation.
mThe size of each point.
npNumber of points in the path.
pointThe set of points.
Returns
The path length.

Definition at line 1364 of file samples.c.

References DistanceTopologySubset().

Referenced by main(), RandomSmooth(), ShortcutSmooth(), and SmoothSamples().

◆ PathEffort()

double PathEffort ( Tparameters p,
unsigned int  m,
unsigned int  np,
double **  point,
Tworld w 
)

Computes the approximated control effort of a path. This only makes sense in problems where there is an associated energy which generates a force field (i.e., the gradient of the energy). The control effort is the effort to compensate this force field and to drive the robot along the path. If no force filed is defined, the control effort gives the path length (see PathLength).

The control effort is defined over the continuous path and we approximate it at discrete times (i.e., an integral approximated as a discrete sum).

Parameters
pThe set of parameters.
mThe size of each point.
npNumber of points in the path.
pointThe set of points.
wThe world structure giving semantic to the path points.
Returns
The (approximated) control effort along the path.

Definition at line 1976 of file samples.c.

References ChangeParameter(), CS_WD_FROM_WORLD, CT_CE, CT_E, CT_N_DOF, CT_R, DeleteBox(), DeleteChart(), DeleteJacobian(), Error(), GetParameter(), GetWorldSimpInitialBox(), GetWorldSimpJacobian(), GetWorldSimpTopology(), InitTrustedChart(), KINEMATIC_SUBSPACE, NEW, RegenerateWorldSolutionPoint(), StepEffort(), TRUE, WorldGenerateSimplifiedPoint(), WorldManifoldDimension(), and WorldSimpKinematicVars().

Referenced by main().

◆ SmoothSamples()

void SmoothSamples ( Tparameters pr,
boolean  parallel,
int  mode,
unsigned int  maxIterations,
unsigned int  ns,
double **  path,
unsigned int *  sns,
double ***  spath,
TAtlasBase w 
)

Produces a path that (locally) minimizes the length and connects the two extremes of the given path.

This implements a basic smoothing structure transforming the input samples (in the original system) to the simplified system and then call a speciallized smoothing procedure.

Only path with more than 2 steps are suitable of optimization. Otherwise this function triggers an error.

Parameters
prThe set of parameters.
parallelTRUE if we have to execute a parallel vesion of smoothing process. Not relevant in SMOOTH_CUT.
modeSmoothing mode to be used: SMOOTH_RANDOM, SMOOTH_GRADIENT, or SMOOTH_CUT.
maxIterationsMaximum number of iterations. To be scaled by the number of steps in the path.
nsThe numer of samples in the input path.
pathThe samples in the input path.
snsThe number of samples in the output (smoothed) path.
spathThe samples in the output (smoothed) path.
wThe The world/cuiksystem on which the sample is defined.

Definition at line 2811 of file samples.c.

References AddSample2Samples(), ChangeParameter(), CS_WD_GENERATE_SIMP_INITIAL_BOX, CS_WD_GENERATE_SIMPLIFIED_POINT, CS_WD_GET_SIMP_TOPOLOGY, CS_WD_GET_SYSTEM_VARS, CS_WD_MANIFOLD_DIMENSION, CS_WD_REGENERATE_ORIGINAL_POINT, CS_WD_REGENERATE_SOLUTION_POINT, CT_DELTA, CT_N_DOF, DeleteBox(), DeleteStatistics(), EffortAndDispersion(), EffortAndDispersionGradient(), Error(), GET_WORLD, GetElapsedTime(), GetParameter(), GradientSmooth(), InitStatistics(), KINEMATIC_SUBSPACE, LengthAndDispersion(), LengthAndDispersionGradient(), NEW, ON_CUIKSYSTEM, PathLength(), RandomSmooth(), ShortcutSmooth(), SMOOTH_DISPERSION, SMOOTH_EFFORT, SMOOTH_GRADIENT, SMOOTH_RANDOM, SMOOTH_SHORTCUT, StepDispersion(), StepDispersionGradient(), StepEffort(), StepEffortGradient(), StepLength(), StepLengthGradient(), and WorldSimpKinematicVars().

Referenced by main().

◆ ConcatSamples()

void ConcatSamples ( unsigned int  nvs,
unsigned int  ns1,
double **  path1,
unsigned int  ns2,
double **  path2,
unsigned int *  ns,
double ***  path 
)

Produces a path that is the concatenation of two paths.

Parameters
nvsThe number of values per sample.
ns1The number of samples defining the first path.
path1The collection of samples defining the first path.
ns2The number of samples defining the second path.
path2The collection of samples defining the second path.
nsThe number of samples defining the output path.
pathThe collection of samples defining the output path.

Definition at line 2981 of file samples.c.

References NEW.

◆ ReverseConcatSamples()

void ReverseConcatSamples ( unsigned int  nvs,
unsigned int  ns1,
double **  path1,
unsigned int  ns2,
double **  path2,
unsigned int *  ns,
double ***  path 
)

Produces a path that is the concatenation of a path and the reverse of a second path. This is basically used to reconstruct paths for bidirectional (Atlas)RRTs.

Parameters
nvsThe number of values per sample.
ns1The number of samples defining the first path.
path1The collection of samples defining the first path.
ns2The number of samples defining the second path.
path2The collection of samples defining the second path.
nsThe number of samples defining the output path.
pathThe collection of samples defining the output path.

Definition at line 3002 of file samples.c.

References NEW.

Referenced by ReverseConcatTrajectories().

◆ ReverseConcatTrajectories()

void ReverseConcatTrajectories ( unsigned int  nvs,
unsigned int  da,
unsigned int  ns1,
double **  path1,
double **  action1,
double *  time1,
unsigned int  ns2,
double **  path2,
double **  action2,
double *  time2,
unsigned int *  ns,
double ***  path,
double ***  action,
double **  time 
)

Version of ReverseConcatSamples but for trajectories.

We assume that the first path is from the START2GOAL tree and that the second path is from the GOAL2START tree. This is critical since the semantic of the actions is different in each tree.

Parameters
nvsThe number of values per sample.
daDimension of the action space.
ns1The number of samples defining the first path.
path1The collection of samples defining the first path.
action1The action executed to reach the corresponding state in path1
time1The time to execute the corresponding action in action1.
ns2The number of samples defining the second path.
path2The collection of samples defining the second path.
action2The action executed to reach the next state in path2. Note the difference with respect to action1. Action1 is the action from the previous state to the current and action2 is the action from the current state to the next.
time2The time to execute the corresponding action in action2.
nsThe number of samples defining the output path.
pathThe collection of samples defining the output path.
actionAction executed to reach each sample.
timeDuration of each action.

Definition at line 3027 of file samples.c.

References Error(), NEW, NEWZ, and ReverseConcatSamples().

Referenced by PathStart2GoalInRRT().

◆ ReverseSamples()

void ReverseSamples ( unsigned int  ns,
double **  path 
)

Reverses a set of samples.

Parameters
nsNumber of samples.
pathThe samples to reverse.

Definition at line 3101 of file samples.c.

Referenced by ReconstructAtlasRRTPath().

◆ ReadOneSample()

unsigned int ReadOneSample ( Tparameters p,
char *  fname,
unsigned int  nvs,
double **  s 
)

Reads one sample from a file.

If the mechanisms representation is DOF-based (see REP_JOINTS) the samples are read from a .dof file. Otherwise they are read from a .samples file.

Parameters
pThe set of parameters.
fnameFile from where to read the sample.
nvsNumber of system variables in the problem = Number of values in the sample.
sWhere to store the sample. The space is allocated internally.
Returns
The dimensionality of the sample. Number of system variables of w.

Definition at line 3121 of file samples.c.

References CreateFileName(), CT_REPRESENTATION, DeleteFileName(), Error(), GetFileFullName(), GetParameter(), JOINTS_EXT, LINKS_EXT, NEW, and REP_JOINTS.

Referenced by main().

◆ ReadTwoSamples()

unsigned int ReadTwoSamples ( Tparameters p,
char *  fname,
unsigned int  nvs,
double **  s1,
double **  s2 
)

Reads two sample from a file.

If the mechanisms representation is DOF-based (see REP_JOINTS) the samples are read from a .dof file. Otherwise they are read from a .samples file.

Parameters
pThe set of parameters.
fnameFile from where to read the sample.
nvsNumber of system variables in the problem = Number of values in the sample.
s1Where to store the first sample. The space is allocated internally.
s2Where to store the second sample. The space is allocated internally.
Returns
The dimensionality of the sample. Number of system variables of w.

Definition at line 3152 of file samples.c.

References CreateFileName(), CT_EPSILON, CT_REPRESENTATION, DeleteFileName(), Distance(), Error(), GetFileFullName(), GetParameter(), JOINTS_EXT, LINKS_EXT, NEW, and REP_JOINTS.

Referenced by main().

◆ SaveSamples()

void SaveSamples ( char *  fname,
char *  suffix,
unsigned int  nvs,
unsigned int  ns,
double **  path 
)

Saves a set of samples (possibly defining a solution path) to a file.

Parameters
fnameThe file where to store the samples.
suffixSuffix to be added to the filename. It is used when generating smoothed paths.
nvsThe dimensionality of each sample.
nsThe number of samples defining the path.
pathThe collection of samples defining the path.

Definition at line 3248 of file samples.c.

References CreateFileName(), DeleteFileName(), SaveSamplesInt(), and SOL_EXT.

Referenced by main(), and MinimizeOnAtlas().

◆ SaveTrajectory()

void SaveTrajectory ( char *  fname,
char *  suffix,
unsigned int  nvs,
unsigned int  ns,
double **  path,
unsigned int  da,
double **  action,
double *  time 
)

Saves a set of samples (possibly defining a solution path) to a file including action and timing information. Thus, the result is a trajectory.

Parameters
fnameThe file where to store the samples.
suffixSuffix to be added to the filename. It is used when generating smoothed paths.
nvsThe dimensionality of each sample.
nsThe number of samples defining the path.
pathThe collection of samples defining the path.
daThe dimension of the action space (of the action vectors).
actionActions executed at each time step.
timeDuration of the execution of each action.

Definition at line 3263 of file samples.c.

References CreateFileName(), DeleteFileName(), SaveSamplesInt(), and SOL_EXT.

Referenced by main().

◆ SaveSamplesN()

void SaveSamplesN ( char *  fname,
boolean  smooth,
unsigned int  n,
unsigned int  nvs,
unsigned int  ns,
double **  path 
)

Saves a set of samples (possibly defining a solution path) to a file. This function is used to save sets of paths.

Parameters
fnameThe file where to store the samples.
smoothTRUE if the set of samples is the result of a smoothing process.
nThe number of this path. Used to define a different name for a sequence of paths to store.
nvsThe dimensionality of each sample.
nsThe number of samples defining the path.
pathThe collection of samples defining the path.

Definition at line 3284 of file samples.c.

References CreateFileName(), DeleteFileName(), SaveSamplesInt(), and SOL_EXT.

Referenced by MinimizeOnAtlas().

◆ LoadSamples()

boolean LoadSamples ( Tfilename fname,
unsigned int *  nvs,
unsigned int *  ns,
double ***  path 
)

Reads a set of samples from a file created using SaveSamples.

Parameters
fnameName of the file containing the samples.
nvsNumber of entries for each sample.
nsNumber of samples (output).
pathThe set of samples (output).
Returns
TRUE if the sample set could be actually read.

Definition at line 3303 of file samples.c.

References Advance(), DeleteListOfBoxes(), EndOfList(), Error(), FALSE, First(), GetBoxCenter(), GetBoxNIntervals(), GetCurrent(), GetFileFullName(), InitIterator(), ListSize(), NEW, ReadListOfBoxes(), and TRUE.

Referenced by main().

◆ LoadTrajectory()

boolean LoadTrajectory ( Tfilename fname,
unsigned int *  nvs,
unsigned int *  ns,
double ***  path,
unsigned int *  da,
double ***  action,
double **  time 
)

Reads a trajectory SaveTrajectory.

Parameters
fnameName of the file containing the samples.
nvsNumber of entries for each sample.
nsNumber of samples (output).
pathThe set of samples (output).
daDimension of the action space (output).
actionThe action applied at each step (output).
timeThe time each action is executed (output).
Returns
TRUE if the sample set could be actually read.

Definition at line 3356 of file samples.c.

References Error(), FALSE, GetFileFullName(), NEW, and TRUE.

Referenced by main().

◆ SparsifyTrajectory()

void SparsifyTrajectory ( double  tm,
unsigned int **  id,
unsigned int *  ns,
double **  path,
double **  action,
double *  time 
)

Ensures a mininum time between two consecutive trajectory steps. This is use before visualizing a trajectory since if the time between frames is too short there are delays in the visualization and it looks unnatural.

Parameters
tmThe minimum time in between steps.
idThe identifiers of the steps that are keep in the sparsified trajectory.
nsNumber of samples.
pathThe set of samples.
actionThe action applied at each step.
timeThe time each action is executed.
Returns
TRUE if the sample set could be actually read.

Definition at line 3435 of file samples.c.

References NEW.

Referenced by main().

◆ PlotSamples()

void PlotSamples ( Tparameters p,
Tplot3d p3d,
unsigned int  xID,
unsigned int  yID,
unsigned int  zID,
unsigned int  ns,
double **  path 
)

Plots a 3D projection of a set of samples representing a path. The path is represented by a green line.

Parameters
pThe set of parametres.
p3dThe 3d plot where to add the plot.
xIDFirst dimension for the projection (in the original system including system vars only).
yIDSecond dimension for the projection (in the original system including system vars only).
zIDThird dimension for the projection (in the original system including system vars only).
nsThe number of samples.
pathThe set of samples.

Definition at line 3472 of file samples.c.

References Close3dObject(), CORRECT_POINT_PLOT, CT_CUT_X, CT_CUT_Y, CT_CUT_Z, DeleteColor(), GetParameter(), M_PI, NEW, NewColor(), PlotSphere(), PlotVect3d(), and StartNew3dObject().

Referenced by main().

◆ PlotForceField()

void PlotForceField ( Tparameters p,
Tplot3d p3d,
unsigned int  xID,
unsigned int  yID,
unsigned int  zID,
Tworld w,
unsigned int  ns,
double **  sols 
)

Plots a 3D projection of the force field on a set of points. The force filed is represented as a short line on each point pointing in the direction of the force field and with length proportional to the force-field magnitude.

Parameters
pThe set of parametres.
p3dThe 3d plot where to add the plot.
xIDFirst dimension for the projection (in the original system including system vars only).
yIDSecond dimension for the projection (in the original system including system vars only).
zIDThird dimension for the projection (in the original system including system vars only).
wThe world from where to compute the force field.
nsThe number of solution points.
solsThe set of solution points.

Definition at line 3583 of file samples.c.

References Close3dObject(), CT_DELTA, CT_EPSILON, DeleteColor(), Error(), FALSE, GetParameter(), GetWorldSystemVars(), INF, NEW, NewColor(), NO_UINT, Norm(), PlotLine(), RegenerateWorldSolutionPoint(), ScaleVector(), StartNew3dObject(), Warning(), and WorldForceField().

Referenced by main().

◆ DeleteSamples()

void DeleteSamples ( unsigned int  ns,
double **  path 
)

Release the memory used by a set of samples.

Parameters
nsThe number of samples.
pathThe set of samples.

Definition at line 3686 of file samples.c.

Referenced by AtlasRRTSimulate(), ConnectSamples(), ConnectSamplesChart(), DeleteRRT(), DeleteSamplesReplay(), DeleteTrajectory(), main(), RandomSmooth(), ReconstructAtlasRRTPath(), ShortcutSmooth(), Steps2PathinAtlasRRT(), and Steps2PathinRRT().

◆ DeleteSamplesReplay()

void DeleteSamplesReplay ( unsigned int  ns,
double **  path,
boolean newChart,
double *  time,
double *  cost 
)

Release the memory used by a set of samples with flags. See InitSamplesReplay.

Parameters
nsThe number of samples.
pathThe set of samples.
newChartTRUE if a chart is created at the corresponding step. Can be NULL.
timeTime lapse from the previous step. Can be NULL.
costCost of the transition. Can be NULL.

Definition at line 3698 of file samples.c.

References DeleteSamples().

Referenced by AddBranchToAtlasDynamicRRT().

◆ DeleteTrajectory()

void DeleteTrajectory ( unsigned int  ns,
double **  path,
double **  action,
double *  time 
)

Release the memory used by a trajectory.

Parameters
nsThe number of samples.
pathThe set of samples.
actionThe action applied at each step.
timeThe time each action is executed.

Definition at line 3710 of file samples.c.

References DeleteSamples().

Referenced by AddBranchToAtlasRRT(), AddNodeToRRT(), ApproachState(), DeleteRRT(), kinobiRRT(), kinoEST(), kinoRRT(), main(), PathStart2GoalInRRT(), and RefineTrajectory().