Public Member Functions | Private Attributes | List of all members
cras::NodeWithOptionalMaster Class Reference

Node that can run both with and without a ROS master. This can be useful for one-off scripts that do not need to publish or subscribe anything, but they want to make use of the parameter processing and name remapping. More...

#include <node_with_optional_master.h>

Inheritance diagram for cras::NodeWithOptionalMaster:
Inheritance graph
[legend]

Public Member Functions

::cras::BoundParamHelperPtr getPrivateParams () const
 Get private parameters of the node. More...
 
void init (const ::ros::M_string &remappings, const ::std::string &name, uint32_t options)
 Initialize the node, autodetecting whether a ros master is running or not. More...
 
void init (const ::ros::VP_string &remappings, const ::std::string &name, uint32_t options)
 Initialize the node, autodetecting whether a ros master is running or not. More...
 
void init (int &argc, char **argv, const ::std::string &name, uint32_t options)
 Initialize the node, autodetecting whether a ros master is running or not. More...
 
bool isInitialized () const
 Has init() been called? More...
 
 NodeWithOptionalMaster (const ::cras::LogHelperPtr &log)
 
bool ok () const
 Equivalent of ros::ok() . More...
 
::std::string resolveName (const ::std::string &name, bool remap=true) const
 Resolve a name relative to the global namespace. More...
 
void shutdown ()
 Shutdown the node. More...
 
bool usesMaster () const
 Is a live ROS master being used? More...
 
virtual ~NodeWithOptionalMaster ()
 
- Public Member Functions inherited from cras::HasLogger
::cras::LogHelperConstPtr getCrasLogger () const
 This is the function picked up by CRAS_* logging macros. More...
 
 HasLogger (const ::cras::LogHelperPtr &log)
 Associate the logger with this interface. More...
 
void setCrasLogger (const ::cras::LogHelperPtr &log)
 Set the logger to be used for logging. More...
 

Private Attributes

::std::unique_ptr< NodeWithOptionalMasterPrivate > data
 PIMPL. More...
 

Additional Inherited Members

- Protected Attributes inherited from cras::HasLogger
::cras::LogHelperPtr log
 Log helper. More...
 

Detailed Description

Node that can run both with and without a ROS master. This can be useful for one-off scripts that do not need to publish or subscribe anything, but they want to make use of the parameter processing and name remapping.

This class provides an interface similar to ros::NodeHandle. However, when init() is called, it first checks whether the rosmaster is running and can be contacted. If not, this class falls back to a mode with no master. It will still provide parameters and name resolving, however, only for the parameters and remaps directly specified when launching the node. When running without master, simulation time is never used.

Definition at line 33 of file node_with_optional_master.h.

Constructor & Destructor Documentation

◆ NodeWithOptionalMaster()

cras::NodeWithOptionalMaster::NodeWithOptionalMaster ( const ::cras::LogHelperPtr log)
explicit
Parameters
[in]logLogger.

◆ ~NodeWithOptionalMaster()

virtual cras::NodeWithOptionalMaster::~NodeWithOptionalMaster ( )
virtual

Member Function Documentation

◆ getPrivateParams()

::cras::BoundParamHelperPtr cras::NodeWithOptionalMaster::getPrivateParams ( ) const

Get private parameters of the node.

Returns
The parameters object.
Remarks
When running without master, only parameters directly specified in remappings will be available.

◆ init() [1/3]

void cras::NodeWithOptionalMaster::init ( const ::ros::M_string remappings,
const ::std::string &  name,
uint32_t  options 
)

Initialize the node, autodetecting whether a ros master is running or not.

Parameters
[in]remappingsRemappings of parameters and topics.
[in]nameNode name.
[in]optionsNode init options.

◆ init() [2/3]

void cras::NodeWithOptionalMaster::init ( const ::ros::VP_string remappings,
const ::std::string &  name,
uint32_t  options 
)

Initialize the node, autodetecting whether a ros master is running or not.

Parameters
[in]remappingsRemappings of parameters and topics.
[in]nameNode name.
[in]optionsNode init options.

◆ init() [3/3]

void cras::NodeWithOptionalMaster::init ( int argc,
char **  argv,
const ::std::string &  name,
uint32_t  options 
)

Initialize the node, autodetecting whether a ros master is running or not.

Parameters
[in]argcNr. of CLI args.
[in]argvCLI args.
[in]nameNode name.
[in]optionsNode init options.

◆ isInitialized()

bool cras::NodeWithOptionalMaster::isInitialized ( ) const

Has init() been called?

◆ ok()

bool cras::NodeWithOptionalMaster::ok ( ) const

Equivalent of ros::ok() .

◆ resolveName()

::std::string cras::NodeWithOptionalMaster::resolveName ( const ::std::string &  name,
bool  remap = true 
) const

Resolve a name relative to the global namespace.

Parameters
nameThe name to be resolved (cannot start with ~).
remapWhether remapping should be applied.
Returns
The resolved name.

◆ shutdown()

void cras::NodeWithOptionalMaster::shutdown ( )

Shutdown the node.

◆ usesMaster()

bool cras::NodeWithOptionalMaster::usesMaster ( ) const

Is a live ROS master being used?

Member Data Documentation

◆ data

::std::unique_ptr<NodeWithOptionalMasterPrivate> cras::NodeWithOptionalMaster::data
private

PIMPL.

Definition at line 103 of file node_with_optional_master.h.


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


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sun Jan 5 2025 03:50:33