LocalizerControlInterface.cpp

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