Fawkes API  Fawkes Development Version
pantilt_plugin.cpp
00001 
00002 /***************************************************************************
00003  *  pantilt_plugin.cpp - Plugin to drive pan/tilt units (e.g. for cameras)
00004  *
00005  *  Created: Wed Jun 17 19:27:08 2009
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
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 /** @class PanTiltPlugin "pantilt_plugin.h"
00034  * Plugin to drive pan/tilt units with Fawkes.
00035  * This plugin integrates a number of known pan/tilt units.
00036  * @author Tim Niemueller
00037  */
00038 
00039 /** Constructor.
00040  * @param config Fawkes configuration
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) {} // ignored, assume enabled
00067 
00068       if (active) {
00069         //printf("Adding sync thread for peer %s\n", peer.c_str());
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         //printf("Ignoring PTU %s\n", ptu.c_str());
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)