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