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 
33 namespace 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 */
50 Laser360Interface::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 */
65 Laser360Interface::~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  */
76 char *
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  */
86 size_t
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  */
98 void
99 Laser360Interface::set_frame(const char * new_frame)
100 {
101  strncpy(data->frame, new_frame, sizeof(data->frame)-1);
102  data->frame[sizeof(data->frame)-1] = 0;
103  data_changed = true;
104 }
105 
106 /** Get distances value.
107  *
108  The distances in meter of the beams.
109 
110  * @return distances value
111  */
112 float *
114 {
115  return data->distances;
116 }
117 
118 /** Get distances value at given index.
119  *
120  The distances in meter of the beams.
121 
122  * @param index index of value
123  * @return distances value
124  * @exception Exception thrown if index is out of bounds
125  */
126 float
127 Laser360Interface::distances(unsigned int index) const
128 {
129  if (index > 359) {
130  throw Exception("Index value %u out of bounds (0..359)", index);
131  }
132  return data->distances[index];
133 }
134 
135 /** Get maximum length of distances value.
136  * @return length of distances value, can be length of the array or number of
137  * maximum number of characters for a string
138  */
139 size_t
141 {
142  return 360;
143 }
144 
145 /** Set distances value.
146  *
147  The distances in meter of the beams.
148 
149  * @param new_distances new distances value
150  */
151 void
152 Laser360Interface::set_distances(const float * new_distances)
153 {
154  memcpy(data->distances, new_distances, sizeof(float) * 360);
155  data_changed = true;
156 }
157 
158 /** Set distances value at given index.
159  *
160  The distances in meter of the beams.
161 
162  * @param new_distances new distances value
163  * @param index index for of the value
164  */
165 void
166 Laser360Interface::set_distances(unsigned int index, const float new_distances)
167 {
168  if (index > 359) {
169  throw Exception("Index value %u out of bounds (0..359)", index);
170  }
171  data->distances[index] = new_distances;
172  data_changed = true;
173 }
174 /** Get clockwise_angle value.
175  *
176  True if the angle grows clockwise.
177 
178  * @return clockwise_angle value
179  */
180 bool
182 {
183  return data->clockwise_angle;
184 }
185 
186 /** Get maximum length of clockwise_angle value.
187  * @return length of clockwise_angle value, can be length of the array or number of
188  * maximum number of characters for a string
189  */
190 size_t
192 {
193  return 1;
194 }
195 
196 /** Set clockwise_angle value.
197  *
198  True if the angle grows clockwise.
199 
200  * @param new_clockwise_angle new clockwise_angle value
201  */
202 void
203 Laser360Interface::set_clockwise_angle(const bool new_clockwise_angle)
204 {
205  data->clockwise_angle = new_clockwise_angle;
206  data_changed = true;
207 }
208 
209 /* =========== message create =========== */
210 Message *
211 Laser360Interface::create_message(const char *type) const
212 {
213  throw UnknownTypeException("The given type '%s' does not match any known "
214  "message type for this interface type.", type);
215 }
216 
217 
218 /** Copy values from other interface.
219  * @param other other interface to copy values from
220  */
221 void
223 {
224  const Laser360Interface *oi = dynamic_cast<const Laser360Interface *>(other);
225  if (oi == NULL) {
226  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
227  type(), other->type());
228  }
229  memcpy(data, oi->data, sizeof(Laser360Interface_data_t));
230 }
231 
232 const char *
233 Laser360Interface::enum_tostring(const char *enumtype, int val) const
234 {
235  throw UnknownTypeException("Unknown enum type %s", enumtype);
236 }
237 
238 /* =========== messages =========== */
239 /** Check if message is valid and can be enqueued.
240  * @param message Message to check
241  * @return true if the message is valid, false otherwise.
242  */
243 bool
244 Laser360Interface::message_valid(const Message *message) const
245 {
246  return false;
247 }
248 
249 /// @cond INTERNALS
250 EXPORT_INTERFACE(Laser360Interface)
251 /// @endcond
252 
253 
254 } // end namespace fawkes
fawkes::Interface::data_ptr
void * data_ptr
Definition: interface.h:223
fawkes::Laser360Interface::set_distances
void set_distances(unsigned int index, const float new_distances)
Set distances value at given index.
Definition: Laser360Interface.cpp:170
fawkes::Laser360Interface::frame
char * frame() const
Get frame value.
Definition: Laser360Interface.cpp:81
fawkes::Message
Definition: message.h:40
fawkes::IFT_BOOL
boolean field
Definition: types.h:48
fawkes::Laser360Interface::maxlenof_clockwise_angle
size_t maxlenof_clockwise_angle() const
Get maximum length of clockwise_angle value.
Definition: Laser360Interface.cpp:195
fawkes::IFT_FLOAT
float field
Definition: types.h:57
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition: interface.cpp:643
fawkes::Interface::add_fieldinfo
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the field info list.
Definition: interface.cpp:339
fawkes::Laser360Interface::distances
float * distances() const
Get distances value.
Definition: Laser360Interface.cpp:117
fawkes::Interface::data_ts
interface_data_ts_t * data_ts
Definition: interface.h:227
fawkes::Laser360Interface::maxlenof_distances
size_t maxlenof_distances() const
Get maximum length of distances value.
Definition: Laser360Interface.cpp:144
fawkes::Laser360Interface::maxlenof_frame
size_t maxlenof_frame() const
Get maximum length of frame value.
Definition: Laser360Interface.cpp:91
fawkes::TypeMismatchException
Definition: software.h:47
fawkes::Interface::data_changed
bool data_changed
Definition: interface.h:225
fawkes::UnknownTypeException
Definition: software.h:53
fawkes::Laser360Interface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Definition: Laser360Interface.cpp:237
fawkes
fawkes::Interface::set_hash
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:319
fawkes::Laser360Interface::create_message
virtual Message * create_message(const char *type) const
Definition: Laser360Interface.cpp:215
fawkes::Laser360Interface::set_frame
void set_frame(const char *new_frame)
Set frame value.
Definition: Laser360Interface.cpp:103
fawkes::Interface
Definition: interface.h:77
fawkes::Laser360Interface::set_clockwise_angle
void set_clockwise_angle(const bool new_clockwise_angle)
Set clockwise_angle value.
Definition: Laser360Interface.cpp:207
fawkes::Interface::data_size
unsigned int data_size
Definition: interface.h:224
fawkes::Laser360Interface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition: Laser360Interface.cpp:226
fawkes::IFT_STRING
string field
Definition: types.h:59
fawkes::Laser360Interface::is_clockwise_angle
bool is_clockwise_angle() const
Get clockwise_angle value.
Definition: Laser360Interface.cpp:185
fawkes::Laser360Interface
Definition: Laser360Interface.h:37
fawkes::Laser360Interface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition: Laser360Interface.cpp:248
fawkes::Exception
Definition: exception.h:39