Fawkes API  Fawkes Development Version
gazsim_webcam_thread.cpp
1 /***************************************************************************
2  * gazsim_webcam_plugin.cpp - Plugin simulates Webcams in Gazebo and
3  * provides a shared memory buffer
4  *
5  * Created: Sat Sep 21 17:37:42 2013
6  * Copyright 2013 Frederik Zwilling
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include "gazsim_webcam_thread.h"
23 
24 #include <tf/types.h>
25 #include <stdio.h>
26 #include <math.h>
27 #include <utils/math/angle.h>
28 
29 #include <gazebo/transport/Node.hh>
30 #include <gazebo/msgs/msgs.hh>
31 #include <gazebo/transport/transport.hh>
32 #include <aspect/logging.h>
33 
34 #include <fvutils/color/conversions.h>
35 
36 using namespace fawkes;
37 using namespace gazebo;
38 
39 /** @class WebcamSimThread "gazsim_webcam_thread.h"
40  * Thread simulates a number of webcams in Gazebo
41  * @author Frederik Zwilling
42  */
43 
44 /** Constructor. */
46  : Thread("WebcamSimThread", Thread::OPMODE_WAITFORWAKEUP),
47  BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS)
48 {
49 }
50 
52 {
53  logger->log_debug(name(), "Initializing Simulation of the Webcams");
54  shm_ids_ = config->get_strings("/gazsim/webcam/shm-image-ids");
55 
56  for (std::vector<std::string>::iterator it = shm_ids_.begin(); it != shm_ids_.end(); ++it)
57  {
58  webcams_.push_back(new GazsimWebcam(*it, gazebo_world_node, config));
59  }
60 }
61 
63 {
64  for (std::vector<GazsimWebcam*>::iterator it = webcams_.begin(); it != webcams_.end(); ++it)
65  {
66  delete *it;
67  }
68 }
69 
71 {
72  //The interesting stuff happens in the callback of the webcams
73 }
WebcamSimThread()
Constructor.
Definition: gps.h:30
Fawkes library namespace.
gazebo::transport::NodePtr gazebo_world_node
Gazebo Node for communication with the world (e.g.
Definition: gazebo.h:52
virtual void finalize()
Finalize the thread.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
Thread aspect to use blocked timing.
virtual void init()
Initialize the thread.
virtual void loop()
Code to execute in the thread.
const char * name() const
Get name of thread.
Definition: thread.h:95
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual std::vector< std::string > get_strings(const char *path)=0
Get list of values from configuration which is of type string.
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:44
Simulates a single webcam in Gazebo.
Definition: gazsim_webcam.h:43