YANE-Framework 1.1.0
Public Member Functions | Protected Member Functions | Protected Attributes

yane::NetworkedControl::ControllerThreadMPC Class Reference

Class for simulating the controller in a distributed plant - sensor - controller - actuator setting.

Inheritance diagram for yane::NetworkedControl::ControllerThreadMPC:
[legend]
Collaboration diagram for yane::NetworkedControl::ControllerThreadMPC:
[legend]

List of all members.

Public Member Functions

ControlClipboardcontrolClipboard ()
 Function to return the pointer of the control clipboard object of class yane::NetworkedControl::ControlClipboard.
CyclecontrollerCycle ()
 Function to return the pointer of the cycle object of class yane::NetworkedControl::Cycle.
 ControllerThreadMPC (IOInterface *iface, yane::MPC::OdeManager *odemanager, yane::MinProg::NLP *minimizer, int horizon, int prediction, yane::Model::Model *model, yane::MPC::ModelShootingData *shootingdata, yane::Utils::DebugMaster *dm, yane::Utils::StatisticsMaster *sm)
 Constructor.
virtual void detach ()
 Blocks until thread is finished, no return information.
virtual bool isLocked ()
 Returns if thread is locked.
virtual bool isRunning ()
 Returns if thread is running.
virtual void lock ()
 Locks the thread, if already locked blocks.
void setActuatorErrorVariables (int lastnonerrorcycle, int currentcycle)
 Function to set the actuator error variables $ \sigma_{\mbox{err}}, \sigma_{\mbox{cor}} $.
void setNewState (double t, double *state)
 Function to set the internal state vector of the MPC controller.
void setOutputThread (ControllerThreadOutput *thread)
 Function to set the output thread.
virtual void start ()
 Creates the thread.
virtual void stop ()
 Stops the thread.
virtual void trigger ()
 Signal / Trigger the thread.
virtual bool trylock ()
 Locks the thread but returns immediately.
virtual void unlock ()
 Unlock the thread.
virtual void wait ()
 Blocks until thread is finished, possible return information.
virtual ~ControllerThreadMPC ()
 Destructor.

Protected Member Functions

void computePrediction (double *state, int from_seq, int to_seq, double *timesteps)
 Function to predict the state vector using the internally buffered control sequences.
virtual void debugMessage (const std::string &message, int debuglevel)
 Submit a debugmessage.
virtual void debugMessageDouble (const std::string &message, const std::string &varname, int length, double *data, int debuglevel)
 Submit a debugmessage with doublevalued data.
virtual void debugMessageInt (const std::string &message, const std::string &varname, int length, int *data, int debuglevel)
 Submit a debugmessage with integervalued data.
virtual void debugMessageString (const std::string &message, const std::string &varname, const char *data, int debuglevel)
 Submit a debugmessage with textstring data.
void predictInternalState (double *state, int from_seq, int to_seq)
 Function to compute/predict the state vector to the sampling instant used by the MPC controller.
void predictSensorValues (double *peekedx, int to_seq)
 Function to compute/predict the state vector to the next sampling instant.
virtual void run ()
 Function to start the MPC computation thread.
virtual bool waitForTrigger (unsigned int wait_msec=0, int debuglevel=0)
 Block until triggered.

Protected Attributes

bool _abort
ControlClipboard_cb
 Pointer of the used control clipboard of class yane::NetworkedControl::ControlClipboard.
Cycle_controllercycle
 Pointer of the used cycle object of class yane::NetworkedControl::Cycle.
DebugClient * _debugclient
bool _error_received
 Decision variable whether an error has been received.
int _horizon
 Length of the optimization horizon.
double * _inputx
 Pointer of the internal state vector.
bool _inputxchanged
 Decision variable whether the internal state vector has been updated.
double _inputxtime
 Time of the last sensor measurement.
IOInterface_interface
 Pointer of the used network interface of class yane::NetworkedControl::IOInterface.
int _last_seq
 Sampling instant of the latest MPC calculation.
yane::MinProg::NLP_minimizer
 Pointer of the used minimizer of class yane::MinProgl::NLP.
yane::Model::Model_model
 Pointer of the used model of class yane::Model::Model.
yane::MPC::MPC_mpc
 Pointer of the used controller of class yane::MPC::MPC.
