Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * Laser360Interface.cpp - Fawkes BlackBoard Interface - Laser360Interface 00004 * 00005 * Templated created: Thu Oct 12 10:49:19 2006 00006 * Copyright 2008-2009 Tim Niemueller 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <interfaces/Laser360Interface.h> 00025 00026 #include <core/exceptions/software.h> 00027 00028 #include <cstring> 00029 #include <cstdlib> 00030 00031 namespace fawkes { 00032 00033 /** @class Laser360Interface <interfaces/Laser360Interface.h> 00034 * Laser360Interface Fawkes BlackBoard Interface. 00035 * 00036 This interface provides access to data of a laser scanner that produces 00037 360 beams per scan. The inter-beam distance is 1 deg, 0 deg is 00038 "forward", i.e. in the Fawkes coordinate system pointing towards 00039 the cartesian point (1,0). The direction in which the angle 00040 grows is indicated by the clockwise_angle field. 00041 00042 * @ingroup FawkesInterfaces 00043 */ 00044 00045 00046 00047 /** Constructor */ 00048 Laser360Interface::Laser360Interface() : Interface() 00049 { 00050 data_size = sizeof(Laser360Interface_data_t); 00051 data_ptr = malloc(data_size); 00052 data = (Laser360Interface_data_t *)data_ptr; 00053 data_ts = (interface_data_ts_t *)data_ptr; 00054 memset(data_ptr, 0, data_size); 00055 add_fieldinfo(IFT_STRING, "frame", 32, data->frame); 00056 add_fieldinfo(IFT_FLOAT, "distances", 360, &data->distances); 00057 add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle); 00058 unsigned char tmp_hash[] = {0x5c, 0x1, 0x85, 0x24, 0x85, 0x28, 0x1f, 0xc6, 0xae, 0x4c, 0x46, 0x66, 0xe9, 0xcb, 0xe9, 0x4e}; 00059 set_hash(tmp_hash); 00060 } 00061 00062 /** Destructor */ 00063 Laser360Interface::~Laser360Interface() 00064 { 00065 free(data_ptr); 00066 } 00067 /* Methods */ 00068 /** Get frame value. 00069 * 00070 Coordinate frame in which the data is presented. 00071 00072 * @return frame value 00073 */ 00074 char * 00075 Laser360Interface::frame() const 00076 { 00077 return data->frame; 00078 } 00079 00080 /** Get maximum length of frame value. 00081 * @return length of frame value, can be length of the array or number of 00082 * maximum number of characters for a string 00083 */ 00084 size_t 00085 Laser360Interface::maxlenof_frame() const 00086 { 00087 return 32; 00088 } 00089 00090 /** Set frame value. 00091 * 00092 Coordinate frame in which the data is presented. 00093 00094 * @param new_frame new frame value 00095 */ 00096 void 00097 Laser360Interface::set_frame(const char * new_frame) 00098 { 00099 strncpy(data->frame, new_frame, sizeof(data->frame)); 00100 data_changed = true; 00101 } 00102 00103 /** Get distances value. 00104 * 00105 The distances in meter of the beams. 00106 00107 * @return distances value 00108 */ 00109 float * 00110 Laser360Interface::distances() const 00111 { 00112 return data->distances; 00113 } 00114 00115 /** Get distances value at given index. 00116 * 00117 The distances in meter of the beams. 00118 00119 * @param index index of value 00120 * @return distances value 00121 * @exception Exception thrown if index is out of bounds 00122 */ 00123 float 00124 Laser360Interface::distances(unsigned int index) const 00125 { 00126 if (index > 360) { 00127 throw Exception("Index value %u out of bounds (0..360)", index); 00128 } 00129 return data->distances[index]; 00130 } 00131 00132 /** Get maximum length of distances value. 00133 * @return length of distances value, can be length of the array or number of 00134 * maximum number of characters for a string 00135 */ 00136 size_t 00137 Laser360Interface::maxlenof_distances() const 00138 { 00139 return 360; 00140 } 00141 00142 /** Set distances value. 00143 * 00144 The distances in meter of the beams. 00145 00146 * @param new_distances new distances value 00147 */ 00148 void 00149 Laser360Interface::set_distances(const float * new_distances) 00150 { 00151 memcpy(data->distances, new_distances, sizeof(float) * 360); 00152 data_changed = true; 00153 } 00154 00155 /** Set distances value at given index. 00156 * 00157 The distances in meter of the beams. 00158 00159 * @param new_distances new distances value 00160 * @param index index for of the value 00161 */ 00162 void 00163 Laser360Interface::set_distances(unsigned int index, const float new_distances) 00164 { 00165 if (index > 360) { 00166 throw Exception("Index value %u out of bounds (0..360)", index); 00167 } 00168 data->distances[index] = new_distances; 00169 data_changed = true; 00170 } 00171 /** Get clockwise_angle value. 00172 * 00173 True if the angle grows clockwise. 00174 00175 * @return clockwise_angle value 00176 */ 00177 bool 00178 Laser360Interface::is_clockwise_angle() const 00179 { 00180 return data->clockwise_angle; 00181 } 00182 00183 /** Get maximum length of clockwise_angle value. 00184 * @return length of clockwise_angle value, can be length of the array or number of 00185 * maximum number of characters for a string 00186 */ 00187 size_t 00188 Laser360Interface::maxlenof_clockwise_angle() const 00189 { 00190 return 1; 00191 } 00192 00193 /** Set clockwise_angle value. 00194 * 00195 True if the angle grows clockwise. 00196 00197 * @param new_clockwise_angle new clockwise_angle value 00198 */ 00199 void 00200 Laser360Interface::set_clockwise_angle(const bool new_clockwise_angle) 00201 { 00202 data->clockwise_angle = new_clockwise_angle; 00203 data_changed = true; 00204 } 00205 00206 /* =========== message create =========== */ 00207 Message * 00208 Laser360Interface::create_message(const char *type) const 00209 { 00210 throw UnknownTypeException("The given type '%s' does not match any known " 00211 "message type for this interface type.", type); 00212 } 00213 00214 00215 /** Copy values from other interface. 00216 * @param other other interface to copy values from 00217 */ 00218 void 00219 Laser360Interface::copy_values(const Interface *other) 00220 { 00221 const Laser360Interface *oi = dynamic_cast<const Laser360Interface *>(other); 00222 if (oi == NULL) { 00223 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)", 00224 type(), other->type()); 00225 } 00226 memcpy(data, oi->data, sizeof(Laser360Interface_data_t)); 00227 } 00228 00229 const char * 00230 Laser360Interface::enum_tostring(const char *enumtype, int val) const 00231 { 00232 throw UnknownTypeException("Unknown enum type %s", enumtype); 00233 } 00234 00235 /* =========== messages =========== */ 00236 /** Check if message is valid and can be enqueued. 00237 * @param message Message to check 00238 * @return true if the message is valid, false otherwise. 00239 */ 00240 bool 00241 Laser360Interface::message_valid(const Message *message) const 00242 { 00243 return false; 00244 } 00245 00246 /// @cond INTERNALS 00247 EXPORT_INTERFACE(Laser360Interface) 00248 /// @endcond 00249 00250 00251 } // end namespace fawkes