Fawkes API Fawkes Development Version
Laser360Interface.cpp
1
2/***************************************************************************
3 * Laser360Interface.cpp - Fawkes BlackBoard Interface - Laser360Interface
4 *
5 * Templated created: Thu Oct 12 10:49:19 2006
6 * Copyright 2008-2009 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/Laser360Interface.h>
25
26#include <core/exceptions/software.h>
27
28#include <map>
29#include <string>
30#include <cstring>
31#include <cstdlib>
32
33namespace fawkes {
34
35/** @class Laser360Interface <interfaces/Laser360Interface.h>
36 * Laser360Interface Fawkes BlackBoard Interface.
37 *
38 This interface provides access to data of a laser scanner that produces
39 360 beams per scan. The inter-beam distance is 1 deg, 0 deg is
40 "forward", i.e. in the Fawkes coordinate system pointing towards
41 the cartesian point (1,0). The direction in which the angle
42 grows is indicated by the clockwise_angle field.
43
44 * @ingroup FawkesInterfaces
45 */
46
47
48
49/** Constructor */
50Laser360Interface::Laser360Interface() : Interface()
51{
52 data_size = sizeof(Laser360Interface_data_t);
53 data_ptr = malloc(data_size);
54 data = (Laser360Interface_data_t *)data_ptr;
55 data_ts = (interface_data_ts_t *)data_ptr;
56 memset(data_ptr, 0, data_size);
57 add_fieldinfo(IFT_STRING, "frame", 32, data->frame);
58 add_fieldinfo(IFT_FLOAT, "distances", 360, &data->distances);
59 add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle);
60 unsigned char tmp_hash[] = {0x5c, 0x1, 0x85, 0x24, 0x85, 0x28, 0x1f, 0xc6, 0xae, 0x4c, 0x46, 0x66, 0xe9, 0xcb, 0xe9, 0x4e};
61 set_hash(tmp_hash);
62}
63
64/** Destructor */
65Laser360Interface::~Laser360Interface()
66{
67 free(data_ptr);
68}
69/* Methods */
70/** Get frame value.
71 *
72 Coordinate frame in which the data is presented.
73
74 * @return frame value
75 */
76char *
77Laser360Interface::frame() const
78{
79 return data->frame;
80}
81
82/** Get maximum length of frame value.
83 * @return length of frame value, can be length of the array or number of
84 * maximum number of characters for a string
85 */
86size_t
87Laser360Interface::maxlenof_frame() const
88{
89 return 32;
90}
91
92/** Set frame value.
93 *
94 Coordinate frame in which the data is presented.
95
96 * @param new_frame new frame value
97 */
98void
99Laser360Interface::set_frame(const char * new_frame)
100{
101 set_field(data->frame, new_frame);
102}
103
104/** Get distances value.
105 *
106 The distances in meter of the beams.
107
108 * @return distances value
109 */
110float *
111Laser360Interface::distances() const
112{
113 return data->distances;
114}
115
116/** Get distances value at given index.
117 *
118 The distances in meter of the beams.
119
120 * @param index index of value
121 * @return distances value
122 * @exception Exception thrown if index is out of bounds
123 */
124float
125Laser360Interface::distances(unsigned int index) const
126{
127 if (index > 359) {
128 throw Exception("Index value %u out of bounds (0..359)", index);
129 }
130 return data->distances[index];
131}
132
133/** Get maximum length of distances value.
134 * @return length of distances value, can be length of the array or number of
135 * maximum number of characters for a string
136 */
137size_t
138Laser360Interface::maxlenof_distances() const
139{
140 return 360;
141}
142
143/** Set distances value.
144 *
145 The distances in meter of the beams.
146
147 * @param new_distances new distances value
148 */
149void
150Laser360Interface::set_distances(const float * new_distances)
151{
152 set_field(data->distances, new_distances);
153}
154
155/** Set distances value at given index.
156 *
157 The distances in meter of the beams.
158
159 * @param new_distances new distances value
160 * @param index index for of the value
161 */
162void
163Laser360Interface::set_distances(unsigned int index, const float new_distances)
164{
165 set_field(data->distances, index, new_distances);
166}
167/** Get clockwise_angle value.
168 *
169 True if the angle grows clockwise.
170
171 * @return clockwise_angle value
172 */
173bool
174Laser360Interface::is_clockwise_angle() const
175{
176 return data->clockwise_angle;
177}
178
179/** Get maximum length of clockwise_angle value.
180 * @return length of clockwise_angle value, can be length of the array or number of
181 * maximum number of characters for a string
182 */
183size_t
184Laser360Interface::maxlenof_clockwise_angle() const
185{
186 return 1;
187}
188
189/** Set clockwise_angle value.
190 *
191 True if the angle grows clockwise.
192
193 * @param new_clockwise_angle new clockwise_angle value
194 */
195void
196Laser360Interface::set_clockwise_angle(const bool new_clockwise_angle)
197{
198 set_field(data->clockwise_angle, new_clockwise_angle);
199}
200
201/* =========== message create =========== */
202Message *
203Laser360Interface::create_message(const char *type) const
204{
205 throw UnknownTypeException("The given type '%s' does not match any known "
206 "message type for this interface type.", type);
207}
208
209
210/** Copy values from other interface.
211 * @param other other interface to copy values from
212 */
213void
214Laser360Interface::copy_values(const Interface *other)
215{
216 const Laser360Interface *oi = dynamic_cast<const Laser360Interface *>(other);
217 if (oi == NULL) {
218 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
219 type(), other->type());
220 }
221 memcpy(data, oi->data, sizeof(Laser360Interface_data_t));
222}
223
224const char *
225Laser360Interface::enum_tostring(const char *enumtype, int val) const
226{
227 throw UnknownTypeException("Unknown enum type %s", enumtype);
228}
229
230/* =========== messages =========== */
231/** Check if message is valid and can be enqueued.
232 * @param message Message to check
233 * @return true if the message is valid, false otherwise.
234 */
235bool
236Laser360Interface::message_valid(const Message *message) const
237{
238 return false;
239}
240
241/// @cond INTERNALS
242EXPORT_INTERFACE(Laser360Interface)
243/// @endcond
244
245
246} // end namespace fawkes
Base class for exceptions in Fawkes.
Definition: exception.h:36
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
Laser360Interface Fawkes BlackBoard Interface.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Fawkes library namespace.