Fawkes API  Fawkes Development Version
tf.cpp
1 
2 /***************************************************************************
3  * tf.cpp - Transform aspect for Fawkes
4  *
5  * Created: Tue Oct 25 21:35:14 2011
6  * Copyright 2006-2011 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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <aspect/tf.h>
25 
26 #include <cstring>
27 #include <cstdlib>
28 #include <core/threading/thread_initializer.h>
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class TransformAspect <aspect/tf.h>
36  * Thread aspect to access the transform system.
37 
38  * Give this aspect to your thread to gain access to the transform
39  * library. Depending on the parameters to the ctor only the listener
40  * or additionaly the publisher is created.
41  * It is guaranteed that if used properly from within plugins that the
42  * blackboard member has been initialized properly.
43  * @ingroup Aspects
44  * @author Tim Niemueller
45  */
46 
47 
48 /** @var tf::TransformListener * TransformAspect::tf_listener
49  * This is the transform listener which saves transforms published by
50  * other threads in the system.
51  */
52 
53 /** @var tf::TransformPublisher * TransformAspect::tf_publisher
54  * This is the transform publisher which can be used to publish
55  * transforms via the blackboard. It is only created if the constructor
56  * taking the blackboard interface ID parameter is used!
57  */
58 
59 /** Constructor.
60  * @param mode mode of operation
61  * @param tf_bb_iface_id interface ID to be used for the transform
62  * publisher. Note that this will be prefixed with "TF ".
63  */
64 TransformAspect::TransformAspect(Mode mode, const char *tf_bb_iface_id)
65  : __tf_aspect_mode(mode)
66 {
67  add_aspect("TransformAspect");
68  if (((mode == ONLY_PUBLISHER) || (mode == BOTH)) && tf_bb_iface_id) {
69  __tf_aspect_bb_iface_id = strdup(tf_bb_iface_id);
70  } else {
71  __tf_aspect_bb_iface_id = 0;
72  }
73 }
74 
75 
76 /** Virtual empty destructor. */
78 {
79  if (__tf_aspect_bb_iface_id) free(__tf_aspect_bb_iface_id);
80 }
81 
82 
83 /** Init transform aspect.
84  * This creates the listener and potentially publisher.
85  * @param blackboard blackboard used to create listener and/or publisher.
86  */
87 void
89 {
90  if (((__tf_aspect_mode == ONLY_PUBLISHER) || (__tf_aspect_mode == BOTH)) &&
91  (__tf_aspect_bb_iface_id == NULL))
92  {
93  throw CannotInitializeThreadException("TransformAspect was initialized "
94  "in mode %s but BB interface ID"
95  "is not set",
96  (__tf_aspect_mode == BOTH) ? "BOTH"
97  : "ONLY_PUBLISHER");
98  }
99 
100  if ((__tf_aspect_mode == ONLY_LISTENER) || (__tf_aspect_mode == BOTH)) {
101  tf_listener = new tf::TransformListener(blackboard);
102  } else {
104  }
105 
106  if ((__tf_aspect_mode == ONLY_PUBLISHER) || (__tf_aspect_mode == BOTH)) {
107  tf_publisher =
108  new tf::TransformPublisher(blackboard, __tf_aspect_bb_iface_id);
109  } else {
110  tf_publisher = new tf::TransformPublisher(NULL, NULL);
111  }
112 }
113 
114 /** Finalize transform aspect.
115  * This deletes the transform listener and publisher.
116  */
117 void
119 {
120  delete tf_listener;
121  delete tf_publisher;
122  tf_listener = 0;
123  tf_publisher = 0;
124 }
125 
126 } // end namespace fawkes
only create a transform publisher
Definition: tf.h:44
tf::TransformPublisher * tf_publisher
This is the transform publisher which can be used to publish transforms via the blackboard.
Definition: tf.h:56
Receive transforms and answer queries.
Fawkes library namespace.
void init_TransformAspect(BlackBoard *blackboard)
Init transform aspect.
Definition: tf.cpp:88
Mode
Enumeration describing the desired mode of operation.
Definition: tf.h:42
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:52
virtual ~TransformAspect()
Virtual empty destructor.
Definition: tf.cpp:77
only create a transform listener
Definition: tf.h:43
Thread cannot be initialized.
create both, transform listener and publisher
Definition: tf.h:45
Utility class to send transforms.
void finalize_TransformAspect()
Finalize transform aspect.
Definition: tf.cpp:118
The BlackBoard abstract class.
Definition: blackboard.h:49
tf::TransformListener * tf_listener
This is the transform listener which saves transforms published by other threads in the system...
Definition: tf.h:55