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

Public Member Functions

 Task (const std::string &name, Tasks::Context &ctx)
 
void onEntityResolution (void)
 
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::RegisterManeuver *msg)
 
void consume (const IMC::EntityInfo *msg)
 
void consume (const IMC::EntityActivationState *msg)
 
void consume (const IMC::FuelLevel *msg)
 
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)
 
void processRequest (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, IMC::PlanStatistics &ps)
 
bool lookForPlan (const std::string &plan_id, IMC::PlanSpecification &ps)
 
bool parseArg (const std::string &plan_id, const IMC::Message *arg, std::string &info)
 
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, OutputType print=TYPE_WAR)
 
void changeMode (IMC::PlanControlState::StateEnum s, const std::string &event_desc, OutputType print=TYPE_WAR)
 
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)
 
virtual ~Task (void)
 
const char * getName (void) const
 
const char * getSystemName (void) const
 
unsigned int getSystemId (void) const
 
unsigned int getEntityId (void) const
 
unsigned int resolveEntity (const std::string &label) const
 
std::string resolveEntity (unsigned int id) const
 
DebugLevel getDebugLevel (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
 
const char * getEntityLabel (void) const
 
void setEntityLabel (const std::string &label)
 
- 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)
 
unsigned getPriority (void)
 
State getState (void)
 
bool isCreated (void)
 
bool isStopping (void)
 
bool isRunning (void)
 
bool isStarting (void)
 
bool isDead (void)
 

Public Attributes

Planm_plan
 
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
 
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
 
unsigned m_eid_imu
 
unsigned m_eid_gen
 
bool m_imu_enabled
 
std::queue< IMC::PlanControl > m_requests
 
Path m_db_file
 
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
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)
 
template<typename E >
E * reserveEntity (const std::string &label)
 
Entities::BasicEntitygetLocalEntity (const std::string &label)
 
bool stopping (void)
 
bool isActive (void) const
 
bool isActivating (void) const
 
bool isDeactivating (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 , typename M >
void bind (T *task_obj, const std::vector< uint32_t > &list, void(T::*consumer)(const M *)=&T::consume)
 
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 bool onWriteParamsXML (std::ostream &os) const
 
virtual void onEntityReservation (void)
 
virtual void onReportEntityState (void)
 
virtual void onRequestActivation (void)
 
virtual void onRequestDeactivation (void)
 
virtual void onActivation (void)
 
virtual void onDeactivation (void)
 
virtual void onQueryEntityParameters (const IMC::QueryEntityParameters *msg)
 
virtual void onSetEntityParameters (const IMC::SetEntityParameters *msg)
 
virtual void onPushEntityParameters (const IMC::PushEntityParameters *msg)
 
virtual void onPopEntityParameters (const IMC::PopEntityParameters *msg)
 
- Protected Member Functions inherited from DUNE::Concurrency::Thread
void startImpl (void)
 
void stopImpl (void)
 
void joinImpl (void)
 
void setPriorityImpl (Scheduler::Policy policy, unsigned priority)
 
unsigned getPriorityImpl (void)
 
- Protected Attributes inherited from DUNE::Tasks::Task
Contextm_ctx
 
std::vector
< Entities::BasicEntity * > 
m_entities
 

Constructor & Destructor Documentation

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,
OutputType  print = TYPE_WAR 
)
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(), DUNE::Tasks::Task::inf(), initMode(), m_last_event, m_pcs, m_plan, Plan::Engine::Plan::planStopped(), Plan::Engine::TYPE_INF, Plan::Engine::TYPE_WAR, 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,
OutputType  print = TYPE_WAR 
)
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::consume ( const IMC::EstimatedState *  msg)
inline
void Plan::Engine::Task::consume ( const IMC::ManeuverControlState *  msg)
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::FuelLevel *  msg)
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 processRequest().

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(), initMode(), m_pcs, m_reply, m_spec, onFailure(), onSuccess(), parseArg(), and parsePlan().

Referenced by processRequest(), 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 m_db_file, and onFailure().

Referenced by parseArg().

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

Called when the task is instructed to resolve all the entity identifiers it needs for normal execution.

