Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * LocalizerControlInterface.cpp - Fawkes BlackBoard Interface - LocalizerControlInterface 00004 * 00005 * Templated created: Thu Oct 12 10:49:19 2006 00006 * Copyright 2009 Daniel Beck 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/LocalizerControlInterface.h> 00025 00026 #include <core/exceptions/software.h> 00027 00028 #include <cstring> 00029 #include <cstdlib> 00030 00031 namespace fawkes { 00032 00033 /** @class LocalizerControlInterface <interfaces/LocalizerControlInterface.h> 00034 * LocalizerControlInterface Fawkes BlackBoard Interface. 00035 * 00036 This interface allows observe the current status of the a 00037 localizer as well as sending it commands (eg., reset, 00038 re-position, etc.) 00039 00040 * @ingroup FawkesInterfaces 00041 */ 00042 00043 00044 00045 /** Constructor */ 00046 LocalizerControlInterface::LocalizerControlInterface() : Interface() 00047 { 00048 data_size = sizeof(LocalizerControlInterface_data_t); 00049 data_ptr = malloc(data_size); 00050 data = (LocalizerControlInterface_data_t *)data_ptr; 00051 data_ts = (interface_data_ts_t *)data_ptr; 00052 memset(data_ptr, 0, data_size); 00053 add_fieldinfo(IFT_STRING, "map_name", 30, data->map_name); 00054 add_messageinfo("ResetMessage"); 00055 unsigned char tmp_hash[] = {0xa4, 0xe8, 0x69, 0x11, 0x29, 0x30, 0xf2, 0xcb, 0xe5, 0xf4, 00, 0x35, 0x19, 0x58, 0x54, 0xfb}; 00056 set_hash(tmp_hash); 00057 } 00058 00059 /** Destructor */ 00060 LocalizerControlInterface::~LocalizerControlInterface() 00061 { 00062 free(data_ptr); 00063 } 00064 /* Methods */ 00065 /** Get map_name value. 00066 * The name of the current 00067 map 00068 * @return map_name value 00069 */ 00070 char * 00071 LocalizerControlInterface::map_name() const 00072 { 00073 return data->map_name; 00074 } 00075 00076 /** Get maximum length of map_name value. 00077 * @return length of map_name value, can be length of the array or number of 00078 * maximum number of characters for a string 00079 */ 00080 size_t 00081 LocalizerControlInterface::maxlenof_map_name() const 00082 { 00083 return 30; 00084 } 00085 00086 /** Set map_name value. 00087 * The name of the current 00088 map 00089 * @param new_map_name new map_name value 00090 */ 00091 void 00092 LocalizerControlInterface::set_map_name(const char * new_map_name) 00093 { 00094 strncpy(data->map_name, new_map_name, sizeof(data->map_name)); 00095 data_changed = true; 00096 } 00097 00098 /* =========== message create =========== */ 00099 Message * 00100 LocalizerControlInterface::create_message(const char *type) const 00101 { 00102 if ( strncmp("ResetMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) { 00103 return new ResetMessage(); 00104 } else { 00105 throw UnknownTypeException("The given type '%s' does not match any known " 00106 "message type for this interface type.", type); 00107 } 00108 } 00109 00110 00111 /** Copy values from other interface. 00112 * @param other other interface to copy values from 00113 */ 00114 void 00115 LocalizerControlInterface::copy_values(const Interface *other) 00116 { 00117 const LocalizerControlInterface *oi = dynamic_cast<const LocalizerControlInterface *>(other); 00118 if (oi == NULL) { 00119 throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)", 00120 type(), other->type()); 00121 } 00122 memcpy(data, oi->data, sizeof(LocalizerControlInterface_data_t)); 00123 } 00124 00125 const char * 00126 LocalizerControlInterface::enum_tostring(const char *enumtype, int val) const 00127 { 00128 throw UnknownTypeException("Unknown enum type %s", enumtype); 00129 } 00130 00131 /* =========== messages =========== */ 00132 /** @class LocalizerControlInterface::ResetMessage <interfaces/LocalizerControlInterface.h> 00133 * ResetMessage Fawkes BlackBoard Interface Message. 00134 * 00135 00136 */ 00137 00138 00139 /** Constructor with initial values. 00140 * @param ini_x initial value for x 00141 * @param ini_y initial value for y 00142 * @param ini_ori initial value for ori 00143 * @param ini_variance initial value for variance 00144 */ 00145 LocalizerControlInterface::ResetMessage::ResetMessage(const float ini_x, const float ini_y, const float ini_ori, const float ini_variance) : Message("ResetMessage") 00146 { 00147 data_size = sizeof(ResetMessage_data_t); 00148 data_ptr = malloc(data_size); 00149 memset(data_ptr, 0, data_size); 00150 data = (ResetMessage_data_t *)data_ptr; 00151 data_ts = (message_data_ts_t *)data_ptr; 00152 data->x = ini_x; 00153 data->y = ini_y; 00154 data->ori = ini_ori; 00155 data->variance = ini_variance; 00156 add_fieldinfo(IFT_FLOAT, "x", 1, &data->x); 00157 add_fieldinfo(IFT_FLOAT, "y", 1, &data->y); 00158 add_fieldinfo(IFT_FLOAT, "ori", 1, &data->ori); 00159 add_fieldinfo(IFT_FLOAT, "variance", 1, &data->variance); 00160 } 00161 /** Constructor */ 00162 LocalizerControlInterface::ResetMessage::ResetMessage() : Message("ResetMessage") 00163 { 00164 data_size = sizeof(ResetMessage_data_t); 00165 data_ptr = malloc(data_size); 00166 memset(data_ptr, 0, data_size); 00167 data = (ResetMessage_data_t *)data_ptr; 00168 data_ts = (message_data_ts_t *)data_ptr; 00169 add_fieldinfo(IFT_FLOAT, "x", 1, &data->x); 00170 add_fieldinfo(IFT_FLOAT, "y", 1, &data->y); 00171 add_fieldinfo(IFT_FLOAT, "ori", 1, &data->ori); 00172 add_fieldinfo(IFT_FLOAT, "variance", 1, &data->variance); 00173 } 00174 00175 /** Destructor */ 00176 LocalizerControlInterface::ResetMessage::~ResetMessage() 00177 { 00178 free(data_ptr); 00179 } 00180 00181 /** Copy constructor. 00182 * @param m message to copy from 00183 */ 00184 LocalizerControlInterface::ResetMessage::ResetMessage(const ResetMessage *m) : Message("ResetMessage") 00185 { 00186 data_size = m->data_size; 00187 data_ptr = malloc(data_size); 00188 memcpy(data_ptr, m->data_ptr, data_size); 00189 data = (ResetMessage_data_t *)data_ptr; 00190 data_ts = (message_data_ts_t *)data_ptr; 00191 } 00192 00193 /* Methods */ 00194 /** Get x value. 00195 * The new initial x-coordinate. 00196 * @return x value 00197 */ 00198 float 00199 LocalizerControlInterface::ResetMessage::x() const 00200 { 00201 return data->x; 00202 } 00203 00204 /** Get maximum length of x value. 00205 * @return length of x value, can be length of the array or number of 00206 * maximum number of characters for a string 00207 */ 00208 size_t 00209 LocalizerControlInterface::ResetMessage::maxlenof_x() const 00210 { 00211 return 1; 00212 } 00213 00214 /** Set x value. 00215 * The new initial x-coordinate. 00216 * @param new_x new x value 00217 */ 00218 void 00219 LocalizerControlInterface::ResetMessage::set_x(const float new_x) 00220 { 00221 data->x = new_x; 00222 } 00223 00224 /** Get y value. 00225 * The new initial x-coordinate. 00226 * @return y value 00227 */ 00228 float 00229 LocalizerControlInterface::ResetMessage::y() const 00230 { 00231 return data->y; 00232 } 00233 00234 /** Get maximum length of y value. 00235 * @return length of y value, can be length of the array or number of 00236 * maximum number of characters for a string 00237 */ 00238 size_t 00239 LocalizerControlInterface::ResetMessage::maxlenof_y() const 00240 { 00241 return 1; 00242 } 00243 00244 /** Set y value. 00245 * The new initial x-coordinate. 00246 * @param new_y new y value 00247 */ 00248 void 00249 LocalizerControlInterface::ResetMessage::set_y(const float new_y) 00250 { 00251 data->y = new_y; 00252 } 00253 00254 /** Get ori value. 00255 * The new initial orientation. 00256 * @return ori value 00257 */ 00258 float 00259 LocalizerControlInterface::ResetMessage::ori() const 00260 { 00261 return data->ori; 00262 } 00263 00264 /** Get maximum length of ori value. 00265 * @return length of ori value, can be length of the array or number of 00266 * maximum number of characters for a string 00267 */ 00268 size_t 00269 LocalizerControlInterface::ResetMessage::maxlenof_ori() const 00270 { 00271 return 1; 00272 } 00273 00274 /** Set ori value. 00275 * The new initial orientation. 00276 * @param new_ori new ori value 00277 */ 00278 void 00279 LocalizerControlInterface::ResetMessage::set_ori(const float new_ori) 00280 { 00281 data->ori = new_ori; 00282 } 00283 00284 /** Get variance value. 00285 * The variance for the reset position. 00286 * @return variance value 00287 */ 00288 float 00289 LocalizerControlInterface::ResetMessage::variance() const 00290 { 00291 return data->variance; 00292 } 00293 00294 /** Get maximum length of variance value. 00295 * @return length of variance value, can be length of the array or number of 00296 * maximum number of characters for a string 00297 */ 00298 size_t 00299 LocalizerControlInterface::ResetMessage::maxlenof_variance() const 00300 { 00301 return 1; 00302 } 00303 00304 /** Set variance value. 00305 * The variance for the reset position. 00306 * @param new_variance new variance value 00307 */ 00308 void 00309 LocalizerControlInterface::ResetMessage::set_variance(const float new_variance) 00310 { 00311 data->variance = new_variance; 00312 } 00313 00314 /** Clone this message. 00315 * Produces a message of the same type as this message and copies the 00316 * data to the new message. 00317 * @return clone of this message 00318 */ 00319 Message * 00320 LocalizerControlInterface::ResetMessage::clone() const 00321 { 00322 return new LocalizerControlInterface::ResetMessage(this); 00323 } 00324 /** Check if message is valid and can be enqueued. 00325 * @param message Message to check 00326 * @return true if the message is valid, false otherwise. 00327 */ 00328 bool 00329 LocalizerControlInterface::message_valid(const Message *message) const 00330 { 00331 const ResetMessage *m0 = dynamic_cast<const ResetMessage *>(message); 00332 if ( m0 != NULL ) { 00333 return true; 00334 } 00335 return false; 00336 } 00337 00338 /// @cond INTERNALS 00339 EXPORT_INTERFACE(LocalizerControlInterface) 00340 /// @endcond 00341 00342 00343 } // end namespace fawkes