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
32using 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
99PLUGIN_DESCRIPTION("Use pan/tilt units with Fawkes.")
100EXPORT_PLUGIN(PanTiltPlugin)
Pan/tilt act thread.
Definition: act_thread.h:41
PanTilt act thread for PTUs from DirectedPerception employing the ASCII protocol.
Definition: dp_thread.h:45
Plugin to drive pan/tilt units with Fawkes.
PanTiltPlugin(fawkes::Configuration *config)
Constructor.
PanTilt act thread for RX28 PTU.
Definition: rx28_thread.h:55
Katana sensor thread.
Definition: sensor_thread.h:41
void add_act_thread(PanTiltActThread *act_thread)
Add an act thread.
PanTilt act thread for the PTU part of the Sony EviD100P camera.
Iterator interface to iterate over config values.
Definition: config.h:75
virtual const char * path() const =0
Path of value.
virtual bool next()=0
Check if there is another element and advance to this if possible.
Interface for configuration handling.
Definition: config.h:68
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 std::string get_string(const char *path)=0
Get value from configuration which is of type string.
Base class for exceptions in Fawkes.
Definition: exception.h:36
Plugin interface class.
Definition: plugin.h:34
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
Configuration * config
Fawkes configuration.
Definition: plugin.h:58
void push_back(Thread *thread)
Add thread to the end.
Fawkes library namespace.