Fawkes API  Fawkes Development Version
pantilt_plugin.cpp
1 
2 /***************************************************************************
3  * pantilt_plugin.cpp - Plugin to drive pan/tilt units (e.g. for cameras)
4  *
5  * Created: Wed Jun 17 19:27:08 2009
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
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 "pantilt_plugin.h"
24 
25 #include "dirperc/dp_thread.h"
26 #include "robotis/rx28_thread.h"
27 #include "sensor_thread.h"
28 #include "sony/evid100p_thread.h"
29 
30 #include <set>
31 
32 using namespace fawkes;
33 
34 /** @class PanTiltPlugin "pantilt_plugin.h"
35  * Plugin to drive pan/tilt units with Fawkes.
36  * This plugin integrates a number of known pan/tilt units.
37  * @author Tim Niemueller
38  */
39 
40 /** Constructor.
41  * @param config Fawkes configuration
42  */
44 {
45  std::set<std::string> ptus;
46  std::set<std::string> ignored_ptus;
47 
48  std::string prefix = "/hardware/pantilt/";
49  std::string ptus_prefix = prefix + "ptus/";
50 
51  PanTiltSensorThread *sensor_thread = new PanTiltSensorThread();
52 
53  Configuration::ValueIterator *i = config->search(ptus_prefix.c_str());
54  while (i->next()) {
55  std::string ptu = std::string(i->path()).substr(ptus_prefix.length());
56  ptu = ptu.substr(0, ptu.find("/"));
57 
58  if ((ptus.find(ptu) == ptus.end()) && (ignored_ptus.find(ptu) == ignored_ptus.end())) {
59  std::string ptu_prefix = ptus_prefix + ptu + "/";
60 
61  bool active = true;
62  try {
63  active = config->get_bool((ptu_prefix + "active").c_str());
64  } catch (Exception &e) {
65  } // ignored, assume enabled
66 
67  if (active) {
68  //printf("Adding sync thread for peer %s\n", peer.c_str());
69  std::string type = config->get_string((ptu_prefix + "type").c_str());
70  PanTiltActThread *act_thread;
71 
72  if (type == "RX28") {
73  act_thread = new PanTiltRX28Thread(prefix, ptu_prefix, ptu);
74  } else if (type == "EviD100P") {
75  act_thread = new PanTiltSonyEviD100PThread(prefix, ptu_prefix, ptu);
76  } else if (type == "DirPercASCII") {
77  act_thread = new PanTiltDirectedPerceptionThread(prefix, ptu_prefix, ptu);
78  } else {
79  throw Exception("Unknown PTU type %s", type.c_str());
80  }
81 
82  ptus.insert(ptu);
83  thread_list.push_back(act_thread);
84  sensor_thread->add_act_thread(act_thread);
85  } else {
86  //printf("Ignoring PTU %s\n", ptu.c_str());
87  ignored_ptus.insert(ptu);
88  }
89  }
90  }
91  delete i;
92 
93  if (thread_list.empty()) {
94  throw Exception("No synchronization peers configured, aborting");
95  }
96  thread_list.push_back(sensor_thread);
97 }
98 
99 PLUGIN_DESCRIPTION("Use pan/tilt units with Fawkes.")
100 EXPORT_PLUGIN(PanTiltPlugin)
PanTiltRX28Thread
Definition: rx28_thread.h:50
fawkes::Plugin::config
Configuration * config
Fawkes configuration.
Definition: plugin.h:64
PanTiltSonyEviD100PThread
Definition: evid100p_thread.h:44
PanTiltPlugin
Definition: pantilt_plugin.h:28
fawkes::Plugin::thread_list
ThreadList thread_list
Thread list member.
Definition: plugin.h:59
fawkes::ThreadList::push_back
void push_back(Thread *thread)
Add thread to the end.
Definition: thread_list.cpp:779
fawkes::Configuration::get_bool
virtual bool get_bool(const char *path)=0
PanTiltSensorThread
Definition: sensor_thread.h:37
PanTiltSensorThread::add_act_thread
void add_act_thread(PanTiltActThread *act_thread)
Add an act thread.
Definition: sensor_thread.cpp:47
PanTiltPlugin::PanTiltPlugin
PanTiltPlugin(fawkes::Configuration *config)
Constructor.
Definition: pantilt_plugin.cpp:43
fawkes::Configuration::ValueIterator
Definition: config.h:77
fawkes::Configuration
Definition: config.h:70
fawkes::Configuration::search
virtual ValueIterator * search(const char *path)=0
PanTiltActThread
Definition: act_thread.h:36
fawkes
PanTiltDirectedPerceptionThread
Definition: dp_thread.h:43
fawkes::Configuration::get_string
virtual std::string get_string(const char *path)=0
fawkes::Configuration::ValueIterator::path
virtual const char * path() const =0
fawkes::Configuration::ValueIterator::next
virtual bool next()=0
fawkes::Plugin
Definition: plugin.h:39
fawkes::Exception
Definition: exception.h:41