See resolveEntity(). Derived classes that need to resolve entity identifiers should override this function.

Reimplemented from DUNE::Tasks::Task.

References Plan::Engine::Arguments::label_gen, Plan::Engine::Arguments::label_imu, m_args, m_eid_gen, m_eid_imu, and DUNE::Tasks::Task::resolveEntity().

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(), processRequest(), 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::Arguments::calibration_time, DUNE::Tasks::Context::config, Plan::Engine::Arguments::fpredict, m_args, DUNE::Tasks::Task::m_ctx, m_plan, m_spec, Plan::Engine::Arguments::max_depth, Plan::Engine::Plan, and Plan::Engine::Arguments::progress.

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 DUNE::Tasks::Task::debug(), m_args, m_db_file, m_report_timer, DUNE::Tasks::Task::setEntityState(), 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_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(), startPlan(), and stopPlan().

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 Plan::Engine::Arguments::calibration_time, m_args, m_plan, DUNE::Tasks::Task::paramChanged(), Plan::Engine::Arguments::progress, and Plan::Engine::Arguments::speriod.

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

References blockedMode(), changeMode(), and Plan::Engine::TYPE_NONE.

Referenced by consume().

void Plan::Engine::Task::onVehicleManeuver ( const IMC::VehicleState *  vs)
inline
void Plan::Engine::Task::onVehicleService ( const IMC::VehicleState *  vs)
inline
bool Plan::Engine::Task::parseArg ( const std::string &  plan_id,
const IMC::Message *  arg,
std::string &  info 
)
inline

Get the PlanSpecification from IMC::Message.

Parameters
[in]plan_idID of the plan
[in]argpointer to arg message
[out]infostring with the error in case of failure
Returns
false if unable to get the spec

References DUNE::Tasks::Task::getEntityId(), lookForPlan(), m_reply, and m_spec.

Referenced by loadPlan().

bool Plan::Engine::Task::parsePlan ( bool  plan_startup,
IMC::PlanStatistics &  ps 
)
inline

Parse a given plan.

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

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

Referenced by loadPlan().

bool Plan::Engine::Task::pendingReply ( void  )
inline
void Plan::Engine::Task::processRequest ( const IMC::PlanControl *  pc)
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(), m_args, m_state, onFailure(), Plan::Engine::Arguments::sk_calib, Plan::Engine::Arguments::sk_radius, Plan::Engine::Arguments::sk_rpm, 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(), Plan::Engine::TYPE_INF, and vehicleRequest().

Referenced by consume(), 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(), Plan::Engine::Arguments::do_calib, execMode(), initMode(), loadPlan(), Plan::Engine::Plan::loadStartManeuver(), m_args, m_last_event, m_plan, m_spec, onFailure(), onSuccess(), Plan::Engine::Plan::planStarted(), Plan::Engine::Plan::planStopped(), startCalibration(), startManeuver(), stopPlan(), and Plan::Engine::TYPE_INF.

Referenced by processRequest().

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(), onSuccess(), Plan::Engine::TYPE_INF, and vehicleRequest().

Referenced by processRequest(), and startPlan().

Member Data Documentation

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

Map of component names to entityinfo.

Referenced by consume(), and parsePlan().

Path Plan::Engine::Task::m_db_file

Plan database file.

Referenced by lookForPlan(), onResourceInitialization(), and Task().

unsigned Plan::Engine::Task::m_eid_gen

Source entity of the plan generator.

Referenced by consume(), and onEntityResolution().

unsigned Plan::Engine::Task::m_eid_imu

Source entity of the IMU.

Referenced by consume(), and onEntityResolution().

bool Plan::Engine::Task::m_imu_enabled

IMU is enabled or not.

Referenced by consume(), and parsePlan().

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().

std::queue<IMC::PlanControl> Plan::Engine::Task::m_requests

Queue of PlanControl messages.

Referenced by consume(), and onMain().

IMC::PlanSpecification Plan::Engine::Task::m_spec
IMC::EstimatedState Plan::Engine::Task::m_state
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(), onMain(), setInitialState(), and vehicleRequest().

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