pantilt_plugin.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "pantilt_plugin.h"
00024 #include "robotis/rx28_thread.h"
00025 #include "sony/evid100p_thread.h"
00026 #include "dirperc/dp_thread.h"
00027 #include "sensor_thread.h"
00028
00029 #include <set>
00030
00031 using namespace fawkes;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 PanTiltPlugin::PanTiltPlugin(Configuration *config)
00043 : Plugin(config)
00044 {
00045 std::set<std::string> ptus;
00046 std::set<std::string> ignored_ptus;
00047
00048 std::string prefix = "/hardware/pantilt/";
00049 std::string ptus_prefix = prefix + "ptus/";
00050
00051 PanTiltSensorThread *sensor_thread = new PanTiltSensorThread();
00052
00053 Configuration::ValueIterator *i = config->search(ptus_prefix.c_str());
00054 while (i->next()) {
00055 std::string ptu = std::string(i->path()).substr(ptus_prefix.length());
00056 ptu = ptu.substr(0, ptu.find("/"));
00057
00058 if ( (ptus.find(ptu) == ptus.end()) &&
00059 (ignored_ptus.find(ptu) == ignored_ptus.end()) ) {
00060
00061 std::string ptu_prefix = ptus_prefix + ptu + "/";
00062
00063 bool active = true;
00064 try {
00065 active = config->get_bool((ptu_prefix + "active").c_str());
00066 } catch (Exception &e) {}
00067
00068 if (active) {
00069
00070 std::string type = config->get_string((ptu_prefix + "type").c_str());
00071 PanTiltActThread *act_thread;
00072
00073 if (type == "RX28") {
00074 act_thread = new PanTiltRX28Thread(prefix, ptu_prefix, ptu);
00075 } else if (type == "EviD100P") {
00076 act_thread = new PanTiltSonyEviD100PThread(prefix, ptu_prefix, ptu);
00077 } else if (type == "DirPercASCII") {
00078 act_thread = new PanTiltDirectedPerceptionThread(prefix, ptu_prefix, ptu);
00079 } else {
00080 throw Exception("Unknown PTU type %s", type.c_str());
00081 }
00082
00083 ptus.insert(ptu);
00084 thread_list.push_back(act_thread);
00085 sensor_thread->add_act_thread(act_thread);
00086 } else {
00087
00088 ignored_ptus.insert(ptu);
00089 }
00090 }
00091 }
00092 delete i;
00093
00094 if ( thread_list.empty() ) {
00095 throw Exception("No synchronization peers configured, aborting");
00096 } else {
00097 }
00098 thread_list.push_back(sensor_thread);
00099 }
00100
00101
00102 PLUGIN_DESCRIPTION("Use pan/tilt units with Fawkes.")
00103 EXPORT_PLUGIN(PanTiltPlugin)