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 #include "robotis/rx28_thread.h"
25 #include "sony/evid100p_thread.h"
26 #include "dirperc/dp_thread.h"
27 #include "sensor_thread.h"
28 
29 #include <set>
30 
31 using namespace fawkes;
32 
33 /** @class PanTiltPlugin "pantilt_plugin.h"
34  * Plugin to drive pan/tilt units with Fawkes.
35  * This plugin integrates a number of known pan/tilt units.
36  * @author Tim Niemueller
37  */
38 
39 /** Constructor.
40  * @param config Fawkes configuration
41  */
43  : Plugin(config)
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()) &&
59  (ignored_ptus.find(ptu) == ignored_ptus.end()) ) {
60 
61  std::string ptu_prefix = ptus_prefix + ptu + "/";
62 
63  bool active = true;
64  try {
65  active = config->get_bool((ptu_prefix + "active").c_str());
66  } catch (Exception &e) {} // ignored, assume enabled
67 
68  if (active) {
69  //printf("Adding sync thread for peer %s\n", peer.c_str());
70  std::string type = config->get_string((ptu_prefix + "type").c_str());
71  PanTiltActThread *act_thread;
72 
73  if (type == "RX28") {
74  act_thread = new PanTiltRX28Thread(prefix, ptu_prefix, ptu);
75  } else if (type == "EviD100P") {
76  act_thread = new PanTiltSonyEviD100PThread(prefix, ptu_prefix, ptu);
77  } else if (type == "DirPercASCII") {
78  act_thread = new PanTiltDirectedPerceptionThread(prefix, ptu_prefix, ptu);
79  } else {
80  throw Exception("Unknown PTU type %s", type.c_str());
81  }
82 
83  ptus.insert(ptu);
84  thread_list.push_back(act_thread);
85  sensor_thread->add_act_thread(act_thread);
86  } else {
87  //printf("Ignoring PTU %s\n", ptu.c_str());
88  ignored_ptus.insert(ptu);
89  }
90  }
91  }
92  delete i;
93 
94  if ( thread_list.empty() ) {
95  throw Exception("No synchronization peers configured, aborting");
96  } else {
97  }
98  thread_list.push_back(sensor_thread);
99 }
100 
101 
102 PLUGIN_DESCRIPTION("Use pan/tilt units with Fawkes.")
103 EXPORT_PLUGIN(PanTiltPlugin)
Plugin interface class.
Definition: plugin.h:33
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual bool next()=0
Check if there is another element and advance to this if possible.
Plugin to drive pan/tilt units with Fawkes.
PanTilt act thread for PTUs from DirectedPerception employing the ASCII protocol. ...
Definition: dp_thread.h:43
PanTiltPlugin(fawkes::Configuration *config)
Constructor.
Base class for exceptions in Fawkes.
Definition: exception.h:36
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
PanTilt act thread for RX28 PTU.
Definition: rx28_thread.h:50
void add_act_thread(PanTiltActThread *act_thread)
Add an act thread.
virtual const char * path() const =0
Path of value.
Pan/tilt act thread.
Definition: act_thread.h:36
void push_back(Thread *thread)
Add thread to the end.
Iterator interface to iterate over config values.
Definition: config.h:72
Interface for configuration handling.
Definition: config.h:67
PanTilt act thread for the PTU part of the Sony EviD100P camera.
Katana sensor thread.
Definition: sensor_thread.h:37
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.