Fawkes API Fawkes Development Version
gazsim_timesource_thread.cpp
1/***************************************************************************
2 * gazsim_timesource_plugin.cpp - Plugin sets the fawkes time
3 * to the simulation time
4 *
5 * Created: Sat Sep 21 20:56:29 2013
6 * Copyright 2013 Frederik Zwilling
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#include "gazsim_timesource_thread.h"
24
25using namespace fawkes;
26
27/** @class GazsimTimesourceThread "clips_thread.h"
28 * Plugin provides the simulation time from gazebo
29 * @author Frederik Zwilling
30 */
31
32GazsimTimesourceThread::GazsimTimesourceThread()
33: Thread("GazsimTimesourceThread", Thread::OPMODE_WAITFORWAKEUP),
34 BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_WORLDSTATE)
35{
36}
37
38GazsimTimesourceThread::~GazsimTimesourceThread()
39{
40}
41
42void
44{
45 logger->log_info(name(), "GazsimTimesource initializing");
46
47 //Create Subscriber
48 time_sync_sub_ = gazebo_world_node->Subscribe(config->get_string("/gazsim/topics/time"),
49 &GazsimTimesourceThread::on_time_sync_msg,
50 this);
51
52 //Create Time Source
53 time_source_ = new GazsimTimesource(clock);
54
55 //register timesource and make it default
56 clock->register_ext_timesource(time_source_, true);
57}
58
59void
61{
62 //remove time source
63 clock->remove_ext_timesource(time_source_);
64 delete time_source_;
65}
66
67void
69{
70 //nothing interesting
71}
72
73void
74GazsimTimesourceThread::on_time_sync_msg(ConstSimTimePtr &msg)
75{
76 // logger->log_info(name(), "Got Simulation Time");
77
78 //provide time source with newest message
79 time_source_->on_time_sync_msg(msg);
80}
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
virtual void loop()
Code to execute in the thread.
Thread aspect to use blocked timing.
Clock * clock
By means of this member access to the clock is given.
Definition: clock.h:42
void remove_ext_timesource(TimeSource *ts=0)
Remove external time source.
Definition: clock.cpp:103
void register_ext_timesource(TimeSource *ts, bool make_default=false)
Register an external time source.
Definition: clock.cpp:88
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:41
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
gazebo::transport::NodePtr gazebo_world_node
Gazebo Node for communication with the world (e.g.
Definition: gazebo.h:51
This time-source provides the simulation time from Gazebo in Fawkes.
void on_time_sync_msg(ConstSimTimePtr &msg)
store data from gazebo time message
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Fawkes library namespace.