Skip to content
Snippets Groups Projects
ros_time.cpp 1.02 KiB
Newer Older
///
/// Copyright 2012 CNRS
///
/// Author: Florent Lamiraux

#include <dynamic-graph/factory.h>
#include <dynamic-graph/signal-caster.h>
#include <dynamic-graph/signal-cast-helper.h>

#include "ros_time.hh"
#include "converter.hh"

namespace dynamicgraph {

Olivier Stasse's avatar
Olivier Stasse committed
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(RosTime, "RosTime");

using namespace boost::posix_time;

const std::string RosTime::docstring_(
    "Export ROS time into dynamic-graph.\n"
    "\n"
    "  Signal \"time\" provides time as given by ros::time as\n"
    "  boost::posix_time::ptime type.\n");

RosTime::RosTime(const std::string& _name)
    : Entity(_name), now_("RosTime(" + _name + ")::output(boost::posix_time::ptime)::time") {
Olivier Stasse's avatar
Olivier Stasse committed
  signalRegistration(now_);
  now_.setConstant(rosTimeToPtime(ros::Time::now()));
  now_.setFunction(boost::bind(&RosTime::update, this, _1, _2));
}

ptime& RosTime::update(ptime& time, const int&) {
  time = rosTimeToPtime(ros::Time::now());
  return time;
}

std::string RosTime::getDocString() const { return docstring_; }
}  // namespace dynamicgraph