Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
tuw::State Class Referenceabstract

Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like) value access. More...

#include <state.h>

Inheritance diagram for tuw::State:
Inheritance graph
[legend]

Public Member Functions

virtual StateSPtr cloneState () const =0
 Clone-to-base-class-ptr function. More...
 
void fromEIGENVec (const Eigen::VectorXd &_vec)
 Copies all values from an Eigen vector. The valueSize of the State object has to be equal with the Eigen vector size. More...
 
void fromSTLVec (const std::vector< double > &_vec)
 Copies all values from an STL vector. The valueSize of the State object has to be equal with the STL vector size. More...
 
Stateoperator= (const State &)=default
 
Stateoperator= (State &&)=default
 
virtual void resize (const size_t &_i)
 Resizes the array. More...
 
 State (State *_parent)
 
 State ()
 
 State (const State &)=default
 
 State (State &&)=default
 
virtual StateSPtrstate (const std::size_t &_i)
 Access sub-state based on index _i. More...
 
virtual size_t stateSize () const
 Size of the sub-states. More...
 
void toEIGENVec (Eigen::VectorXd &_vec)
 Converts all the array values to an Eigen vector. More...
 
void toSTLVec (std::vector< double > &_vec)
 Converts all the array values to an STL vector. More...
 
virtual void updateSize ()
 Performs internal manipulation when any of the underlying arrays are being resized. More...
 
virtual double & value (const std::size_t &_i)=0
 Access state variable based on index _i. More...
 
virtual const double & value (const std::size_t &_i) const =0
 Const access state variable based on index _i. More...
 
virtual size_t valueSize () const =0
 Size of the state variables. More...
 
virtual ~State ()=default
 

Static Public Member Functions

static std::vector< double > & minus (State &_lhs, State &_rhs, std::vector< double > &_ans)
 Performs substraction. Left and right operand are required to have the same valueSize. More...
 
static Eigen::VectorXd & minus (State &_lhs, State &_rhs, Eigen::VectorXd &_ans)
 Performs substraction. Left and right operand are required to have the same valueSize. More...
 
static Stateminus (State &_lhs, State &_rhs, State &_ans)
 Performs substraction. Answer variable, left operand and right operand are required to have the same valueSize. More...
 
static std::vector< double > & plus (State &_lhs, State &_rhs, std::vector< double > &_ans)
 Performs addition. Left and right operand are required to have the same valueSize. More...
 
static Eigen::VectorXd & plus (State &_lhs, State &_rhs, Eigen::VectorXd &_ans)
 Performs addition. Left and right operand are required to have the same valueSize. More...
 
static Stateplus (State &_lhs, State &_rhs, State &_ans)
 Performs addition. Answer variable, left operand and right operand are required to have the same valueSize. More...
 

Protected Member Functions

void callRootUpdateSize ()
 Calls (if present) the parent updateSize procedure. Otherwise performs root updateSize. More...
 

Protected Attributes

Stateparent_
 Pointer to the parent State structure. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const State &o)
 prints the state value to an output stream. More...
 

Detailed Description

Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like) value access.

#include <iostream>
using namespace tuw;
struct I2WS_Wheel_State {
double steering;
double revolute;
void fromState ( const StateSPtr state ) {
steering = state->value ( 0 );
revolute = state->value ( 1 );
}
friend std::ostream &operator << ( std::ostream &os, const I2WS_Wheel_State &o ) {
os << "[" << o.steering << ", " << o.revolute << "]";
return os;
};
};
struct I2WS_Wheels_State {
I2WS_Wheel_State left;
I2WS_Wheel_State right;
void fromState ( const StateSPtr state ) {
#ifdef true
left. fromState ( state->state ( 0 ) );
right.fromState ( state->state ( 1 ) );
#else
left. steering = state->value ( 0 );
left. revolute = state->value ( 1 );
right.steering = state->value ( 2 );
right.revolute = state->value ( 3 );
#endif
}
friend std::ostream &operator << ( std::ostream &os, const I2WS_Wheels_State &o ) {
os << "[" << o.left << ", " << o.right << "]";
return os;
};
};
enum class StateWheel { Steer, Revol, ENUM_SIZE };
using StateWhInpPtrType = std::shared_ptr<StateWhInpType>;
int main ( int argc, char **argv ) {
std::cout << "iws utils test" << std::endl;
StateWhInpPtrType tuw_i2ws_wheel_state = std::shared_ptr<StateWhInpType>(new StateWhInpType);
tuw_i2ws_wheel_state->resize ( 2 );
tuw_i2ws_wheel_state->value(0) = 10;
tuw_i2ws_wheel_state->value(1) = 11;
tuw_i2ws_wheel_state->value(2) = 12;
tuw_i2ws_wheel_state->value(3) = 13;
std::cout << "tuw : " << *tuw_i2ws_wheel_state << std::endl;
std::vector<double> values;
tuw_i2ws_wheel_state->toSTLVec ( values );
I2WS_Wheels_State classical_state;
classical_state.fromState(tuw_i2ws_wheel_state);
std::cout << "classical: " << classical_state << std::endl;
std::cout << "tuw : [" << *tuw_i2ws_wheel_state->state(0) << ", " << *tuw_i2ws_wheel_state->state(1) << "]" <<
std::endl;
std::cout << "tuw : " << tuw_i2ws_wheel_state->stateScoped(1)->value<StateWheel::Steer>() << std::endl;
}

