YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarprobotinterface::Module Class Reference

#include </home/runner/work/yarp-documentation/yarp-documentation/yarp/src/commands/yarprobotinterface/Module.h>

+ Inheritance diagram for yarprobotinterface::Module:

Classes

class  Private
 

Public Member Functions

 Module ()
 
virtual ~Module ()
 
double getPeriod () override
 You can override this to control the approximate periodicity at which updateModule() is called by runModule().
 
bool updateModule () override
 Override this to do whatever your module needs to do.
 
bool close () override
 Close function.
 
bool interruptModule () override
 Try to halt any ongoing operations by threads managed by the module.
 
bool configure (yarp::os::ResourceFinder &rf) override
 Configure the module, pass a ResourceFinder object to the module.
 
bool attach (yarp::os::RpcServer &source) override
 Make any input from an RpcServer object go to the respond() method.
 
std::string get_phase () override
 Returns current phase.
 
int32_t get_level () override
 Returns current level.
 
bool is_ready () override
 Returns true if yarprobotinterface is ready (all startup actions performed and no interrupt called).
 
std::string get_robot () override
 Returns robot name.
 
std::string quit () override
 Closes yarprobotinterface.
 
std::string bye () override
 Closes yarprobotinterface.
 
std::string exit () override
 Closes yarprobotinterface.
 
- Public Member Functions inherited from yarp::os::RFModule
 RFModule ()
 Constructor.
 
virtual ~RFModule ()
 Destructor.
 
virtual int runModule ()
 Calls updateModule() until that returns false.
 
virtual int runModule (yarp::os::ResourceFinder &rf)
 Simple helper method to call configure() and then runModule().
 
virtual int runModuleThreaded ()
 Calls updateModule() on a separate thread until that returns false.
 
virtual int runModuleThreaded (yarp::os::ResourceFinder &rf)
 Simple helper method to call configure() and then runModule() on a separate thread.
 
virtual int getThreadKey ()
 return the Thread unique identifier
 
virtual bool respond (const Bottle &command, Bottle &reply)
 Respond to a message.
 
virtual bool attach (yarp::os::Port &source)
 Make any input from a Port object go to the respond() method.
 
bool attachTerminal ()
 Make any input from standard input (usually the keyboard) go to the respond() method.
 
bool detachTerminal ()
 Detach terminal.
 
void stopModule (bool wait=false)
 Ask the module to stop.
 
bool isStopping ()
 Check if the module should stop.
 
bool joinModule (double seconds=-1)
 The function returns when the thread execution has completed.
 
std::string getName (const std::string &subName="")
 Return name of module, as set with setName().
 
void setName (const char *name)
 Set the name of the module.
 
bool safeRespond (const Bottle &command, Bottle &reply)
 Wrapper around respond() that is guaranteed to process system messages.
 
- Public Member Functions inherited from yarprobotinterfaceRpc
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion ()
 
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion ()
 
virtual bool checkProtocolVersion ()
 
 yarprobotinterfaceRpc ()
 
virtual std::vector< std::string > help (const std::string &functionName="--all")
 
bool read (yarp::os::ConnectionReader &connection) override
 Read this object from a network connection.
 
- Public Member Functions inherited from yarp::os::Wire
yarp::os::WireLinkyarp ()
 Get YARP state associated with this object.
 
const yarp::os::WireLinkyarp () const
 Get YARP state associated with this object (const version).
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor.
 
virtual Type getReadType () const
 

Detailed Description

Definition at line 15 of file Module.h.

Constructor & Destructor Documentation

◆ Module()

yarprobotinterface::Module::Module ( )
explicit

Definition at line 92 of file Module.cpp.

◆ ~Module()

yarprobotinterface::Module::~Module ( )
virtual

Definition at line 105 of file Module.cpp.

Member Function Documentation

◆ attach()

bool yarprobotinterface::Module::attach ( yarp::os::RpcServer source)
overridevirtual

Make any input from an RpcServer object go to the respond() method.

Parameters
sourcethe RpcServer port to attach
Returns
true if source was attached correctly.

Reimplemented from yarp::os::RFModule.

Definition at line 276 of file Module.cpp.

◆ bye()

