chrono::ChFunction_Sequence Class Reference

Description

Sequence function: y = sequence_of_functions(f1(y), f2(y), f3(y)) All other function types can be inserted into this.

This function is very important because very complex motion laws can be created by sequencing many basic ChFunctions.

#include <ChFunction_Sequence.h>

Inheritance diagram for chrono::ChFunction_Sequence:
Collaboration diagram for chrono::ChFunction_Sequence:

Public Member Functions

 ChFunction_Sequence (const ChFunction_Sequence &other)
 
virtual ChFunction_SequenceClone () const override
 "Virtual" copy constructor (covariant return type).
 
virtual FunctionType Get_Type () const override
 Return the unique function type identifier.
 
virtual double Get_y (double x) const override
 Return the y value of the function, at position x.
 
virtual double Get_y_dx (double x) const override
 Return the dy/dx derivative of the function, at position x. More...
 
virtual double Get_y_dxdx (double x) const override
 Return the ddy/dxdx double derivative of the function, at position x. More...
 
void Set_start (double m_start)
 The sequence of functions starts at this x value.
 
double Get_start () const
 
std::list< ChFseqNode > & Get_list ()
 Access the list of the sub-functions.
 
void Setup ()
 Scans all the seq.of functions and setup the timings and continuity offsets, to satisfy all constraints. More...
 
bool InsertFunct (std::shared_ptr< ChFunction > myfx, double duration, double weight=1, bool c0=false, bool c1=false, bool c2=false, int position=-1)
 Insert function after the fx with defined "position" index in list. More...
 
bool KillFunct (int position)
 Remove and deletes function with defined "position", and returns true. More...
 
std::shared_ptr< ChFunctionGetNthFunction (int position)
 Returns the ChFunction with given "position". More...
 
ChFseqNodeGetNthNode (int position)
 As above, but returns the function node (containing function pointer, function duration, continuity flags with previous node, etc.)
 
double GetNthDuration (int position)
 As above, but returning duration. More...
 
virtual double Get_weight (double x) const override
 Return the weight of the function (useful for applications where you need to mix different weighted ChFunctions)
 
virtual void Estimate_x_range (double &xmin, double &xmax) const override
 Return an estimate of the range of the function argument. More...
 
virtual int HandleNumber () const override
 Return the number of handles of the function.
 
virtual bool HandleAccess (int handle_id, double mx, double my, bool set_mode) override
 Get the x and y position of handle, given identifier. More...
 
virtual void ArchiveOUT (ChArchiveOut &marchive) override
 Method to allow serialization of transient data to archives.
 
virtual void ArchiveIN (ChArchiveIn &marchive) override
 Method to allow deserialization of transient data from archives.
 
- Public Member Functions inherited from chrono::ChFunction
 ChFunction (const ChFunction &other)
 
virtual void Estimate_y_range (double xmin, double xmax, double &ymin, double &ymax, int derivate) const
 Return an estimate of the range of the function value. More...
 
virtual double Get_y_dN (double x, int derivate) const
 Return the function derivative of specified order at the given point. More...
 
virtual double Compute_max (double xmin, double xmax, double sampling_step, int derivate) const
 Compute the maximum of y(x) in a range xmin-xmax, using a sampling method.
 
virtual double Compute_min (double xmin, double xmax, double sampling_step, int derivate) const
 Compute the minimum of y(x) in a range xmin-xmax, using a sampling method.
 
virtual double Compute_mean (double xmin, double xmax, double sampling_step, int derivate) const
 Compute the mean value of y(x) in a range xmin-xmax, using a sampling method.
 
virtual double Compute_sqrmean (double xmin, double xmax, double sampling_step, int derivate) const
 Compute the square mean val. of y(x) in a range xmin-xmax, using sampling.
 
virtual double Compute_int (double xmin, double xmax, double sampling_step, int derivate) const
 Compute the integral of y(x) in a range xmin-xmax, using a sampling method.
 
virtual double Get_Ca_pos () const
 Computes the positive acceleration coefficient (inherited classes should customize this).
 
virtual double Get_Ca_neg () const
 Compute the positive acceleration coefficient (inherited classes should customize this).
 
virtual double Get_Cv () const
 Compute the speed coefficient (inherited classes must customize this).
 
virtual int FilePostscriptPlot (ChFile_ps *m_file, int plotY, int plotDY, int plotDDY)
 Plot function in graph space of the ChFile_ps postscript file where zoom factor, centering, colour, thickness etc. More...
 
