SignalLogger
A library for signal logging.
signal_logger_ros::SignalLoggerRos Class Reference

#include <SignalLoggerRos.hpp>

Inheritance diagram for signal_logger_ros::SignalLoggerRos:
Inheritance graph

Public Member Functions

 SignalLoggerRos (ros::NodeHandle *nh)
 
 ~SignalLoggerRos () override=default
 Destructor. More...
 
template<typename ValueType_ >
void add (const ValueType_ *const var, const std::string &name, const std::string &group=signal_logger::LOG_ELEMENT_DEFAULT_GROUP_NAME, const std::string &unit=signal_logger::LOG_ELEMENT_DEFAULT_UNIT, const std::size_t divider=signal_logger::LOG_ELEMENT_DEFAULT_DIVIDER, const signal_logger::LogElementAction action=signal_logger::LOG_ELEMENT_DEFAULT_ACTION, const std::size_t bufferSize=signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_SIZE, const signal_logger::BufferType bufferType=signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_TYPE)
 
virtual bool cleanup () override
 Shutdown ros communication. More...
 
virtual signal_logger::TimestampPair getCurrentTime () override
 
virtual bool workerSaveData (const std::string &logFileName, const signal_logger::LogFileTypeSet &logfileTypes) override
 Save all the buffered data into a log file. More...
 
bool getLoggerConfiguration (signal_logger_msgs::GetLoggerConfigurationRequest &req, signal_logger_msgs::GetLoggerConfigurationResponse &res)
 
bool getLoggerElement (signal_logger_msgs::GetLoggerElementRequest &req, signal_logger_msgs::GetLoggerElementResponse &res)
 
bool setLoggerElement (signal_logger_msgs::SetLoggerElementRequest &req, signal_logger_msgs::SetLoggerElementResponse &res)
 
bool startLogger (std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &res)
 
bool stopLogger (std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &res)
 
bool saveLoggerData (signal_logger_msgs::SaveLoggerDataRequest &req, signal_logger_msgs::SaveLoggerDataResponse &res)
 
bool isLoggerRunning (std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &res)
 
bool loadLoggerScript (signal_logger_msgs::EditLoggerScriptRequest &req, signal_logger_msgs::EditLoggerScriptResponse &res)
 
bool saveLoggerScript (signal_logger_msgs::EditLoggerScriptRequest &req, signal_logger_msgs::EditLoggerScriptResponse &res)
 
bool logElementtoMsg (const std::string &name, signal_logger_msgs::LogElement &msg)
 
bool msgToLogElement (const signal_logger_msgs::LogElement &msg)
 
- Public Member Functions inherited from signal_logger_std::SignalLoggerStd
 SignalLoggerStd ()
 
virtual ~SignalLoggerStd ()
 
template<typename ValueType_ >
void add (const ValueType_ *const var, const std::string &name, const std::string &group=signal_logger::LOG_ELEMENT_DEFAULT_GROUP_NAME, const std::string &unit=signal_logger::LOG_ELEMENT_DEFAULT_UNIT, const std::size_t divider=signal_logger::LOG_ELEMENT_DEFAULT_DIVIDER, const signal_logger::LogElementAction action=signal_logger::LOG_ELEMENT_DEFAULT_ACTION, const std::size_t bufferSize=signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_SIZE, const signal_logger::BufferType bufferType=signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_TYPE)
 
virtual void initTimeLogElement () override
 
- Public Member Functions inherited from signal_logger::SignalLoggerBase
 SignalLoggerBase ()
 
virtual ~SignalLoggerBase ()=default
 Destructor. More...
 
virtual void initLogger (const SignalLoggerOptions &options)
 
bool isRunning () const
 True if logger is running. More...
 
virtual bool startLogger (bool updateLogger=false)
 Starts the logger (enable collecting) More...
 
virtual bool stopLogger ()
 Stop the logger (disable collecting) More...
 
virtual bool restartLogger (bool updateLogger=false)
 Stop and then restart the logger. More...
 
virtual bool updateLogger (const bool readScript=true, const std::string &scriptname="")
 Update the logger, variables added since the last call are added. More...
 
virtual bool saveLoggerScript (const std::string &scriptName=std::string(LOGGER_DEFAULT_SCRIPT_FILENAME))
 
virtual bool collectLoggerData ()
 Collect log data, read data and push it into the buffer. More...
 
virtual bool publishData ()
 Publish a single data point of every element from the buffer. More...
 
virtual bool saveLoggerData (const LogFileTypeSet &logfileTypes)
 
virtual bool stopAndSaveLoggerData (const LogFileTypeSet &logfileTypes)
 
void setMaxLoggingTime (double maxLoggingTime)
 Set max logging time. More...
 
bool hasElement (const std::string &name)
 Checks if logger has a log element with name 'name'. More...
 
const LogElementInterfacegetElement (const std::string &name)
 Gets a const reference to a log element. More...
 
bool enableElement (const std::string &name)
 Enables the element if: More...
 
bool disableElement (const std::string &name)
 Disables element if logger is not running. More...
 
