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