Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * Laser720Interface.cpp - Fawkes BlackBoard Interface - Laser720Interface 00004 * 00005 * Templated created: Thu Oct 12 10:49:19 2006 00006 * Copyright 2008 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/Laser720Interface.h> 00025 00026 #include <core/exceptions/software.h> 00027 00028 #include <cstring> 00029 #include <cstdlib> 00030 00031 namespace fawkes { 00032 00033 /** @class Laser720Interface <interfaces/Laser720Interface.h> 00034 * Laser720Interface Fawkes BlackBoard Interface. 00035 * 00036 This interface provides access to data of a laser scanner that produces 00037 720 beams per scan. 00038 00039 * @ingroup FawkesInterfaces 00040 */ 00041 00042 00043 00044 /** Constructor */ 00045 Laser720Interface::Laser720Interface() : Interface() 00046 { 00047 data_size = sizeof(Laser720Interface_data_t); 00048 data_ptr = malloc(data_size); 00049 data = (Laser720Interface_data_t *)data_ptr; 00050 data_ts = (interface_data_ts_t *)data_ptr; 00051 memset(data_ptr, 0, data_size); 00052 add_fieldinfo(IFT_STRING, "frame", 32, data->frame); 00053 add_fieldinfo(IFT_FLOAT, "distances", 720, &data->distances); 00054 add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle); 00055 unsigned char tmp_hash[] = {0xca, 0x5e, 0xf1, 0x60, 0x74, 0x77, 0x8d, 0x9b, 0x5c, 0x81, 0x53, 0x5f, 0xc1, 0xf6, 0x89, 0x69}; 00056 set_hash(tmp_hash); 00057 } 00058 00059 /** Destructor */ 00060 Laser720Interface::~Laser720Interface() 00061 { 00062 free(data_ptr); 00063 } 00064 /* Methods */ 00065 /** Get frame value. 00066 * 00067 Coordinate frame in which the data is presented. 00068 00069 * @return frame value 00070 */ 00071 char * 00072 Laser720Interface::frame() const 00073 { 00074 return data->frame; 00075 } 00076 00077 /** Get maximum length of frame value. 00078 * @return length of frame value, can be length of the array or number of 00079 * maximum number of characters for a string 00080 */ 00081 size_t 00082 Laser720Interface::maxlenof_frame() const 00083 { 00084 return 32; 00085 } 00086 00087 /** Set frame value. 00088 * 00089 Coordinate frame in which the data is presented. 00090 00091 * @param new_frame new frame value 00092 */ 00093 void 00094 Laser720Interface::set_frame(const char * new_frame) 00095 { 00096 strncpy(data->frame, new_frame, sizeof(data->frame)); 00097 data_changed = true; 00098 } 00099 00100 /** Get distances value. 00101 * 00102 The distances in meter of the beams. 00103 00104 * @return distances value 00105 */ 00106 float * 00107 Laser720Interface::distances() const 00108 { 00109 return data->distances; 00110 } 00111 00112 /** Get distances value at given index. 00113 * 00114 The distances in meter of the beams. 00115 00116 * @param index index of value 00117 * @return distances value 00118 * @exception Exception thrown if index is out of bounds 00119 */ 00120 float 00121 Laser720Interface::distances(unsigned int index) const 00122 { 00123 if (index > 720) { 00124 throw Exception("Index value %u out of bounds (0..720)", index); 00125 } 00126 return data->distances[index]; 00127 } 00128 00129 /** Get maximum length of distances value. 00130 * @return length of distances value, can be length of the array or number of 00131 * maximum number of characters for a string 00132 */ 00133 size_t 00134 Laser720Interface::maxlenof_distances() const 00135 { 00136 return 720; 00137 } 00138 00139 /** Set distances value. 00140 * 00141 The distances in meter of the beams. 00142 00143 * @param new_distances new distances value 00144 */ 00145 void 00146 Laser720Interface::set_distances(const float * new_distances) 00147 { 00148 memcpy(data->distances, new_distances, sizeof(float) * 720); 00149 data_changed = true; 00150 } 00151 00152 /** Set distances value at given index. 00153 * 00154 The distances in meter of the beams. 00155 00156 * @param new_distances new distances value 00157 * @param index index for of the value 00158 */ 00159 void 00160 Laser720Interface::set_distances(unsigned int index, const float new_distances) 00161 { 00162 if (index > 720) { 00163 throw Exception("Index value %u out of bounds (0..720)", index); 00164 } 00165 data->distances[index] = new_distances; 00166 data_changed = true; 00167 } 00168 /** Get clockwise_angle value. 00169 * 00170 True if the angle grows clockwise. 00171 00172 * @return clockwise_angle value 00173 */ 00174 bool 00175 Laser720Interface::is_clockwise_angle() const 00176 { 00177 return data->clockwise_angle; 00178 } 00179 00180 /** Get maximum length of clockwise_angle value. 00181 * @return length of clockwise_angle value, can be length of the array or number of 00182 * maximum number of characters for a string 00183 */ 00184 size_t 00185 Laser720Interface::maxlenof_clockwise_angle() const 00186 { 00187 return 1; 00188 } 00189 00190 /** Set clockwise_angle value. 00191 * 00192 True if the angle grows clockwise. 00193 00194 * @param new_clockwise_angle new clockwise_angle value 00195 */ 00196 void 00197 Laser720Interface::set_clockwise_angle(const bool new_clockwise_angle) 00198 { 00199 data->clockwise_angle = new_clockwise_angle; 00200 data_changed = true; 00201 } 00202 00203 /* =========== message create =========== */ 00204 Message * 00205 Laser720Interface::create_message(const char *type) const 00206 { 00207 throw UnknownTypeException("The given type '%s' does not match any known " 00208 "message type for this interface type.", type); 00209 } 00210 00211 00212 /** Copy values from other interface. 00213 * @param other other interface to copy values from 00214 */ 00215 void 00216 Laser720Interface::copy_values(const Interface *other) 00217 { 00218 const Laser720Interface *oi = dynamic_cast<const Laser720Interface *>(other); 00219 if (oi == NULL) { 00220 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)", 00221 type(), other->type()); 00222 } 00223 memcpy(data, oi->data, sizeof(Laser720Interface_data_t)); 00224 } 00225 00226 const char * 00227 Laser720Interface::enum_tostring(const char *enumtype, int val) const 00228 { 00229 throw UnknownTypeException("Unknown enum type %s", enumtype); 00230 } 00231 00232 /* =========== messages =========== */ 00233 /** Check if message is valid and can be enqueued. 00234 * @param message Message to check 00235 * @return true if the message is valid, false otherwise. 00236 */ 00237 bool 00238 Laser720Interface::message_valid(const Message *message) const 00239 { 00240 return false; 00241 } 00242 00243 /// @cond INTERNALS 00244 EXPORT_INTERFACE(Laser720Interface) 00245 /// @endcond 00246 00247 00248 } // end namespace fawkes