bool setElementBufferSize (const std::string &name, const std::size_t size)
 Sets buffer size of element if logger is not running. More...
 
bool setElementBufferType (const std::string &name, const BufferType type)
 Sets buffer type of element if logger is not running. More...
 
bool setElementDivider (const std::string &name, const std::size_t divider)
 Sets divider of element if logger is not running. More...
 
bool setElementAction (const std::string &name, const LogElementAction action)
 Sets action of element if logger is not running. More...
 
template<typename ValueType_ >
vector_type< ValueType_ > readNewValues (const std::string &name)
 Get new values (since the last call to this function) as a vector (first entry is the oldest) More...
 
bool enableNamespace (const std::string &ns)
 Property setting functions extended to namespace. More...
 
bool disableNamespace (const std::string &ns)
 
bool setNamespaceBufferSize (const std::string &ns, const std::size_t size)
 
bool setNamespaceBufferType (const std::string &ns, const BufferType type)
 
bool setNamespaceDivider (const std::string &ns, const std::size_t divider)
 
bool setNamespaceAction (const std::string &ns, const LogElementAction action)
 

Private Attributes

ros::NodeHandle * nh_
 ROS nodehandle. More...
 
std::shared_ptr< rosbag::Bag > bagWriter_
 Shared ptr to a bag writer object. More...
 
ros::ServiceServer getLoggerConfigurationService_
 Get logger configuration service. More...
 
ros::ServiceServer getLoggerElementService_
 Get logger element service. More...
 
ros::ServiceServer setLoggerElementService_
 Set logger element service. More...
 
ros::ServiceServer startLoggerService_
 Start logger service. More...
 
ros::ServiceServer stopLoggerService_
 Stop logger service. More...
 
ros::ServiceServer saveLoggerDataService_
 Save logger data service. More...
 
ros::ServiceServer loadLoggerScriptService_
 Load logger script service. More...
 
ros::ServiceServer saveLoggerScriptService_
 Save logger script service. More...
 
ros::ServiceServer isLoggerRunningService_
 Is logger running service. More...
 

Additional Inherited Members

- Protected Types inherited from signal_logger::SignalLoggerBase
using LogPair = std::pair< std::string, std::unique_ptr< LogElementInterface >>
 Log element map types. More...
 
using LogElementMap = std::unordered_map< std::string, std::unique_ptr< LogElementInterface >>
 
using LogElementMapIterator = LogElementMap::iterator
 
- Protected Member Functions inherited from signal_logger::SignalLoggerBase
bool readDataCollectScript (const std::string &scriptName)
 
bool saveDataCollectScript (const std::string &scriptName)
 
virtual bool hasElementLockFree (const std::string &name)
 Lock free version of has element. More...
 
virtual bool updateLoggerLockFree (const bool readScript=true, const std::string &scriptname="")
 Lock free version of updateLogger. More...
 
- Protected Attributes inherited from signal_logger_std::SignalLoggerStd
std::ofstream file_
 Log file. More...
 
std::stringstream textStream_
 Text stream. More...
 
std::stringstream binaryStream_
 Binary stream. More...
 
- Protected Attributes inherited from signal_logger::SignalLoggerBase
SignalLoggerOptions options_
 Logger Options. More...
 
std::atomic_uint noCollectDataCalls_
 Nr of calls to collect data. More...
 
std::atomic_uint noCollectDataCallsCopy_
 Copy of nr of calls to collect data for saving. More...
 
LogElementMap logElements_
 Map of log elements (excluding time, elements added after last updateLogger() call) More...
 
std::vector< LogElementMapIteratorenabledElements_
 Vector of iterators in logElements_ map. More...
 
LogElementMap logElementsToAdd_
 Map of all log elements added since last call to updateLogger() More...
 
TimestampPair logTime_
 Time variable. More...
 
std::shared_ptr< LogElementBase< TimestampPair > > timeElement_
 Corresponding time log element. More...
 
std::atomic_bool isInitialized_
 Flag to check if logger is initialized. More...
 
std::atomic_bool isCollectingData_
 Flag to collect data. More...
 
std::atomic_bool isSavingData_
 Flag to save data. More...
 
std::atomic_bool isCopyingBuffer_
 Flag to save data. More...
 
std::atomic_bool isStarting_
 Flag is starting in different thread. More...
 
std::atomic_bool shouldPublish_
 Flag if data should be published. More...
 
boost::shared_mutex loggerMutex_
 Init, add, update, start, stop and cleanup should be called in sequence. More...
 
std::mutex saveLoggerDataMutex_
 Allow call to save logger data only once. More...
 

Constructor & Destructor Documentation

signal_logger_ros::SignalLoggerRos::SignalLoggerRos ( ros::NodeHandle *  nh)
explicit

Constructor

Parameters
nhpointer to the ros nodehandle
signal_logger_ros::SignalLoggerRos::~SignalLoggerRos ( )
overridedefault

Destructor.

Member Function Documentation

