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 <cstring>
29 #include <cstdlib>
30 
31 namespace fawkes {
32 
33 /** @class Laser720Interface <interfaces/Laser720Interface.h>
34  * Laser720Interface Fawkes BlackBoard Interface.
35  *
36  This interface provides access to data of a laser scanner that produces
37  720 beams per scan.
38 
39  * @ingroup FawkesInterfaces
40  */
41 
42 
43 
44 /** Constructor */
45 Laser720Interface::Laser720Interface() : Interface()
46 {
47  data_size = sizeof(Laser720Interface_data_t);
48  data_ptr = malloc(data_size);
49  data = (Laser720Interface_data_t *)data_ptr;
50  data_ts = (interface_data_ts_t *)data_ptr;
51  memset(data_ptr, 0, data_size);
52  add_fieldinfo(IFT_STRING, "frame", 32, data->frame, "");
53  add_fieldinfo(IFT_FLOAT, "distances", 720, &data->distances, "");
54  add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle, "");
55  unsigned char tmp_hash[] = {0xca, 0x5e, 0xf1, 0x60, 0x74, 0x77, 0x8d, 0x9b, 0x5c, 0x81, 0x53, 0x5f, 0xc1, 0xf6, 0x89, 0x69};
56  set_hash(tmp_hash);
57 }
58 
59 /** Destructor */
60 Laser720Interface::~Laser720Interface()
61 {
62  free(data_ptr);
63 }
64 /* Methods */
65 /** Get frame value.
66  *
67  Coordinate frame in which the data is presented.
68 
69  * @return frame value
70  */
71 char *
73 {
74  return data->frame;
75 }
76 
77 /** Get maximum length of frame value.
78  * @return length of frame value, can be length of the array or number of
79  * maximum number of characters for a string
80  */
81 size_t
83 {
84  return 32;
85 }
86 
87 /** Set frame value.
88  *
89  Coordinate frame in which the data is presented.
90 
91  * @param new_frame new frame value
92  */
93 void
94 Laser720Interface::set_frame(const char * new_frame)
95 {
96  strncpy(data->frame, new_frame, sizeof(data->frame));
97  data_changed = true;
98 }
99 
100 /** Get distances value.
101  *
102  The distances in meter of the beams.
103 
104  * @return distances value
105  */
106 float *
108 {
109  return data->distances;
110 }
111 
112 /** Get distances value at given index.
113  *
114  The distances in meter of the beams.
115 
116  * @param index index of value
117  * @return distances value
118  * @exception Exception thrown if index is out of bounds
119  */
120 float
121 Laser720Interface::distances(unsigned int index) const
122 {
123  if (index > 720) {
124  throw Exception("Index value %u out of bounds (0..720)", index);
125  }
126  return data->distances[index];
127 }
128 
129 /** Get maximum length of distances value.
130  * @return length of distances value, can be length of the array or number of
131  * maximum number of characters for a string
132  */
133 size_t
135 {
136  return 720;
137 }
138 
139 /** Set distances value.
140  *
141  The distances in meter of the beams.
142 
143  * @param new_distances new distances value
144  */
145 void
146 Laser720Interface::set_distances(const float * new_distances)
147 {
148  memcpy(data->distances, new_distances, sizeof(float) * 720);
149  data_changed = true;
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  if (index > 720) {
163  throw Exception("Index value %u out of bounds (0..720)", index);
164  }
165  data->distances[index] = new_distances;
166  data_changed = true;
167 }
168 /** Get clockwise_angle value.
169  *
170  True if the angle grows clockwise.
171 
172  * @return clockwise_angle value
173  */
174 bool
176 {
177  return data->clockwise_angle;
178 }
179 
180 /** Get maximum length of clockwise_angle value.
181  * @return length of clockwise_angle value, can be length of the array or number of
182  * maximum number of characters for a string
183  */
184 size_t
186 {
187  return 1;
188 }
189 
190 /** Set clockwise_angle value.
191  *
192  True if the angle grows clockwise.
193 
194  * @param new_clockwise_angle new clockwise_angle value
195  */
196 void
197 Laser720Interface::set_clockwise_angle(const bool new_clockwise_angle)
198 {
199  data->clockwise_angle = new_clockwise_angle;
200  data_changed = true;
201 }
202 
203 /* =========== message create =========== */
204 Message *
205 Laser720Interface::create_message(const char *type) const
206 {
207  throw UnknownTypeException("The given type '%s' does not match any known "
208  "message type for this interface type.", type);
209 }
210 
211 
212 /** Copy values from other interface.
213  * @param other other interface to copy values from
214  */
215 void
217 {
218  const Laser720Interface *oi = dynamic_cast<const Laser720Interface *>(other);
219  if (oi == NULL) {
220  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
221  type(), other->type());
222  }
223  memcpy(data, oi->data, sizeof(Laser720Interface_data_t));
224 }
225 
226 const char *
227 Laser720Interface::enum_tostring(const char *enumtype, int val) const
228 {
229  throw UnknownTypeException("Unknown enum type %s", enumtype);
230 }
231 
232 /* =========== messages =========== */
233 /** Check if message is valid and can be enqueued.
234  * @param message Message to check
235  * @return true if the message is valid, false otherwise.
236  */
237 bool
239 {
240  return false;
241 }
242 
243 /// @cond INTERNALS
244 EXPORT_INTERFACE(Laser720Interface)
245 /// @endcond
246 
247 
248 } // end namespace fawkes
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:312
void set_frame(const char *new_frame)
Set frame value.
Fawkes library namespace.
unsigned int data_size
Minimal data size to hold data storage.
Definition: interface.h:207
string field
Definition: types.h:45
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
virtual void copy_values(const Interface *other)
Copy values from other interface.
char * frame() const
Get frame value.
bool data_changed
Indicator if data has changed.
Definition: interface.h:208
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:206
bool is_clockwise_angle() const
Get clockwise_angle value.
Base class for exceptions in Fawkes.
Definition: exception.h:36
size_t maxlenof_frame() const
Get maximum length of frame value.
void set_distances(unsigned int index, const float new_distances)
Set distances value at given index.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the field info list.
Definition: interface.cpp:332
virtual Message * create_message(const char *type) const
Create message based on type name.
float field
Definition: types.h:43
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
void set_clockwise_angle(const bool new_clockwise_angle)
Set clockwise_angle value.
size_t maxlenof_clockwise_angle() const
Get maximum length of clockwise_angle value.
size_t maxlenof_distances() const
Get maximum length of distances value.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
Definition: interface.h:216
float * distances() const
Get distances value.
boolean field
Definition: types.h:34
const char * type() const
Get type of interface.
Definition: interface.cpp:635
Laser720Interface Fawkes BlackBoard Interface.