Fawkes API  Fawkes Development Version
LaserClusterInterface.cpp
1 
2 /***************************************************************************
3  * LaserClusterInterface.cpp - Fawkes BlackBoard Interface - LaserClusterInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2013 Tim Niemueller
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 <interfaces/LaserClusterInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <map>
29 #include <string>
30 #include <cstring>
31 #include <cstdlib>
32 
33 namespace fawkes {
34 
35 /** @class LaserClusterInterface <interfaces/LaserClusterInterface.h>
36  * LaserClusterInterface Fawkes BlackBoard Interface.
37  * Laser cluster parameterization.
38  * @ingroup FawkesInterfaces
39  */
40 
41 
42 
43 /** Constructor */
44 LaserClusterInterface::LaserClusterInterface() : Interface()
45 {
46  data_size = sizeof(LaserClusterInterface_data_t);
47  data_ptr = malloc(data_size);
48  data = (LaserClusterInterface_data_t *)data_ptr;
49  data_ts = (interface_data_ts_t *)data_ptr;
50  memset(data_ptr, 0, data_size);
51  enum_map_SelectionMode[(int)SELMODE_MIN_ANGLE] = "SELMODE_MIN_ANGLE";
52  enum_map_SelectionMode[(int)SELMODE_MIN_DIST] = "SELMODE_MIN_DIST";
53  add_fieldinfo(IFT_FLOAT, "max_x", 1, &data->max_x);
54  add_fieldinfo(IFT_ENUM, "selection_mode", 1, &data->selection_mode, "SelectionMode", &enum_map_SelectionMode);
55  add_messageinfo("SetMaxXMessage");
56  add_messageinfo("SetSelectionModeMessage");
57  unsigned char tmp_hash[] = {0xad, 0xf8, 0x6e, 0xe7, 0x17, 0x56, 0x8a, 0xfb, 0xf9, 0xad, 0x3e, 0xba, 0xd, 0x15, 0xce, 0xde};
58  set_hash(tmp_hash);
59 }
60 
61 /** Destructor */
62 LaserClusterInterface::~LaserClusterInterface()
63 {
64  free(data_ptr);
65 }
66 /** Convert SelectionMode constant to string.
67  * @param value value to convert to string
68  * @return constant value as string.
69  */
70 const char *
71 LaserClusterInterface::tostring_SelectionMode(SelectionMode value) const
72 {
73  switch (value) {
74  case SELMODE_MIN_ANGLE: return "SELMODE_MIN_ANGLE";
75  case SELMODE_MIN_DIST: return "SELMODE_MIN_DIST";
76  default: return "UNKNOWN";
77  }
78 }
79 /* Methods */
80 /** Get max_x value.
81  * Maximum distance in X coordinate
82  of sensor frame.
83  * @return max_x value
84  */
85 float
86 LaserClusterInterface::max_x() const
87 {
88  return data->max_x;
89 }
90 
91 /** Get maximum length of max_x value.
92  * @return length of max_x value, can be length of the array or number of
93  * maximum number of characters for a string
94  */
95 size_t
96 LaserClusterInterface::maxlenof_max_x() const
97 {
98  return 1;
99 }
100 
101 /** Set max_x value.
102  * Maximum distance in X coordinate
103  of sensor frame.
104  * @param new_max_x new max_x value
105  */
106 void
107 LaserClusterInterface::set_max_x(const float new_max_x)
108 {
109  data->max_x = new_max_x;
110  data_changed = true;
111 }
112 
113 /** Get selection_mode value.
114  *
115  Current cluster selection mode.
116 
117  * @return selection_mode value
118  */
120 LaserClusterInterface::selection_mode() const
121 {
122  return (LaserClusterInterface::SelectionMode)data->selection_mode;
123 }
124 
125 /** Get maximum length of selection_mode value.
126  * @return length of selection_mode value, can be length of the array or number of
127  * maximum number of characters for a string
128  */
129 size_t
130 LaserClusterInterface::maxlenof_selection_mode() const
131 {
132  return 1;
133 }
134 
135 /** Set selection_mode value.
136  *
137  Current cluster selection mode.
138 
139  * @param new_selection_mode new selection_mode value
140  */
141 void
142 LaserClusterInterface::set_selection_mode(const SelectionMode new_selection_mode)
143 {
144  data->selection_mode = new_selection_mode;
145  data_changed = true;
146 }
147 
148 /* =========== message create =========== */
149 Message *
150 LaserClusterInterface::create_message(const char *type) const
151 {
152  if ( strncmp("SetMaxXMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
153  return new SetMaxXMessage();
154  } else if ( strncmp("SetSelectionModeMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
155  return new SetSelectionModeMessage();
156  } else {
157  throw UnknownTypeException("The given type '%s' does not match any known "
158  "message type for this interface type.", type);
159  }
160 }
161 
162 
163 /** Copy values from other interface.
164  * @param other other interface to copy values from
165  */
166 void
167 LaserClusterInterface::copy_values(const Interface *other)
168 {
169  const LaserClusterInterface *oi = dynamic_cast<const LaserClusterInterface *>(other);
170  if (oi == NULL) {
171  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
172  type(), other->type());
173  }
174  memcpy(data, oi->data, sizeof(LaserClusterInterface_data_t));
175 }
176 
177 const char *
178 LaserClusterInterface::enum_tostring(const char *enumtype, int val) const
179 {
180  if (strcmp(enumtype, "SelectionMode") == 0) {
181  return tostring_SelectionMode((SelectionMode)val);
182  }
183  throw UnknownTypeException("Unknown enum type %s", enumtype);
184 }
185 
186 /* =========== messages =========== */
187 /** @class LaserClusterInterface::SetMaxXMessage <interfaces/LaserClusterInterface.h>
188  * SetMaxXMessage Fawkes BlackBoard Interface Message.
189  *
190 
191  */
192 
193 
194 /** Constructor with initial values.
195  * @param ini_max_x initial value for max_x
196  */
197 LaserClusterInterface::SetMaxXMessage::SetMaxXMessage(const float ini_max_x) : Message("SetMaxXMessage")
198 {
199  data_size = sizeof(SetMaxXMessage_data_t);
200  data_ptr = malloc(data_size);
201  memset(data_ptr, 0, data_size);
202  data = (SetMaxXMessage_data_t *)data_ptr;
204  data->max_x = ini_max_x;
205  enum_map_SelectionMode[(int)SELMODE_MIN_ANGLE] = "SELMODE_MIN_ANGLE";
206  enum_map_SelectionMode[(int)SELMODE_MIN_DIST] = "SELMODE_MIN_DIST";
207  add_fieldinfo(IFT_FLOAT, "max_x", 1, &data->max_x);
208 }
209 /** Constructor */
211 {
212  data_size = sizeof(SetMaxXMessage_data_t);
213  data_ptr = malloc(data_size);
214  memset(data_ptr, 0, data_size);
215  data = (SetMaxXMessage_data_t *)data_ptr;
217  enum_map_SelectionMode[(int)SELMODE_MIN_ANGLE] = "SELMODE_MIN_ANGLE";
218  enum_map_SelectionMode[(int)SELMODE_MIN_DIST] = "SELMODE_MIN_DIST";
219  add_fieldinfo(IFT_FLOAT, "max_x", 1, &data->max_x);
220 }
221 
222 /** Destructor */
224 {
225  free(data_ptr);
226 }
227 
228 /** Copy constructor.
229  * @param m message to copy from
230  */
232 {
233  data_size = m->data_size;
234  data_ptr = malloc(data_size);
235  memcpy(data_ptr, m->data_ptr, data_size);
236  data = (SetMaxXMessage_data_t *)data_ptr;
238 }
239 
240 /* Methods */
241 /** Get max_x value.
242  * Maximum distance in X coordinate
243  of sensor frame.
244  * @return max_x value
245  */
246 float
248 {
249  return data->max_x;
250 }
251 
252 /** Get maximum length of max_x value.
253  * @return length of max_x value, can be length of the array or number of
254  * maximum number of characters for a string
255  */
256 size_t
258 {
259  return 1;
260 }
261 
262 /** Set max_x value.
263  * Maximum distance in X coordinate
264  of sensor frame.
265  * @param new_max_x new max_x value
266  */
267 void
269 {
270  data->max_x = new_max_x;
271 }
272 
273 /** Clone this message.
274  * Produces a message of the same type as this message and copies the
275  * data to the new message.
276  * @return clone of this message
277  */
278 Message *
280 {
281  return new LaserClusterInterface::SetMaxXMessage(this);
282 }
283 /** @class LaserClusterInterface::SetSelectionModeMessage <interfaces/LaserClusterInterface.h>
284  * SetSelectionModeMessage Fawkes BlackBoard Interface Message.
285  *
286 
287  */
288 
289 
290 /** Constructor with initial values.
291  * @param ini_selection_mode initial value for selection_mode
292  */
294 {
295  data_size = sizeof(SetSelectionModeMessage_data_t);
296  data_ptr = malloc(data_size);
297  memset(data_ptr, 0, data_size);
298  data = (SetSelectionModeMessage_data_t *)data_ptr;
300  data->selection_mode = ini_selection_mode;
301  enum_map_SelectionMode[(int)SELMODE_MIN_ANGLE] = "SELMODE_MIN_ANGLE";
302  enum_map_SelectionMode[(int)SELMODE_MIN_DIST] = "SELMODE_MIN_DIST";
303  add_fieldinfo(IFT_ENUM, "selection_mode", 1, &data->selection_mode, "SelectionMode", &enum_map_SelectionMode);
304 }
305 /** Constructor */
307 {
308  data_size = sizeof(SetSelectionModeMessage_data_t);
309  data_ptr = malloc(data_size);
310  memset(data_ptr, 0, data_size);
311  data = (SetSelectionModeMessage_data_t *)data_ptr;
313  enum_map_SelectionMode[(int)SELMODE_MIN_ANGLE] = "SELMODE_MIN_ANGLE";
314  enum_map_SelectionMode[(int)SELMODE_MIN_DIST] = "SELMODE_MIN_DIST";
315  add_fieldinfo(IFT_ENUM, "selection_mode", 1, &data->selection_mode, "SelectionMode", &enum_map_SelectionMode);
316 }
317 
318 /** Destructor */
320 {
321  free(data_ptr);
322 }
323 
324 /** Copy constructor.
325  * @param m message to copy from
326  */
328 {
329  data_size = m->data_size;
330  data_ptr = malloc(data_size);
331  memcpy(data_ptr, m->data_ptr, data_size);
332  data = (SetSelectionModeMessage_data_t *)data_ptr;
334 }
335 
336 /* Methods */
337 /** Get selection_mode value.
338  *
339  Current cluster selection mode.
340 
341  * @return selection_mode value
342  */
345 {
346  return (LaserClusterInterface::SelectionMode)data->selection_mode;
347 }
348 
349 /** Get maximum length of selection_mode value.
350  * @return length of selection_mode value, can be length of the array or number of
351  * maximum number of characters for a string
352  */
353 size_t
355 {
356  return 1;
357 }
358 
359 /** Set selection_mode value.
360  *
361  Current cluster selection mode.
362 
363  * @param new_selection_mode new selection_mode value
364  */
365 void
367 {
368  data->selection_mode = new_selection_mode;
369 }
370 
371 /** Clone this message.
372  * Produces a message of the same type as this message and copies the
373  * data to the new message.
374  * @return clone of this message
375  */
376 Message *
378 {
380 }
381 /** Check if message is valid and can be enqueued.
382  * @param message Message to check
383  * @return true if the message is valid, false otherwise.
384  */
385 bool
387 {
388  const SetMaxXMessage *m0 = dynamic_cast<const SetMaxXMessage *>(message);
389  if ( m0 != NULL ) {
390  return true;
391  }
392  const SetSelectionModeMessage *m1 = dynamic_cast<const SetSelectionModeMessage *>(message);
393  if ( m1 != NULL ) {
394  return true;
395  }
396  return false;
397 }
398 
399 /// @cond INTERNALS
400 EXPORT_INTERFACE(LaserClusterInterface)
401 /// @endcond
402 
403 
404 } // end namespace fawkes
void set_selection_mode(const SelectionMode new_selection_mode)
Set selection_mode value.
virtual Message * clone() const
Clone this message.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:124
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Choose the cluster with the minimum angle difference from 0 degrees.
LaserClusterInterface Fawkes BlackBoard Interface.
Fawkes library namespace.
SetSelectionModeMessage Fawkes BlackBoard Interface Message.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:129
SetMaxXMessage Fawkes BlackBoard Interface Message.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Choose the cluster with the minimum distance in X direction of the reference frame (typically forward...
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:133
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:125
const char * type() const
Get type of interface.
Definition: interface.cpp:651
SelectionMode selection_mode() const
Get selection_mode value.
virtual Message * clone() const
Clone this message.
size_t maxlenof_max_x() const
Get maximum length of max_x value.
void set_max_x(const float new_max_x)
Set max_x value.
float field
Definition: types.h:45
size_t maxlenof_selection_mode() const
Get maximum length of selection_mode value.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition: message.cpp:436
field with interface specific enum type
Definition: types.h:49
SelectionMode
Enumeration defining the possible cluster selection modes.