yane::Utils::Semaphore_mpcstartsem
 Pointer of the used semaphore of class yane::Utils::Semaphore.
yane::MPC::OdeManager_odemanager
 Pointer of the used odemanager of class yane::MPC::OdeManager.
ControllerThreadOutput_outputthread
 Pointer of the used output thread of class yane::NetworkedControl::ControllerThreadOutput.
int _prediction
 Length of the ahead prediction.
double _samplingTime
 Sampling time.
int _seq
 Current sampling instant used for the MPC calculation.
yane::MPC::ModelShootingData_shootingdata
 Pointer of the used shooting data of class yane::MPC::ModelShootingData.
int _sigma_cor
 Value of $ \sigma_{\mbox{cor}} $, the sampling instant of the last correct control sequence.
int _sigma_err
 Value of $ \sigma_{\mbox{err}} $, the sampling instant of the latest error within the scheme.
yane::Model::Simulator_simulator
 Pointer of the used simulator of class yane::Model::Simulator.
yane::Utils::StatisticsClientAverage_stat_calcduration
 Statistics collector for average computing time.
bool _stat_collect
 Decision variable whether staticstical data shall be collected.
yane::Utils::StatisticsClientIntCounter_stat_computedseq
 Statistics collector for computed control sequences.
yane::Utils::StatisticsClientIntCounter_stat_discardseq_locked
 Statistics collector for discarded sequences due to lock.
yane::Utils::StatisticsClientIntCounter_stat_discardseq_timeout
 Statistics collector for discarded sequences due to timeout.
yane::Utils::StatisticsClientIntCounter_stat_inputfuture
 Statistics collector for received future input sequences.
yane::Utils::StatisticsClientIntCounter_stat_invalidateseq
 Statistics collector for invalidated control sequences.
yane::Utils::StatisticsClientIntCounter_stat_skipseq
 Statistics collector for skipped computations.
double * _t
 Pointer of the time grid.
double * _u
 Pointer of the control sequence.
double * _x
 Pointer of the state vector.

Constructor & Destructor Documentation

yane::NetworkedControl::ControllerThreadMPC::ControllerThreadMPC ( IOInterface iface,
yane::MPC::OdeManager odemanager,
yane::MinProg::NLP minimizer,
int  horizon,
int  prediction,
yane::Model::Model model,
yane::MPC::ModelShootingData shootingdata,
yane::Utils::DebugMaster dm,
yane::Utils::StatisticsMaster sm 
)

Constructor

Parameters:
ifacePointer of the input/output interface of class yane::MPC::IOInterface
odemanagerPointer of the differential equation manager of class yane::MPC::OdeManager
minimizerPointer of the minimization routine of class yane::MinProg::NLP
horizonLength of the horizon
predictionNumber of preceding prediction steps
modelPointer of the class yane::Model::Model object used for optimization
shootingdataPointer of the yane::Model::ModelShootingData object used for optimization
dmPointer of the debugmanager of class yane::Utils::DebugMaster
smPointer of the statistics manager of class yane::Utils::StatisticsMaster

Member Function Documentation

void yane::NetworkedControl::ControllerThreadMPC::computePrediction ( double *  state,
int  from_seq,
int  to_seq,
double *  timesteps 
) [protected]

Function to predict the state vector using the internally buffered control sequences

Parameters:
stateState vector
from_seqInitial sampling instant
to_seqTerminal sampling instant
timestepsTime grid
LIB_EXPORT void yane::Utils::Thread::debugMessage ( const std::string &  message,
int  debuglevel 
) [protected, virtual, inherited]

Added for convenient handling

Parameters:
messageMessage which is debugged
debuglevelLevel with which the message is debugged.
LIB_EXPORT void yane::Utils::Thread::debugMessageDouble ( const std::string &  message,
const std::string &  varname,
int  length,
double *  data,
int  debuglevel 
) [protected, virtual, inherited]

Added for convenient handling

Parameters:
messageMessage which is debugged
varnameData name
lengthLength of data array
dataData which is added.
debuglevelLevel with which the message is debugged.
LIB_EXPORT void yane::Utils::Thread::debugMessageInt ( const std::string &  message,
const std::string &  varname,
int  length,
int *  data,
int  debuglevel 
) [protected, virtual, inherited]

