DUNE: Uniform Navigational Environment  2.4.1
Plan::Engine::Task Struct Reference

Public Member Functions

 Task (const std::string &name, Tasks::Context &ctx)
 
 ~Task ()
 
void onUpdateParameters (void)
 
void onResourceRelease (void)
 
void onResourceAcquisition (void)
 
void onResourceInitialization (void)
 
void consume (const IMC::EstimatedState *msg)
 
void consume (const IMC::ManeuverControlState *msg)
 
void consume (const IMC::PowerOperation *po)
 
void consume (const IMC::RegisterManeuver *msg)
 
void consume (const IMC::EntityInfo *msg)
 
void consume (const IMC::PlanDB *pdb)
 
void consume (const IMC::EntityActivationState *msg)
 
void openDB (void)
 
void closeDB (void)
 
void consume (const IMC::VehicleCommand *vc)
 
void consume (const IMC::VehicleState *vs)
 
void onVehicleService (const IMC::VehicleState *vs)
 
void onVehicleManeuver (const IMC::VehicleState *vs)
 
void onVehicleError (const IMC::VehicleState *vs)
 
void onVehicleCalibration (const IMC::VehicleState *vs)
 
void onVehicleExternalControl (const IMC::VehicleState *vs)
 
void consume (const IMC::PlanControl *pc)
 
bool loadPlan (const std::string &plan_id, const IMC::Message *arg, bool plan_startup=false)
 
void getPlan (void)
 
bool stopPlan (bool plan_startup=false)
 
bool parsePlan (bool plan_startup)
 
bool lookForPlan (const std::string &plan_id, IMC::PlanSpecification &ps)
 
bool startPlan (const std::string &plan_id, const IMC::Message *spec, uint16_t flags)
 
bool startCalibration (void)
 
void startManeuver (IMC::PlanManeuver *pman)
 
void answer (uint8_t type, const std::string &desc, bool print=true)
 
void onFailure (const std::string &errmsg, bool print=true)
 
void onSuccess (const std::string &msg=DTR("OK"), bool print=true)
 
void changeMode (IMC::PlanControlState::StateEnum s, const std::string &event_desc, const std::string &nid, const IMC::Message *maneuver, bool print=true)
 
void changeMode (IMC::PlanControlState::StateEnum s, const std::string &event_desc, bool print=true)
 
void setInitialState (void)
 
void reportProgress (void)
 
void onMain (void)
 
void vehicleRequest (IMC::VehicleCommand::CommandEnum command, const IMC::Message *arg=0)
 
bool pendingReply (void)
 
bool blockedMode (void) const
 
bool readyMode (void) const
 
bool initMode (void) const
 
bool execMode (void) const
 
void changeLog (const std::string &name)
 
- Public Member Functions inherited from DUNE::Tasks::Task
 Task (const std::string &name, Context &context)
 
const char * getName (void) const
 
const char * getSystemName (void) const
 
unsigned int getSystemId (void) const
 
unsigned int getEntityId (void) const
 
uint16_t getActivationTime (void) const
 
uint16_t getDeactivationTime (void) const
 
unsigned int resolveSystemName (const std::string &name) const
 
const char * resolveSystemId (unsigned int id) const
 
void loadConfig (void)
 
void setPriority (unsigned int value)
 
unsigned int getPriority (void) const
 
