Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
LocalizerControlInterface.cpp
1
2
/***************************************************************************
3
* LocalizerControlInterface.cpp - Fawkes BlackBoard Interface - LocalizerControlInterface
4
*
5
* Templated created: Thu Oct 12 10:49:19 2006
6
* Copyright 2009 Daniel Beck
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/LocalizerControlInterface.h>
25
26
#include <core/exceptions/software.h>
27
28
#include <cstring>
29
#include <cstdlib>
30
31
namespace
fawkes {
32
33
/** @class LocalizerControlInterface <interfaces/LocalizerControlInterface.h>
34
* LocalizerControlInterface Fawkes BlackBoard Interface.
35
*
36
This interface allows observe the current status of the a
37
localizer as well as sending it commands (eg., reset,
38
re-position, etc.)
39
40
* @ingroup FawkesInterfaces
41
*/
42
43
44
45
/** Constructor */
46
LocalizerControlInterface::LocalizerControlInterface() : Interface()
47
{
48
data_size
=
sizeof
(LocalizerControlInterface_data_t);
49
data_ptr
= malloc(
data_size
);
50
data = (LocalizerControlInterface_data_t *)
data_ptr
;
51
data_ts
= (interface_data_ts_t *)
data_ptr
;
52
memset(
data_ptr
, 0,
data_size
);
53
add_fieldinfo
(
IFT_STRING
,
"map_name"
, 30, data->map_name);
54
add_messageinfo
(
"ResetMessage"
);
55
unsigned
char
tmp_hash[] = {0xa4, 0xe8, 0x69, 0x11, 0x29, 0x30, 0xf2, 0xcb, 0xe5, 0xf4, 00, 0x35, 0x19, 0x58, 0x54, 0xfb};
56
set_hash
(tmp_hash);
57
}
58
59
/** Destructor */
60
LocalizerControlInterface::~LocalizerControlInterface()
61
{
62
free(
data_ptr
);
63
}
64
/* Methods */
65
/** Get map_name value.
66
* The name of the current
67
map
68
* @return map_name value
69
*/
70
char
*
71
LocalizerControlInterface::map_name
()
const
72
{
73
return
data->map_name;
74
}
75
76
/** Get maximum length of map_name value.
77
* @return length of map_name value, can be length of the array or number of
78
* maximum number of characters for a string
79
*/
80
size_t
81
LocalizerControlInterface::maxlenof_map_name
()
const
82
{
83
return
30;
84
}
85
86
/** Set map_name value.
87
* The name of the current
88
map
89
* @param new_map_name new map_name value
90
*/
91
void
92
LocalizerControlInterface::set_map_name
(
const
char
* new_map_name)
93
{
94
strncpy(data->map_name, new_map_name,
sizeof
(data->map_name));
95
data_changed
=
true
;
96
}
97
98
/* =========== message create =========== */
99
Message
*
100
LocalizerControlInterface::create_message
(
const
char
*
type
)
const
101
{
102
if
( strncmp(
"ResetMessage"
, type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
103
return
new
ResetMessage
();
104
}
else
{
105
throw
UnknownTypeException
(
"The given type '%s' does not match any known "
106
"message type for this interface type."
, type);
107
}
108
}
109
110
111
/** Copy values from other interface.
112
* @param other other interface to copy values from
113
*/
114
void
115
LocalizerControlInterface::copy_values
(
const
Interface
*other)
116
{
117
const
LocalizerControlInterface
*oi =
dynamic_cast<
const
LocalizerControlInterface
*
>
(other);
118
if
(oi == NULL) {
119
throw
TypeMismatchException
(
"Can only copy values from interface of same type (%s vs. %s)"
,
120
type
(), other->
type
());
121
}
122
memcpy(data, oi->data,
sizeof
(LocalizerControlInterface_data_t));
123
}
124
125
const
char
*
126
LocalizerControlInterface::enum_tostring
(
const
char
*enumtype,
int
val)
const
127
{
128
throw
UnknownTypeException
(
"Unknown enum type %s"
, enumtype);
129
}
130
131
/* =========== messages =========== */
132
/** @class LocalizerControlInterface::ResetMessage <interfaces/LocalizerControlInterface.h>
133
* ResetMessage Fawkes BlackBoard Interface Message.
134
*
135
136
*/
137
138
139
/** Constructor with initial values.
140
* @param ini_x initial value for x
141
* @param ini_y initial value for y
142
* @param ini_ori initial value for ori
143
* @param ini_variance initial value for variance
144
*/
145
LocalizerControlInterface::ResetMessage::ResetMessage
(
const
float
ini_x,
const
float
ini_y,
const
float
ini_ori,
const
float
ini_variance) :
Message
(
"ResetMessage"
)
146
{
147
data_size
=
sizeof
(ResetMessage_data_t);
148
data_ptr
= malloc(
data_size
);
149
memset(
data_ptr
, 0,
data_size
);
150
data = (ResetMessage_data_t *)
data_ptr
;
151
data_ts
= (
message_data_ts_t
*)
data_ptr
;
152
data->x = ini_x;
153
data->y = ini_y;
154
data->ori = ini_ori;
155
data->variance = ini_variance;
156
add_fieldinfo
(
IFT_FLOAT
,
"x"
, 1, &data->x);
157
add_fieldinfo
(
IFT_FLOAT
,
"y"
, 1, &data->y);
158
add_fieldinfo
(
IFT_FLOAT
,
"ori"
, 1, &data->ori);
159
add_fieldinfo
(
IFT_FLOAT
,
"variance"
, 1, &data->variance);
160
}
161
/** Constructor */
162
LocalizerControlInterface::ResetMessage::ResetMessage
() :
Message
(
"ResetMessage"
)
163
{
164
data_size
=
sizeof
(ResetMessage_data_t);
165
data_ptr
= malloc(
data_size
);
166
memset(
data_ptr
, 0,
data_size
);
167
data = (ResetMessage_data_t *)
data_ptr
;
168
data_ts
= (
message_data_ts_t
*)
data_ptr
;
169
add_fieldinfo
(
IFT_FLOAT
,
"x"
, 1, &data->x);
170
add_fieldinfo
(
IFT_FLOAT
,
"y"
, 1, &data->y);
171
add_fieldinfo
(
IFT_FLOAT
,
"ori"
, 1, &data->ori);
172
add_fieldinfo
(
IFT_FLOAT
,
"variance"
, 1, &data->variance);
173
}
174
175
/** Destructor */
176
LocalizerControlInterface::ResetMessage::~ResetMessage
()
177
{
178
free(
data_ptr
);
179
}
180
181
/** Copy constructor.
182
* @param m message to copy from
183
*/
184
LocalizerControlInterface::ResetMessage::ResetMessage
(
const
ResetMessage
*m) :
Message
(
"ResetMessage"
)
185
{
186
data_size
= m->
data_size
;
187
data_ptr
= malloc(
data_size
);
188
memcpy(
data_ptr
, m->
data_ptr
,
data_size
);
189
data = (ResetMessage_data_t *)
data_ptr
;
190
data_ts
= (
message_data_ts_t
*)
data_ptr
;
191
}
192
193
/* Methods */
194
/** Get x value.
195
* The new initial x-coordinate.
196
* @return x value
197
*/
198
float
199
LocalizerControlInterface::ResetMessage::x
()
const
200
{
201
return
data->x;
202
}
203
204
/** Get maximum length of x value.
205
* @return length of x value, can be length of the array or number of
206
* maximum number of characters for a string
207
*/
208
size_t
209
LocalizerControlInterface::ResetMessage::maxlenof_x
()
const
210
{
211
return
1;
212
}
213
214
/** Set x value.
215
* The new initial x-coordinate.
216
* @param new_x new x value
217
*/
218
void
219
LocalizerControlInterface::ResetMessage::set_x
(
const
float
new_x)
220
{
221
data->x = new_x;
222
}
223
224
/** Get y value.
225
* The new initial x-coordinate.
226
* @return y value
227
*/
228
float
229
LocalizerControlInterface::ResetMessage::y
()
const
230
{
231
return
data->y;
232
}
233
234
/** Get maximum length of y value.
235
* @return length of y value, can be length of the array or number of
236
* maximum number of characters for a string
237
*/
238
size_t
239
LocalizerControlInterface::ResetMessage::maxlenof_y
()
const
240
{
241
return
1;
242
}
243
244
/** Set y value.
245
* The new initial x-coordinate.
246
* @param new_y new y value
247
*/
248
void
249
LocalizerControlInterface::ResetMessage::set_y
(
const
float
new_y)
250
{
251
data->y = new_y;
252
}
253
254
/** Get ori value.
255
* The new initial orientation.
256
* @return ori value
257
*/
258
float
259
LocalizerControlInterface::ResetMessage::ori
()
const
260
{
261
return
data->ori;
262
}
263
264
/** Get maximum length of ori value.
265
* @return length of ori value, can be length of the array or number of
266
* maximum number of characters for a string
267
*/
268
size_t
269
LocalizerControlInterface::ResetMessage::maxlenof_ori
()
const
270
{
271
return
1;
272
}
273
274
/** Set ori value.
275
* The new initial orientation.
276
* @param new_ori new ori value
277
*/
278
void
279
LocalizerControlInterface::ResetMessage::set_ori
(
const
float
new_ori)
280
{
281
data->ori = new_ori;
282
}
283
284
/** Get variance value.
285
* The variance for the reset position.
286
* @return variance value
287
*/
288
float
289
LocalizerControlInterface::ResetMessage::variance
()
const
290
{
291
return
data->variance;
292
}
293
294
/** Get maximum length of variance value.
295
* @return length of variance value, can be length of the array or number of
296
* maximum number of characters for a string
297
*/
298
size_t
299
LocalizerControlInterface::ResetMessage::maxlenof_variance
()
const
300
{
301
return
1;
302
}
303
304
/** Set variance value.
305
* The variance for the reset position.
306
* @param new_variance new variance value
307
*/
308
void
309
LocalizerControlInterface::ResetMessage::set_variance
(
const
float
new_variance)
310
{
311
data->variance = new_variance;
312
}
313
314
/** Clone this message.
315
* Produces a message of the same type as this message and copies the
316
* data to the new message.
317
* @return clone of this message
318
*/
319
Message
*
320
LocalizerControlInterface::ResetMessage::clone
()
const
321
{
322
return
new
LocalizerControlInterface::ResetMessage
(
this
);
323
}
324
/** Check if message is valid and can be enqueued.
325
* @param message Message to check
326
* @return true if the message is valid, false otherwise.
327
*/
328
bool
329
LocalizerControlInterface::message_valid
(
const
Message
*message)
const
330
{
331
const
ResetMessage
*m0 =
dynamic_cast<
const
ResetMessage
*
>
(message);
332
if
( m0 != NULL ) {
333
return
true
;
334
}
335
return
false
;
336
}
337
338
/// @cond INTERNALS
339
EXPORT_INTERFACE(
LocalizerControlInterface
)
340
/// @endcond
341
342
343
}
// end namespace fawkes
src
libs
interfaces
LocalizerControlInterface.cpp
Generated by
1.8.3.1