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 <aspect/logging.h>
25 #include <fvutils/color/conversions.h>
26 #include <tf/types.h>
27 #include <utils/math/angle.h>
28 
29 #include <gazebo/msgs/msgs.hh>
30 #include <gazebo/transport/Node.hh>
31 #include <gazebo/transport/transport.hh>
32 #include <math.h>
33 #include <stdio.h>
34 
35 using namespace fawkes;
36 using namespace gazebo;
37 
38 /** @class WebcamSimThread "gazsim_webcam_thread.h"
39  * Thread simulates a number of webcams in Gazebo
40  * @author Frederik Zwilling
41  */
42 
43 /** Constructor. */
45 : Thread("WebcamSimThread", Thread::OPMODE_WAITFORWAKEUP),
46  BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS)
47 {
48 }
49 
50 void
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  webcams_.push_back(new GazsimWebcam(*it, gazebo_world_node, config));
58  }
59 }
60 
61 void
63 {
64  for (std::vector<GazsimWebcam *>::iterator it = webcams_.begin(); it != webcams_.end(); ++it) {
65  delete *it;
66  }
67 }
68 
69 void
71 {
72  //The interesting stuff happens in the callback of the webcams
73 }
WebcamSimThread::init
virtual void init()
Initialize the thread.
Definition: gazsim_webcam_thread.cpp:51
WebcamSimThread::WebcamSimThread
WebcamSimThread()
Constructor.
Definition: gazsim_webcam_thread.cpp:44
fawkes::BlockedTimingAspect
Definition: blocked_timing.h:56
WebcamSimThread::loop
virtual void loop()
Code to execute in the thread.
Definition: gazsim_webcam_thread.cpp:70
fawkes::Thread::name
const char * name() const
Definition: thread.h:100
fawkes::LoggingAspect::logger
Logger * logger
Definition: logging.h:53
fawkes
fawkes::Configuration::get_strings
virtual std::vector< std::string > get_strings(const char *path)=0
fawkes::GazeboAspect::gazebo_world_node
gazebo::transport::NodePtr gazebo_world_node
Gazebo Node for communication with the world (e.g.
Definition: gazebo.h:57
fawkes::ConfigurableAspect::config
Configuration * config
Definition: configurable.h:53
GazsimWebcam
Definition: gazsim_webcam.h:42
fawkes::Thread
Definition: thread.h:45
WebcamSimThread::finalize
virtual void finalize()
Finalize the thread.
Definition: gazsim_webcam_thread.cpp:62
fawkes::Logger::log_debug
virtual void log_debug(const char *component, const char *format,...)=0