void inf (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void war (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void void err (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void void void cri (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void void void void debug (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void void void void void trace (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void void void void void void spew (const char *format,...) DUNE_PRINTF_FORMAT(2
 
void void void void void void
void void 
dispatch (IMC::Message *msg, unsigned int flags=0)
 
void dispatch (IMC::Message &msg, unsigned int flags=0)
 
void dispatchReply (const IMC::Message &original, IMC::Message &msg, unsigned int flags=0)
 
void receive (const IMC::Message *msg)
 
void reserveEntities (void)
 
void resolveEntities (void)
 
void acquireResources (void)
 
void releaseResources (void)
 
void initializeResources (void)
 
void updateParameters (bool act_deact=true)
 
void writeParamsXML (std::ostream &os) const
 
- Public Member Functions inherited from DUNE::Tasks::AbstractTask
 AbstractTask (void)
 
virtual ~AbstractTask (void)
 
- Public Member Functions inherited from DUNE::Concurrency::Thread
 Thread (void)
 
virtual ~Thread (void)
 
int getProcessorUsage (void)
 
- Public Member Functions inherited from DUNE::Concurrency::Runnable
 Runnable (void)
 
virtual ~Runnable (void)
 
void start (void)
 
void stop (void)
 
void join (void)
 
void stopAndJoin (void)
 
void setPriority (Scheduler::Policy policy, unsigned priority)
 
State getState (void)
 
bool isCreated (void)
 
bool isStopping (void)
 
bool isRunning (void)
 
bool isStarting (void)
 
bool isDead (void)
 

Public Attributes

Planm_plan
 
Calibrationm_calib
 
bool m_stopped_calib
 
bool m_wait_min
 
IMC::PlanControlState m_pcs
 
IMC::PlanControl m_reply
 
std::string m_last_event
 
uint16_t m_vreq_ctr
 
double m_vc_reply_deadline
 
double m_last_vstate
 
IMC::VehicleCommand m_vc
 
IMC::PlanSpecification m_spec
 
std::set< uint16_t > m_supported_maneuvers
 
Database::Connection * m_db
 
Database::Statement * m_get_plan_stmt
 
IMC::LoggingControl m_lc
 
IMC::EstimatedState m_state
 
IMC::ManeuverControlState m_mcs
 
Time::Counter< float > m_report_timer
 
std::map< std::string,
IMC::EntityInfo > 
m_cinfo
 
Arguments m_args
 

Additional Inherited Members

- Public Types inherited from DUNE::Concurrency::Runnable
enum  State {
  StateStarting, StateRunning, StateStopping, StateDead,
  StateUnknown
}
 
- Protected Member Functions inherited from DUNE::Tasks::Task
const char * getEntityLabel (void) const
 
void setEntityLabel (const std::string &label)
 
void setEntityState (IMC::EntityState::StateEnum state, Status::Code code)
 
void setEntityState (IMC::EntityState::StateEnum state, const std::string &description)
 
IMC::EntityState::StateEnum getEntityState (void) const
 
unsigned int reserveEntity (const std::string &label)
 
unsigned int resolveEntity (const std::string &label) const
 
std::string resolveEntity (unsigned int id) const
 
bool stopping (void)
 
bool isActive (void) const
 
void waitForMessages (double timeout)
 
void consumeMessages (void)
 
template<typename T >
Parameterparam (const std::string &name, T &var)
 
template<typename Y , typename T >
Parameterparam (const std::string &name, T &var)
 
template<typename T >
bool paramChanged (T &var)
 
void paramActive (Parameter::Scope def_scope, Parameter::Visibility def_visibility, bool def_value=false)
 
void setParamSectionEditor (const std::string &name)
 
template<typename M , typename T >
void bind (T *task_obj, void(T::*consumer)(const M *)=&T::consume)
 
template<typename T >
void bind (T *task_obj, const std::vector< uint32_t > &list)
 
template<typename T >
void bind (T *task_obj, const std::vector< std::string > &list)
 
void requestActivation (void)
 
void requestDeactivation (void)
 
void activate (void)
 
void activationFailed (const std::string &reason)
 
void deactivate (void)
 
void deactivationFailed (const std::string &reason)
 
virtual void onEntityReservation (void)
 
virtual void onEntityResolution (void)
 
virtual void onReportEntityState (void)
 
virtual void onRequestActivation (void)
 
virtual void onRequestDeactivation (void)
 
virtual void onActivation (void)
 
virtual void onDeactivation (void)
 
- Protected Member Functions inherited from DUNE::Concurrency::Thread
void startImpl (void)
 
void stopImpl (void)
 
void joinImpl (void)
 
void setPriorityImpl (Scheduler::Policy policy, unsigned priority)
 
- Protected Attributes inherited from DUNE::Tasks::Task
Contextm_ctx
 

Constructor & Destructor Documentation

Plan::Engine::Task::~Task ( void  )
inlinevirtual

Destructor.

Reimplemented from DUNE::Tasks::Task.

References closeDB().

Member Function Documentation

void Plan::Engine::Task::answer ( uint8_t  type,
const std::string &  desc,
bool  print = true 
)
inline

Answer to the plan control request.

Parameters
[in]typetype of reply (same field as plan control message)
[in]descdescription for the answer
[in]printtrue if output should be printed out

References Plan::Engine::c_op_desc, DUNE::Tasks::Task::dispatch(), DUNE::Tasks::Task::err(), DUNE::Tasks::Task::inf(), and m_reply.

Referenced by onFailure(), and onSuccess().

bool Plan::Engine::Task::blockedMode ( void  ) const
inline
void Plan::Engine::Task::changeLog ( const std::string &  name)
inline

References DUNE::Tasks::Task::dispatch(), and m_lc.

Referenced by changeMode(), and startPlan().

void Plan::Engine::Task::changeMode ( IMC::PlanControlState::StateEnum  s,
const std::string &  event_desc,
const std::string &  nid,
const IMC::Message *  maneuver,
bool  print = true 
)
inline

Change the current plan control state mode.

Parameters
[in]splan control state to switch to
[in]event_descdescription of the event that motivated the change
[in]nidid of the maneuver if any
[in]maneuverpointer to maneuver message
[in]printtrue if the messages should be printed to output

References Plan::Engine::c_state_desc, changeLog(), DUNE::Tasks::Task::debug(), DUNE::Tasks::Task::dispatch(), execMode(), initMode(), m_last_event, m_pcs, m_plan, Plan::Engine::Plan::planStopped(), and DUNE::Tasks::Task::war().

Referenced by changeMode(), consume(), loadPlan(), onMain(), onVehicleCalibration(), onVehicleError(), onVehicleExternalControl(), onVehicleManeuver(), onVehicleService(), startManeuver(), startPlan(), and stopPlan().

void Plan::Engine::Task::changeMode ( IMC::PlanControlState::StateEnum  s,
const std::string &  event_desc,
bool  print = true 
)
inline

Change the current plan control state mode.

Parameters
[in]splan control state to switch to
[in]event_descdescription of the event that motivated the change
[in]printtrue if the messages should be printed to output

References changeMode().

void Plan::Engine::Task::closeDB ( void  )
inline

References DUNE::Tasks::Task::debug(), m_db, and m_get_plan_stmt.

Referenced by consume(), and ~Task().

void Plan::Engine::Task::consume ( const IMC::EstimatedState *  msg)
inline

References m_state.

void Plan::Engine::Task::consume ( const IMC::ManeuverControlState *  msg)
inline
void Plan::Engine::Task::consume ( const IMC::PowerOperation *  po)
inline
void Plan::Engine::Task::consume ( const IMC::RegisterManeuver *  msg)
inline

References m_supported_maneuvers.

void Plan::Engine::Task::consume ( const IMC::EntityInfo *  msg)
inline

References m_cinfo.

void Plan::Engine::Task::consume ( const IMC::PlanDB *  pdb)
inline

References openDB().

void Plan::Engine::Task::consume ( const IMC::VehicleCommand *  vc)
inline
void Plan::Engine::Task::consume ( const IMC::PlanControl *  pc)
inline
bool Plan::Engine::Task::execMode ( void  ) const
inline
void Plan::Engine::Task::getPlan ( void  )
inline

Get current plan.

References execMode(), initMode(), m_reply, m_spec, onFailure(), and onSuccess().

Referenced by consume().

bool Plan::Engine::Task::initMode ( void  ) const
inline
bool Plan::Engine::Task::loadPlan ( const std::string &  plan_id,
const IMC::Message *  arg,
bool  plan_startup = false 
)
inline

Load a plan into the vehicle.

Parameters
[in]plan_idname of the plan
[in]argargument which may either be a maneuver or a plan specification
[in]plan_startuptrue if a plan will start right after
Returns
true if plan is successfully loaded

References changeMode(), execMode(), DUNE::Tasks::Task::getEntityId(), initMode(), lookForPlan(), m_pcs, m_reply, m_spec, onFailure(), onSuccess(), and parsePlan().

Referenced by consume(), and startPlan().

bool Plan::Engine::Task::lookForPlan ( const std::string &  plan_id,
IMC::PlanSpecification &  ps 
)
inline

Look for a plan in the database.

Parameters
[in]plan_idname of the plan
[in]psplan specification message
Returns
true if plan is found

References DUNE::Tasks::Task::err(), m_get_plan_stmt, and onFailure().

Referenced by loadPlan().

void Plan::Engine::Task::onFailure ( const std::string &  errmsg,
bool  print = true 
)
inline

Answer to the reply with a failure message.

Parameters
[in]errmsgtext error message to send
[in]printtrue if the message should be printed to output

References answer(), and m_pcs.

Referenced by consume(), getPlan(), loadPlan(), lookForPlan(), onVehicleError(), onVehicleService(), parsePlan(), startCalibration(), startPlan(), and stopPlan().

void Plan::Engine::Task::onResourceAcquisition ( void  )
inlinevirtual

Called when the task is instructed to acquire resources whose configuration is defined by run-time parameters.

Reimplemented from DUNE::Tasks::Task.

References Plan::Engine::Calibration, Plan::Engine::Arguments::calibration_time, m_args, m_calib, m_plan, m_spec, Plan::Engine::Plan, Plan::Engine::Arguments::progress, Plan::Engine::Arguments::speed_conv_act, and Plan::Engine::Arguments::speed_conv_rpm.

void Plan::Engine::Task::onResourceInitialization ( void  )
inlinevirtual

Called when the task is instructed to initialize resources acquired previously or whose initialization depends on run-time parameters.

Reimplemented from DUNE::Tasks::Task.

References m_args, m_report_timer, and Plan::Engine::Arguments::speriod.

void Plan::Engine::Task::onResourceRelease ( void  )
inlinevirtual

Called when the task is instructed to release resources.

Derived classes that override this function must not assume that any resource was previously acquired. This function must be implemented in such a way that it can be called at any time.

Reimplemented from DUNE::Tasks::Task.

References m_calib, and m_plan.

void Plan::Engine::Task::onSuccess ( const std::string &  msg = DTR("OK"),
bool  print = true 
)
inline

Answer to the reply with a success message.

Parameters
[in]msgtext message to send
[in]printtrue if the message should be printed to output

References answer(), and m_pcs.

Referenced by getPlan(), loadPlan(), onVehicleManeuver(), and startPlan().

void Plan::Engine::Task::onUpdateParameters ( void  )
inlinevirtual

Called when the task is instructed to update its run-time parameters.

Derived classes that need to compute auxiliary values based on run-time parameters should override this function.

Reimplemented from DUNE::Tasks::Task.

References m_args, DUNE::Tasks::Task::paramChanged(), and Plan::Engine::Arguments::speriod.

void Plan::Engine::Task::onVehicleCalibration ( const IMC::VehicleState *  vs)
inline

References blockedMode(), changeMode(), and initMode().

Referenced by consume().

void Plan::Engine::Task::onVehicleError ( const IMC::VehicleState *  vs)
inline
void Plan::Engine::Task::onVehicleExternalControl ( const IMC::VehicleState *  vs)
inline

References blockedMode(), and changeMode().

Referenced by consume().

void Plan::Engine::Task::onVehicleManeuver ( const IMC::VehicleState *  vs)
inline
void Plan::Engine::Task::onVehicleService ( const IMC::VehicleState *  vs)
inline
void Plan::Engine::Task::openDB ( void  )
inline
bool Plan::Engine::Task::parsePlan ( bool  plan_startup)
inline

Parse a given plan.

Parameters
[in]plan_startuptrue if the plan is starting up
Returns
true if was able to parse the plan

References m_cinfo, m_plan, m_state, m_supported_maneuvers, onFailure(), and Plan::Engine::Plan::parse().

Referenced by loadPlan().

bool Plan::Engine::Task::pendingReply ( void  )
inline
bool Plan::Engine::Task::readyMode ( void  ) const
inline

References m_pcs.

void Plan::Engine::Task::reportProgress ( void  )
inline
void Plan::Engine::Task::setInitialState ( void  )
inline

Set task's initial state.

References DUNE::Tasks::Task::dispatch(), m_last_event, m_last_vstate, m_pcs, m_vc_reply_deadline, and m_vreq_ctr.

Referenced by onMain().

bool Plan::Engine::Task::startCalibration ( void  )
inline

Send a request to start calibration procedures.

Returns
true if request was sent

References blockedMode(), onFailure(), and vehicleRequest().

Referenced by startPlan().

void Plan::Engine::Task::startManeuver ( IMC::PlanManeuver *  pman)
inline

Start a maneuver by name.

Parameters
[in]pmanpointer to plan maneuver message

References changeMode(), Plan::Engine::Plan::getCurrentId(), m_plan, Plan::Engine::Plan::maneuverStarted(), and vehicleRequest().

Referenced by onVehicleManeuver(), onVehicleService(), and startPlan().

bool Plan::Engine::Task::startPlan ( const std::string &  plan_id,
const IMC::Message *  spec,
uint16_t  flags 
)
inline

Start a given plan.

Parameters
[in]plan_idname of the plan to execute
[in]specplan specification message if any
[in]flagsplan control flags
Returns
false if previously executing maneuver was not stopped

References changeLog(), changeMode(), DUNE::Tasks::Task::dispatch(), execMode(), Plan::Engine::Plan::getCalibrationTime(), initMode(), loadPlan(), Plan::Engine::Plan::loadStartManeuver(), m_calib, m_last_event, m_plan, m_spec, onFailure(), onSuccess(), Plan::Engine::Plan::planStarted(), Plan::Engine::Plan::planStopped(), Plan::Engine::Calibration::setTime(), startCalibration(), startManeuver(), and stopPlan().

Referenced by consume().

bool Plan::Engine::Task::stopPlan ( bool  plan_startup = false)
inline

Stop current plan being executed.

Parameters
[in]plan_startuptrue if a plan will start right after this stop
Returns
false if a plan is still running after this

References changeMode(), DUNE::Tasks::Task::debug(), execMode(), initMode(), m_pcs, m_reply, m_spec, onFailure(), and vehicleRequest().

Referenced by consume(), and startPlan().

void Plan::Engine::Task::vehicleRequest ( IMC::VehicleCommand::CommandEnum  command,
const IMC::Message *  arg = 0 
)
inline

Member Data Documentation

Arguments Plan::Engine::Task::m_args
std::map<std::string, IMC::EntityInfo> Plan::Engine::Task::m_cinfo

Map of component names to entityinfo.

Referenced by consume(), and parsePlan().

Database::Connection* Plan::Engine::Task::m_db

Database related (for plan DB direct queries to avoid unnecessary interface with bus / PlanDB task directly)

Referenced by closeDB(), and openDB().

Database::Statement* Plan::Engine::Task::m_get_plan_stmt

Referenced by closeDB(), lookForPlan(), and openDB().

std::string Plan::Engine::Task::m_last_event

Last event description.

Referenced by changeMode(), onVehicleError(), setInitialState(), and startPlan().

double Plan::Engine::Task::m_last_vstate

Referenced by consume(), onMain(), and setInitialState().

IMC::LoggingControl Plan::Engine::Task::m_lc

Misc.

Referenced by changeLog().

IMC::ManeuverControlState Plan::Engine::Task::m_mcs

ManeuverControlState message.

Referenced by consume(), and reportProgress().

IMC::PlanControl Plan::Engine::Task::m_reply
Time::Counter<float> Plan::Engine::Task::m_report_timer

Timer counter for state report period.

Referenced by onMain(), and onResourceInitialization().

IMC::PlanSpecification Plan::Engine::Task::m_spec
IMC::EstimatedState Plan::Engine::Task::m_state

Referenced by consume(), and parsePlan().

bool Plan::Engine::Task::m_stopped_calib

True if a stop for calibration has been requested.

Referenced by consume(), and vehicleRequest().

std::set<uint16_t> Plan::Engine::Task::m_supported_maneuvers

List of supported maneuvers.

Referenced by consume(), and parsePlan().

IMC::VehicleCommand Plan::Engine::Task::m_vc

Referenced by vehicleRequest().

double Plan::Engine::Task::m_vc_reply_deadline
uint16_t Plan::Engine::Task::m_vreq_ctr

Vehicle interface.

Referenced by consume(), setInitialState(), and vehicleRequest().

bool Plan::Engine::Task::m_wait_min

True if just waiting for minimum time of calibration.

Referenced by consume().

Collaboration diagram for Plan::Engine::Task:
Collaboration graph