virtual int FileAsciiPairsSave (ChStreamOutAscii &m_file, double xmin=0, double xmax=1, int msamples=200)
 Save function as X-Y pairs separated by space, with CR at each pair, into an ASCII file. More...
 

Additional Inherited Members

- Public Types inherited from chrono::ChFunction
enum  FunctionType {
  FUNCT_CUSTOM, FUNCT_CONST, FUNCT_CONSTACC, FUNCT_DERIVE,
  FUNCT_FILLET3, FUNCT_INTEGRATE, FUNCT_MATLAB, FUNCT_MIRROR,
  FUNCT_MOCAP, FUNCT_NOISE, FUNCT_OPERATION, FUNCT_OSCILLOSCOPE,
  FUNCT_POLY, FUNCT_POLY345, FUNCT_RAMP, FUNCT_RECORDER,
  FUNCT_REPEAT, FUNCT_SEQUENCE, FUNCT_SIGMA, FUNCT_SINE,
  FUNCT_LAMBDA
}
 Enumeration of function types.
 

Member Function Documentation

void chrono::ChFunction_Sequence::Estimate_x_range ( double &  xmin,
double &  xmax 
) const
overridevirtual

Return an estimate of the range of the function argument.

(Can be used for automatic zooming in a GUI)

Reimplemented from chrono::ChFunction.

double chrono::ChFunction_Sequence::Get_y_dx ( double  x) const
overridevirtual

Return the dy/dx derivative of the function, at position x.

Note that inherited classes may also avoid overriding this method, because this base method already provide a general-purpose numerical differentiation to get dy/dx only from the Get_y() function. (however, if the analytical derivative is known, it may better to implement a custom method).

Reimplemented from chrono::ChFunction.

double chrono::ChFunction_Sequence::Get_y_dxdx ( double  x) const
overridevirtual

Return the ddy/dxdx double derivative of the function, at position x.

Note that inherited classes may also avoid overriding this method, because this base method already provide a general-purpose numerical differentiation to get ddy/dxdx only from the Get_y() function. (however, if the analytical derivative is known, it may be better to implement a custom method).

Reimplemented from chrono::ChFunction.

double chrono::ChFunction_Sequence::GetNthDuration ( int  position)

As above, but returning duration.

(return value is reference, so it can be also changed later, but remember Setup() for the ChFunction_Sequence after you modified this return value by reference ***TO DO***). If no function, returns 0.

std::shared_ptr< ChFunction > chrono::ChFunction_Sequence::GetNthFunction ( int  position)

Returns the ChFunction with given "position".

  • If position = 0, returns always head (beginning),
  • If position = -1 returns tail (end).
  • If position > max number of current nodes, returns tail fx anyway.
bool chrono::ChFunction_Sequence::HandleAccess ( int  handle_id,
double  mx,
double  my,
bool  set_mode 
)
overridevirtual

Get the x and y position of handle, given identifier.

If set mode, x and y values are stored. Return false if handle not found.

Reimplemented from chrono::ChFunction.

bool chrono::ChFunction_Sequence::InsertFunct ( std::shared_ptr< ChFunction myfx,
double  duration,
double  weight = 1,
bool  c0 = false,
bool  c1 = false,
bool  c2 = false,
int  position = -1 
)

Insert function after the fx with defined "position" index in list.

  • If index is higher than available objects, it simply goes to the end.
  • If index = 0 insert at the beginning,
  • If index = -1 insert at the end. Inserted functions will be deleted automatically when this object will be deleted. The fx segment has its own 'weight': use 1.0 for default, or different weights if you want that Get_weight() will give different results depending on the "x" parameter. Set c0=true if you want to force C0 continuity with previous function (an offset will be implicitly added to the function, as y=f(x)+Offset). Same for C1 and C2 continuity, using c1 and c2 flags. position index, 0,1,2,3.. (if -1 insert at the end)
Parameters
myfxthe function to insert
durationduration of the time segment for this function
weightoptional weight scalar
c2impose continuity to previous f() by offsetting/slanting
bool chrono::ChFunction_Sequence::KillFunct ( int  position)

Remove and deletes function with defined "position", and returns true.

  • If position = 0, removes always head (beginning),
  • If position = -1 removes tail (end).
  • If position > max number of current nodes, removes tail anyway, but returns false.
void chrono::ChFunction_Sequence::Setup ( )

Scans all the seq.of functions and setup the timings and continuity offsets, to satisfy all constraints.

This must be called whenever a new function is inserted, or its timing and continuity constraints are changed.