Definition at line 135 of file state.h.

Constructor & Destructor Documentation

tuw::State::State ( State _parent)
inline

Definition at line 139 of file state.h.

tuw::State::State ( )
inline

Definition at line 145 of file state.h.

virtual tuw::State::~State ( )
virtualdefault
tuw::State::State ( const State )
default
tuw::State::State ( State &&  )
default

Member Function Documentation

void tuw::State::callRootUpdateSize ( )
inlineprotected

Calls (if present) the parent updateSize procedure. Otherwise performs root updateSize.

Definition at line 380 of file state.h.

virtual StateSPtr tuw::State::cloneState ( ) const
pure virtual
void tuw::State::fromEIGENVec ( const Eigen::VectorXd &  _vec)
inline

Copies all values from an Eigen vector. The valueSize of the State object has to be equal with the Eigen vector size.

Definition at line 240 of file state.h.

void tuw::State::fromSTLVec ( const std::vector< double > &  _vec)
inline

Copies all values from an STL vector. The valueSize of the State object has to be equal with the STL vector size.

Definition at line 226 of file state.h.

static std::vector<double>& tuw::State::minus ( State _lhs,
State _rhs,
std::vector< double > &  _ans 
)
inlinestatic

Performs substraction. Left and right operand are required to have the same valueSize.

Parameters
_lhsLeft operand
_rhsRight operand
_ansComputation result
Returns
Computation result

Definition at line 314 of file state.h.

static Eigen::VectorXd& tuw::State::minus ( State _lhs,
State _rhs,
Eigen::VectorXd &  _ans 
)
inlinestatic

Performs substraction. Left and right operand are required to have the same valueSize.

Parameters
_lhsLeft operand
_rhsRight operand
_ansComputation result
Returns
Computation result

Definition at line 333 of file state.h.

static State& tuw::State::minus ( State _lhs,
State _rhs,
State _ans 
)
inlinestatic

Performs substraction. Answer variable, left operand and right operand are required to have the same valueSize.

Parameters
_lhsLeft operand
_rhsRight operand
_ansComputation result
Returns
Computation result

Definition at line 353 of file state.h.

State& tuw::State::operator= ( const State )
default
State& tuw::State::operator= ( State &&  )
default
static std::vector<double>& tuw::State::plus ( State _lhs,
State _rhs,
std::vector< double > &  _ans 
)
inlinestatic

Performs addition. Left and right operand are required to have the same valueSize.

Parameters
_lhsLeft operand
_rhsRight operand
_ansComputation result
Returns
Computation result

Definition at line 257 of file state.h.

static Eigen::VectorXd& tuw::State::plus ( State _lhs,
State _rhs,
Eigen::VectorXd &  _ans 
)
inlinestatic

Performs addition. Left and right operand are required to have the same valueSize.

Parameters
_lhsLeft operand
_rhsRight operand
_ansComputation result
Returns
Computation result

Definition at line 276 of file state.h.

static State& tuw::State::plus ( State _lhs,
State _rhs,
State _ans 
)
inlinestatic

Performs addition. Answer variable, left operand and right operand are required to have the same valueSize.

Parameters
_lhsLeft operand
_rhsRight operand
_ansComputation result
Returns
Computation result

Definition at line 296 of file state.h.

virtual void tuw::State::resize ( const size_t &  _i)
inlinevirtual

Resizes the array.

Reimplemented in tuw::StateNestedVector< SubState >, and tuw::StateNestedVector< OneWheelType >.

Definition at line 186 of file state.h.

virtual StateSPtr& tuw::State::state ( const std::size_t &  _i)
inlinevirtual
virtual size_t tuw::State::stateSize ( ) const
inlinevirtual
void tuw::State::toEIGENVec ( Eigen::VectorXd &  _vec)
inline

Converts all the array values to an Eigen vector.

Definition at line 215 of file state.h.

void tuw::State::toSTLVec ( std::vector< double > &  _vec)
inline

Converts all the array values to an STL vector.

Definition at line 205 of file state.h.

virtual void tuw::State::updateSize ( )
inlinevirtual
virtual double& tuw::State::value ( const std::size_t &  _i)
pure virtual
virtual const double& tuw::State::value ( const std::size_t &  _i) const
pure virtual
virtual size_t tuw::State::valueSize ( ) const
pure virtual

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const State o 
)
friend

prints the state value to an output stream.

Parameters
os
o
Returns
stream

Definition at line 370 of file state.h.

Member Data Documentation

State* tuw::State::parent_
protected

Pointer to the parent State structure.

Definition at line 392 of file state.h.


The documentation for this class was generated from the following file:


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:23