std::string yarprobotinterface::Module::bye ( )
inlineoverridevirtual

Closes yarprobotinterface.

Reimplemented from yarprobotinterfaceRpc.

Definition at line 39 of file Module.h.

◆ close()

bool yarprobotinterface::Module::close ( )
overridevirtual

Close function.

This is called automatically when the module closes, after the last call to updateModule. Override this to cleanup memory allocated in the configure() function or perform other activities that ensure graceful shutdown.

Returns
true/false on success failure.

Reimplemented from yarp::os::RFModule.

Definition at line 242 of file Module.cpp.

◆ configure()

bool yarprobotinterface::Module::configure ( yarp::os::ResourceFinder rf)
overridevirtual

Configure the module, pass a ResourceFinder object to the module.

This function can perform initialization including object creation and memory allocation; returns false to notify that initialization was not successful and that the module should not start. Cleanup should be performed by the function close(). In case of failure during the initialization and before returning false, the function configure() should cleanup memory and resources allocated.

Parameters
rfa previously initialized ResourceFinder
Returns
true/false upon success/failure
Note
attachTerminal() is no longer called automatically. You can call it in the configure function.

Reimplemented from yarp::os::RFModule.

Definition at line 110 of file Module.cpp.

◆ exit()

std::string yarprobotinterface::Module::exit ( )
inlineoverridevirtual

Closes yarprobotinterface.

Reimplemented from yarprobotinterfaceRpc.

Definition at line 40 of file Module.h.

◆ get_level()

int32_t yarprobotinterface::Module::get_level ( )
overridevirtual

Returns current level.

Reimplemented from yarprobotinterfaceRpc.

Definition at line 287 of file Module.cpp.

◆ get_phase()

std::string yarprobotinterface::Module::get_phase ( )
overridevirtual

Returns current phase.

Reimplemented from yarprobotinterfaceRpc.

Definition at line 282 of file Module.cpp.

◆ get_robot()

std::string yarprobotinterface::Module::get_robot ( )
overridevirtual

Returns robot name.

Reimplemented from yarprobotinterfaceRpc.

Definition at line 297 of file Module.cpp.

◆ getPeriod()

double yarprobotinterface::Module::getPeriod ( )
overridevirtual

You can override this to control the approximate periodicity at which updateModule() is called by runModule().

By default, it returns 1.0. Time here is in seconds.

Returns
the desired period between successive calls to updateModule()

Reimplemented from yarp::os::RFModule.

Definition at line 186 of file Module.cpp.

◆ interruptModule()

bool yarprobotinterface::Module::interruptModule ( )
overridevirtual

Try to halt any ongoing operations by threads managed by the module.

This is called asynchronously just after a quit command is received. By default it does nothing - you may want to override this. If you have created any ports, and have any threads that are might be blocked on reading data from those ports, this is a good place to add calls to BufferedPort::interrupt() or Port::interrupt().

Returns
true if there was no catastrophic failure

Reimplemented from yarp::os::RFModule.

Definition at line 204 of file Module.cpp.

◆ is_ready()

bool yarprobotinterface::Module::is_ready ( )
overridevirtual

Returns true if yarprobotinterface is ready (all startup actions performed and no interrupt called).

Reimplemented from yarprobotinterfaceRpc.

Definition at line 292 of file Module.cpp.

◆ quit()

std::string yarprobotinterface::Module::quit ( )
overridevirtual

Closes yarprobotinterface.

Reimplemented from yarprobotinterfaceRpc.

Definition at line 302 of file Module.cpp.

◆ updateModule()

bool yarprobotinterface::Module::updateModule ( )
overridevirtual

Override this to do whatever your module needs to do.

When your module wants to stop, return false. The module's actual work could be done during this call, or it could just check the state of a thread running in the background.

The thread calls the updateModule() function every <period> seconds. At the end of each run, the thread will sleep the amounth of time required, taking into account the time spent inside the loop function. Example: requested period is 10ms, the updateModule() function take 3ms to be executed, the thread will sleep for 7ms.

Note: after each run is completed, the thread will call a yield() in order to facilitate other threads to run.

Returns
true iff module should continue

Implements yarp::os::RFModule.

Definition at line 191 of file Module.cpp.


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