cnoid_ros_utils
ClockPublisherItem.h
Go to the documentation of this file.
1 /* Author: Masaki Murooka */
2 
3 #pragma once
4 
5 #include <cnoid/Archive>
6 #include <cnoid/Item>
7 #include <cnoid/SimulatorItem>
8 #include <cnoid/WorldItem>
9 
10 #include <ros/ros.h>
11 #include <rosgraph_msgs/Clock.h>
12 
13 namespace CnoidRosUtils
14 {
22 class ClockPublisherItem : public cnoid::Item
23 {
24 public:
25  static void initialize(cnoid::ExtensionManager * ext);
26 
27  inline static bool initialized_ = false;
28 
29 public:
31 
33 
35 
36 protected:
37  virtual cnoid::Item * doDuplicate() const override;
38 
39  virtual void doPutProperties(cnoid::PutPropertyFunction & putProperty) override;
40 
41  virtual bool store(cnoid::Archive & archive) override;
42 
43  virtual bool restore(const cnoid::Archive & archive) override;
44 
45  void setup();
46 
47  bool start();
48 
49  void stop();
50 
51  void onPostDynamics();
52 
53  int getPubSkip() const;
54 
55 protected:
56  cnoid::WorldItemPtr world_;
57  cnoid::SimulatorItemPtr sim_;
58 
59  std::set<std::string> hooked_sims_;
60 
62 
63  std::shared_ptr<ros::NodeHandle> nh_;
64  std::string clock_topic_name_ = "";
65  double pub_rate_ = 1000.0;
66  ros::Publisher clock_pub_;
67  bool use_sim_time_ = true;
68 
69  int sim_cnt_ = 0;
70  int pub_skip_ = 0;
71 };
72 } // namespace CnoidRosUtils
CnoidRosUtils::ClockPublisherItem::pub_skip_
int pub_skip_
Definition: ClockPublisherItem.h:70
CnoidRosUtils::ClockPublisherItem::doPutProperties
virtual void doPutProperties(cnoid::PutPropertyFunction &putProperty) override
Definition: ClockPublisherItem.cpp:53
CnoidRosUtils::ClockPublisherItem::getPubSkip
int getPubSkip() const
Definition: ClockPublisherItem.cpp:161
CnoidRosUtils::ClockPublisherItem::onPostDynamics
void onPostDynamics()
Definition: ClockPublisherItem.cpp:147
CnoidRosUtils::ClockPublisherItem::ClockPublisherItem
ClockPublisherItem()
Definition: ClockPublisherItem.cpp:30
CnoidRosUtils::ClockPublisherItem::start
bool start()
Definition: ClockPublisherItem.cpp:109
CnoidRosUtils::ClockPublisherItem::sim_
cnoid::SimulatorItemPtr sim_
Definition: ClockPublisherItem.h:57
CnoidRosUtils::ClockPublisherItem::use_sim_time_
bool use_sim_time_
Definition: ClockPublisherItem.h:67
CnoidRosUtils::ClockPublisherItem::clock_pub_
ros::Publisher clock_pub_
Definition: ClockPublisherItem.h:66
CnoidRosUtils::ClockPublisherItem::world_
cnoid::WorldItemPtr world_
Definition: ClockPublisherItem.h:56
CnoidRosUtils::ClockPublisherItem::clock_topic_name_
std::string clock_topic_name_
Definition: ClockPublisherItem.h:64
CnoidRosUtils::ClockPublisherItem::stop
void stop()
Definition: ClockPublisherItem.cpp:137
CnoidRosUtils::ClockPublisherItem::~ClockPublisherItem
~ClockPublisherItem()
Definition: ClockPublisherItem.cpp:43
CnoidRosUtils::ClockPublisherItem::nh_
std::shared_ptr< ros::NodeHandle > nh_
Definition: ClockPublisherItem.h:63
CnoidRosUtils::ClockPublisherItem
Plugin item to publish clock topic.
Definition: ClockPublisherItem.h:22
CnoidRosUtils::ClockPublisherItem::sim_cnt_
int sim_cnt_
Definition: ClockPublisherItem.h:69
CnoidRosUtils::ClockPublisherItem::post_dynamics_func_id_
int post_dynamics_func_id_
Definition: ClockPublisherItem.h:61
CnoidRosUtils::ClockPublisherItem::hooked_sims_
std::set< std::string > hooked_sims_
Definition: ClockPublisherItem.h:59
CnoidRosUtils::ClockPublisherItem::restore
virtual bool restore(const cnoid::Archive &archive) override
Definition: ClockPublisherItem.cpp:77
CnoidRosUtils::ClockPublisherItem::setup
void setup()
Definition: ClockPublisherItem.cpp:86
CnoidRosUtils
Definition: ClockPublisherItem.h:13
CnoidRosUtils::ClockPublisherItem::store
virtual bool store(cnoid::Archive &archive) override
Definition: ClockPublisherItem.cpp:68
CnoidRosUtils::ClockPublisherItem::initialize
static void initialize(cnoid::ExtensionManager *ext)
Definition: ClockPublisherItem.cpp:13
CnoidRosUtils::ClockPublisherItem::doDuplicate
virtual cnoid::Item * doDuplicate() const override
Definition: ClockPublisherItem.cpp:48
CnoidRosUtils::ClockPublisherItem::pub_rate_
double pub_rate_
Definition: ClockPublisherItem.h:65
CnoidRosUtils::ClockPublisherItem::initialized_
static bool initialized_
Definition: ClockPublisherItem.h:27