Added for convenient handling

Parameters:
messageMessage which is debugged
varnameData name
lengthLength of data array
dataData which is added.
debuglevelLevel with which the message is debugged.
LIB_EXPORT void yane::Utils::Thread::debugMessageString ( const std::string &  message,
const std::string &  varname,
const char *  data,
int  debuglevel 
) [protected, virtual, inherited]

Added for convenient handling

Parameters:
messageMessage which is debugged
varnameData name
dataPointer to an additional nullterminated character array, that has to be stored as data
debuglevelLevel with which the message is debugged.
LIB_EXPORT void yane::Utils::Thread::detach ( ) [virtual, inherited]

The calling thread is blocked until the thread is finished, no return information

LIB_EXPORT bool yane::Utils::Thread::isLocked ( ) [virtual, inherited]

Returns wether the thread is locked or not.

Returns:
true if thread is locked.
LIB_EXPORT bool yane::Utils::Thread::isRunning ( ) [virtual, inherited]

Returns wether the thread is running (_abort = false) or not.

Returns:
true if thread is running.
LIB_EXPORT void yane::Utils::Thread::lock ( ) [virtual, inherited]

Locks the thread. If already locked the calling thread is blocked until the thread is unlocked.

void yane::NetworkedControl::ControllerThreadMPC::predictInternalState ( double *  state,
int  from_seq,
int  to_seq 
) [protected]

Function to compute/predict the state vector to the sampling instant used by the MPC controller

Parameters:
peededxComputed initial value
from_seqInitial sampling instant
to_seqSampling instant the initial value is computed for
void yane::NetworkedControl::ControllerThreadMPC::predictSensorValues ( double *  peekedx,
int  to_seq 
) [protected]

Function to compute/predict the state vector measured by sensors to the next sampling instant

Parameters:
peededxComputed initial value
to_seqSampling instant the initial value is computed for
void yane::NetworkedControl::ControllerThreadMPC::setActuatorErrorVariables ( int  lastnonerrorcycle,
int  currentcycle 
)

Function to set the actuator error variables $ \sigma_{\mbox{err}}, \sigma_{\mbox{cor}} $ upon receiving an actuator error

Parameters:
lastnoerrorcycleValue of $ \sigma_{\mbox{cor}} $
currentcycleValue of $ \sigma_{\mbox{err}} $
void yane::NetworkedControl::ControllerThreadMPC::setNewState ( double  t,
double *  state 
)

Function to set the internal state vector of the MPC controller

Parameters:
tTime instant of the state vector to be set
stateState vector
void yane::NetworkedControl::ControllerThreadMPC::setOutputThread ( ControllerThreadOutput thread)

Function to set the output thread

Parameters:
threadOutput thread
LIB_EXPORT void yane::Utils::Thread::start ( ) [virtual, inherited]

This function creates the thread and should be called after creating the object.

LIB_EXPORT void yane::Utils::Thread::stop ( ) [virtual, inherited]

This function sets _abort to false, your thread should stop now.

LIB_EXPORT void yane::Utils::Thread::trigger ( ) [virtual, inherited]

Signal a thread to resume, if it's blocked due to a call to waitForTrigger()

See also:
waitForTrigger()
LIB_EXPORT bool yane::Utils::Thread::trylock ( ) [virtual, inherited]

Locks the thread. If already locked returns immediately.

Returns:
true if successful
LIB_EXPORT void yane::Utils::Thread::unlock ( ) [virtual, inherited]

Unlocks the thread.

LIB_EXPORT void yane::Utils::Thread::wait ( ) [virtual, inherited]

The calling thread is blocked until the thread is finished, possible return information

LIB_EXPORT bool yane::Utils::Thread::waitForTrigger ( unsigned int  wait_msec = 0,
int  debuglevel = 0 
) [protected, virtual, inherited]

The calling function (usually the thread) is blocked until the function is triggered.

Parameters:
wait_msecTime until waiting is aborted.
debuglevelDebuglevel with which the abort message is stored.
Returns:
true if successful

Member Data Documentation

bool yane::Utils::Thread::_abort [protected, inherited]

If true thread should be stopped. Value is changed by stop().

DebugClient* yane::Utils::Thread::_debugclient [protected, inherited]

Debugclient the debug messages are stored into.