template<typename ValueType_ >
void signal_logger_ros::SignalLoggerRos::add ( const ValueType_ *const  var,
const std::string &  name,
const std::string &  group = signal_logger::LOG_ELEMENT_DEFAULT_GROUP_NAME,
const std::string &  unit = signal_logger::LOG_ELEMENT_DEFAULT_UNIT,
const std::size_t  divider = signal_logger::LOG_ELEMENT_DEFAULT_DIVIDER,
const signal_logger::LogElementAction  action = signal_logger::LOG_ELEMENT_DEFAULT_ACTION,
const std::size_t  bufferSize = signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_SIZE,
const signal_logger::BufferType  bufferType = signal_logger::LOG_ELEMENT_DEFAULT_BUFFER_TYPE 
)
inline

Add variable to logger. This is a default implementation if no specialization is provided an error is posted.

Template Parameters
ValueType_Data type of the logger element
Parameters
varPointer to log variable
namename of the log variable
grouplogger group the variable belongs to
unitunit of the log variable
dividerdivider is defining the update frequency of the logger element (ctrl_freq/divider)
actionlog action of the log variable
bufferSizesize of the buffer storing log elements
bufferTypedetermines the buffer type
virtual bool signal_logger_ros::SignalLoggerRos::cleanup ( )
overridevirtual

Shutdown ros communication.

Reimplemented from signal_logger::SignalLoggerBase.

virtual signal_logger::TimestampPair signal_logger_ros::SignalLoggerRos::getCurrentTime ( )
overridevirtual

Returns the current time

Returns
current time

Reimplemented from signal_logger::SignalLoggerBase.

bool signal_logger_ros::SignalLoggerRos::getLoggerConfiguration ( signal_logger_msgs::GetLoggerConfigurationRequest req,
signal_logger_msgs::GetLoggerConfigurationResponse res 
)

Get current logger configuration

Parameters
reqempty request
reslogger_namespace, script_filepath, log_element_names, collect_frequency
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::getLoggerElement ( signal_logger_msgs::GetLoggerElementRequest req,
signal_logger_msgs::GetLoggerElementResponse res 
)

Get logger element

Parameters
reqelement name
reslogger element
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::isLoggerRunning ( std_srvs::TriggerRequest &  req,
std_srvs::TriggerResponse &  res 
)

Is logger running

Parameters
reqempty request
resis logger running flag
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::loadLoggerScript ( signal_logger_msgs::EditLoggerScriptRequest req,
signal_logger_msgs::EditLoggerScriptResponse res 
)

Load logger script

Parameters
reqfile path
ressuccess status
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::logElementtoMsg ( const std::string &  name,
signal_logger_msgs::LogElement msg 
)

Write log element to msg

Parameters
namelog element name
msglog element message
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::msgToLogElement ( const signal_logger_msgs::LogElement msg)

Write msg to log element

Parameters
msglog element message (contains name of log element to write)
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::saveLoggerData ( signal_logger_msgs::SaveLoggerDataRequest req,
signal_logger_msgs::SaveLoggerDataResponse res 
)

Save Logger data

Parameters
reqempty request
ressuccess status
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::saveLoggerScript ( signal_logger_msgs::EditLoggerScriptRequest req,
signal_logger_msgs::EditLoggerScriptResponse res 
)

Save logger script

Parameters
reqfile path
ressuccess status
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::setLoggerElement ( signal_logger_msgs::SetLoggerElementRequest req,
signal_logger_msgs::SetLoggerElementResponse res 
)

Set logger element

Parameters
reqlog element
ressuccess status
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::startLogger ( std_srvs::TriggerRequest &  req,
std_srvs::TriggerResponse &  res 
)

Start Logger

Parameters
reqempty request
ressuccess status
Returns
true iff successful
bool signal_logger_ros::SignalLoggerRos::stopLogger ( std_srvs::TriggerRequest &  req,
std_srvs::TriggerResponse &  res 
)

Stop Logger

Parameters
reqempty request
ressuccess status
Returns
true iff successful
virtual bool signal_logger_ros::SignalLoggerRos::workerSaveData ( const std::string &  logFileName,
const signal_logger::LogFileTypeSet logfileTypes 
)
overridevirtual

Save all the buffered data into a log file.

Reimplemented from signal_logger_std::SignalLoggerStd.

Member Data Documentation

std::shared_ptr<rosbag::Bag> signal_logger_ros::SignalLoggerRos::bagWriter_
private

Shared ptr to a bag writer object.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::getLoggerConfigurationService_
private

Get logger configuration service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::getLoggerElementService_
private

Get logger element service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::isLoggerRunningService_
private

Is logger running service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::loadLoggerScriptService_
private

Load logger script service.

ros::NodeHandle* signal_logger_ros::SignalLoggerRos::nh_
private

ROS nodehandle.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::saveLoggerDataService_
private

Save logger data service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::saveLoggerScriptService_
private

Save logger script service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::setLoggerElementService_
private

Set logger element service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::startLoggerService_
private

Start logger service.

ros::ServiceServer signal_logger_ros::SignalLoggerRos::stopLoggerService_
private

Stop logger service.


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