Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * tf.cpp - Transform aspect for Fawkes 00004 * 00005 * Created: Tue Oct 25 21:35:14 2011 00006 * Copyright 2006-2011 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. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <aspect/tf.h> 00025 00026 #include <cstring> 00027 #include <cstdlib> 00028 #include <core/threading/thread_initializer.h> 00029 00030 namespace fawkes { 00031 #if 0 /* just to make Emacs auto-indent happy */ 00032 } 00033 #endif 00034 00035 /** @class TransformAspect <aspect/tf.h> 00036 * Thread aspect to access the transform system. 00037 00038 * Give this aspect to your thread to gain access to the transform 00039 * library. Depending on the parameters to the ctor only the listener 00040 * or additionaly the publisher is created. 00041 * It is guaranteed that if used properly from within plugins that the 00042 * blackboard member has been initialized properly. 00043 * @ingroup Aspects 00044 * @author Tim Niemueller 00045 */ 00046 00047 00048 /** @var tf::TransformListener * TransformAspect::tf_listener 00049 * This is the transform listener which saves transforms published by 00050 * other threads in the system. 00051 */ 00052 00053 /** @var tf::TransformPublisher * TransformAspect::tf_publisher 00054 * This is the transform publisher which can be used to publish 00055 * transforms via the blackboard. It is only created if the constructor 00056 * taking the blackboard interface ID parameter is used! 00057 */ 00058 00059 /** Constructor. 00060 * @param mode mode of operation 00061 * @param tf_bb_iface_id interface ID to be used for the transform 00062 * publisher. Note that this will be prefixed with "TF ". 00063 */ 00064 TransformAspect::TransformAspect(Mode mode, const char *tf_bb_iface_id) 00065 : __tf_aspect_mode(mode) 00066 { 00067 add_aspect("TransformAspect"); 00068 if (((mode == ONLY_PUBLISHER) || (mode == BOTH)) && tf_bb_iface_id) { 00069 __tf_aspect_bb_iface_id = strdup(tf_bb_iface_id); 00070 } else { 00071 __tf_aspect_bb_iface_id = 0; 00072 } 00073 } 00074 00075 00076 /** Virtual empty destructor. */ 00077 TransformAspect::~TransformAspect() 00078 { 00079 if (__tf_aspect_bb_iface_id) free(__tf_aspect_bb_iface_id); 00080 } 00081 00082 00083 /** Init transform aspect. 00084 * This creates the listener and potentially publisher. 00085 * @param blackboard blackboard used to create listener and/or publisher. 00086 */ 00087 void 00088 TransformAspect::init_TransformAspect(BlackBoard *blackboard) 00089 { 00090 if (((__tf_aspect_mode == ONLY_PUBLISHER) || (__tf_aspect_mode == BOTH)) && 00091 (__tf_aspect_bb_iface_id == NULL)) 00092 { 00093 throw CannotInitializeThreadException("TransformAspect was initialized " 00094 "in mode %s but BB interface ID" 00095 "is not set", 00096 (__tf_aspect_mode == BOTH) ? "BOTH" 00097 : "ONLY_PUBLISHER"); 00098 } 00099 00100 if ((__tf_aspect_mode == ONLY_LISTENER) || (__tf_aspect_mode == BOTH)) { 00101 tf_listener = new tf::TransformListener(blackboard); 00102 } else { 00103 tf_listener = new tf::TransformListener(NULL); 00104 } 00105 00106 if ((__tf_aspect_mode == ONLY_PUBLISHER) || (__tf_aspect_mode == BOTH)) { 00107 tf_publisher = 00108 new tf::TransformPublisher(blackboard, __tf_aspect_bb_iface_id); 00109 } else { 00110 tf_publisher = new tf::TransformPublisher(NULL, NULL); 00111 } 00112 } 00113 00114 /** Finalize transform aspect. 00115 * This deletes the transform listener and publisher. 00116 */ 00117 void 00118 TransformAspect::finalize_TransformAspect() 00119 { 00120 delete tf_listener; 00121 delete tf_publisher; 00122 tf_listener = 0; 00123 tf_publisher = 0; 00124 } 00125 00126 } // end namespace fawkes