Fawkes API  Fawkes Development Version
Laser720Interface.cpp
1 
2 /***************************************************************************
3  * Laser720Interface.cpp - Fawkes BlackBoard Interface - Laser720Interface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2008 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/Laser720Interface.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 Laser720Interface <interfaces/Laser720Interface.h>
36  * Laser720Interface Fawkes BlackBoard Interface.
37  *
38  This interface provides access to data of a laser scanner that produces
39  720 beams per scan.
40 
41  * @ingroup FawkesInterfaces
42  */
43 
44 
45 
46 /** Constructor */
47 Laser720Interface::Laser720Interface() : Interface()
48 {
49  data_size = sizeof(Laser720Interface_data_t);
50  data_ptr = malloc(data_size);
51  data = (Laser720Interface_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", 720, &data->distances);
56  add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle);
57  unsigned char tmp_hash[] = {0xca, 0x5e, 0xf1, 0x60, 0x74, 0x77, 0x8d, 0x9b, 0x5c, 0x81, 0x53, 0x5f, 0xc1, 0xf6, 0x89, 0x69};
58  set_hash(tmp_hash);
59 }
60 
61 /** Destructor */
62 Laser720Interface::~Laser720Interface()
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  */
73 char *
74 Laser720Interface::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  */
83 size_t
84 Laser720Interface::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  */
95 void
96 Laser720Interface::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  */
107 float *
108 Laser720Interface::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  */
121 float
122 Laser720Interface::distances(unsigned int index) const
123 {
124  if (index > 719) {
125  throw Exception("Index value %u out of bounds (0..719)", 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  */
134 size_t
135 Laser720Interface::maxlenof_distances() const
136 {
137  return 720;
138 }
139 
140 /** Set distances value.
141  *
142  The distances in meter of the beams.
143 
144  * @param new_distances new distances value
145  */
146 void
147 Laser720Interface::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  */
159 void
160 Laser720Interface::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  */
170 bool
171 Laser720Interface::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  */
180 size_t
181 Laser720Interface::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  */
192 void
193 Laser720Interface::set_clockwise_angle(const bool new_clockwise_angle)
194 {
195  set_field(data->clockwise_angle, new_clockwise_angle);
196 }
197 
198 /* =========== message create =========== */
199 Message *
200 Laser720Interface::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  */
210 void
211 Laser720Interface::copy_values(const Interface *other)
212 {
213  const Laser720Interface *oi = dynamic_cast<const Laser720Interface *>(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(Laser720Interface_data_t));
219 }
220 
221 const char *
222 Laser720Interface::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  */
232 bool
233 Laser720Interface::message_valid(const Message *message) const
234 {
235  return false;
236 }
237 
238 /// @cond INTERNALS
239 EXPORT_INTERFACE(Laser720Interface)
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
Laser720Interface Fawkes BlackBoard Interface.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Fawkes library namespace.