Fawkes API Fawkes Development Version

KickerInterface.cpp

00001 
00002 /***************************************************************************
00003  *  KickerInterface.cpp - Fawkes BlackBoard Interface - KickerInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2007  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/KickerInterface.h>
00025 
00026 #include <core/exceptions/software.h>
00027 
00028 #include <cstring>
00029 #include <cstdlib>
00030 
00031 namespace fawkes {
00032 
00033 /** @class KickerInterface <interfaces/KickerInterface.h>
00034  * KickerInterface Fawkes BlackBoard Interface.
00035  * 
00036       In these variables it is stored how often the right, center or 
00037       left kick have been triggered.
00038     
00039  * @ingroup FawkesInterfaces
00040  */
00041 
00042 
00043 
00044 /** Constructor */
00045 KickerInterface::KickerInterface() : Interface()
00046 {
00047   data_size = sizeof(KickerInterface_data_t);
00048   data_ptr  = malloc(data_size);
00049   data      = (KickerInterface_data_t *)data_ptr;
00050   data_ts   = (interface_data_ts_t *)data_ptr;
00051   memset(data_ptr, 0, data_size);
00052   add_fieldinfo(IFT_INT32, "num_kicks_left", 1, &data->num_kicks_left);
00053   add_fieldinfo(IFT_INT32, "num_kicks_center", 1, &data->num_kicks_center);
00054   add_fieldinfo(IFT_INT32, "num_kicks_right", 1, &data->num_kicks_right);
00055   add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "GuideBallSideEnum");
00056   add_fieldinfo(IFT_UINT32, "current_intensity", 1, &data->current_intensity);
00057   add_messageinfo("KickMessage");
00058   add_messageinfo("ResetCounterMessage");
00059   add_messageinfo("GuideBallMessage");
00060   unsigned char tmp_hash[] = {0x96, 0x3d, 0x55, 0x60, 0xfd, 0x65, 0xf2, 0xfa, 0xa8, 0xfa, 0xfc, 0xaa, 0xb6, 0xfc, 0xc2, 0x81};
00061   set_hash(tmp_hash);
00062 }
00063 
00064 /** Destructor */
00065 KickerInterface::~KickerInterface()
00066 {
00067   free(data_ptr);
00068 }
00069 /** Convert GuideBallSideEnum constant to string.
00070  * @param value value to convert to string
00071  * @return constant value as string.
00072  */
00073 const char *
00074 KickerInterface::tostring_GuideBallSideEnum(GuideBallSideEnum value) const
00075 {
00076   switch (value) {
00077   case GUIDE_BALL_LEFT: return "GUIDE_BALL_LEFT";
00078   case GUIDE_BALL_RIGHT: return "GUIDE_BALL_RIGHT";
00079   default: return "UNKNOWN";
00080   }
00081 }
00082 /* Methods */
00083 /** Get num_kicks_left value.
00084  * 
00085       Number of Left-Kicks
00086     
00087  * @return num_kicks_left value
00088  */
00089 int32_t
00090 KickerInterface::num_kicks_left() const
00091 {
00092   return data->num_kicks_left;
00093 }
00094 
00095 /** Get maximum length of num_kicks_left value.
00096  * @return length of num_kicks_left value, can be length of the array or number of 
00097  * maximum number of characters for a string
00098  */
00099 size_t
00100 KickerInterface::maxlenof_num_kicks_left() const
00101 {
00102   return 1;
00103 }
00104 
00105 /** Set num_kicks_left value.
00106  * 
00107       Number of Left-Kicks
00108     
00109  * @param new_num_kicks_left new num_kicks_left value
00110  */
00111 void
00112 KickerInterface::set_num_kicks_left(const int32_t new_num_kicks_left)
00113 {
00114   data->num_kicks_left = new_num_kicks_left;
00115   data_changed = true;
00116 }
00117 
00118 /** Get num_kicks_center value.
00119  * 
00120       Number of Center-Kicks
00121     
00122  * @return num_kicks_center value
00123  */
00124 int32_t
00125 KickerInterface::num_kicks_center() const
00126 {
00127   return data->num_kicks_center;
00128 }
00129 
00130 /** Get maximum length of num_kicks_center value.
00131  * @return length of num_kicks_center value, can be length of the array or number of 
00132  * maximum number of characters for a string
00133  */
00134 size_t
00135 KickerInterface::maxlenof_num_kicks_center() const
00136 {
00137   return 1;
00138 }
00139 
00140 /** Set num_kicks_center value.
00141  * 
00142       Number of Center-Kicks
00143     
00144  * @param new_num_kicks_center new num_kicks_center value
00145  */
00146 void
00147 KickerInterface::set_num_kicks_center(const int32_t new_num_kicks_center)
00148 {
00149   data->num_kicks_center = new_num_kicks_center;
00150   data_changed = true;
00151 }
00152 
00153 /** Get num_kicks_right value.
00154  * 
00155       Number of Right-Kicks
00156     
00157  * @return num_kicks_right value
00158  */
00159 int32_t
00160 KickerInterface::num_kicks_right() const
00161 {
00162   return data->num_kicks_right;
00163 }
00164 
00165 /** Get maximum length of num_kicks_right value.
00166  * @return length of num_kicks_right value, can be length of the array or number of 
00167  * maximum number of characters for a string
00168  */
00169 size_t
00170 KickerInterface::maxlenof_num_kicks_right() const
00171 {
00172   return 1;
00173 }
00174 
00175 /** Set num_kicks_right value.
00176  * 
00177       Number of Right-Kicks
00178     
00179  * @param new_num_kicks_right new num_kicks_right value
00180  */
00181 void
00182 KickerInterface::set_num_kicks_right(const int32_t new_num_kicks_right)
00183 {
00184   data->num_kicks_right = new_num_kicks_right;
00185   data_changed = true;
00186 }
00187 
00188 /** Get guide_ball_side value.
00189  * Side where the ball
00190       guidance arm is currently erected.
00191  * @return guide_ball_side value
00192  */
00193 KickerInterface::GuideBallSideEnum
00194 KickerInterface::guide_ball_side() const
00195 {
00196   return data->guide_ball_side;
00197 }
00198 
00199 /** Get maximum length of guide_ball_side value.
00200  * @return length of guide_ball_side value, can be length of the array or number of 
00201  * maximum number of characters for a string
00202  */
00203 size_t
00204 KickerInterface::maxlenof_guide_ball_side() const
00205 {
00206   return 1;
00207 }
00208 
00209 /** Set guide_ball_side value.
00210  * Side where the ball
00211       guidance arm is currently erected.
00212  * @param new_guide_ball_side new guide_ball_side value
00213  */
00214 void
00215 KickerInterface::set_guide_ball_side(const GuideBallSideEnum new_guide_ball_side)
00216 {
00217   data->guide_ball_side = new_guide_ball_side;
00218   data_changed = true;
00219 }
00220 
00221 /** Get current_intensity value.
00222  * 
00223       The currently set intensity.
00224     
00225  * @return current_intensity value
00226  */
00227 uint32_t
00228 KickerInterface::current_intensity() const
00229 {
00230   return data->current_intensity;
00231 }
00232 
00233 /** Get maximum length of current_intensity value.
00234  * @return length of current_intensity value, can be length of the array or number of 
00235  * maximum number of characters for a string
00236  */
00237 size_t
00238 KickerInterface::maxlenof_current_intensity() const
00239 {
00240   return 1;
00241 }
00242 
00243 /** Set current_intensity value.
00244  * 
00245       The currently set intensity.
00246     
00247  * @param new_current_intensity new current_intensity value
00248  */
00249 void
00250 KickerInterface::set_current_intensity(const uint32_t new_current_intensity)
00251 {
00252   data->current_intensity = new_current_intensity;
00253   data_changed = true;
00254 }
00255 
00256 /* =========== message create =========== */
00257 Message *
00258 KickerInterface::create_message(const char *type) const
00259 {
00260   if ( strncmp("KickMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00261     return new KickMessage();
00262   } else if ( strncmp("ResetCounterMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00263     return new ResetCounterMessage();
00264   } else if ( strncmp("GuideBallMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
00265     return new GuideBallMessage();
00266   } else {
00267     throw UnknownTypeException("The given type '%s' does not match any known "
00268                                "message type for this interface type.", type);
00269   }
00270 }
00271 
00272 
00273 /** Copy values from other interface.
00274  * @param other other interface to copy values from
00275  */
00276 void
00277 KickerInterface::copy_values(const Interface *other)
00278 {
00279   const KickerInterface *oi = dynamic_cast<const KickerInterface *>(other);
00280   if (oi == NULL) {
00281     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00282                                 type(), other->type());
00283   }
00284   memcpy(data, oi->data, sizeof(KickerInterface_data_t));
00285 }
00286 
00287 const char *
00288 KickerInterface::enum_tostring(const char *enumtype, int val) const
00289 {
00290   if (strcmp(enumtype, "GuideBallSideEnum") == 0) {
00291     return tostring_GuideBallSideEnum((GuideBallSideEnum)val);
00292   }
00293   throw UnknownTypeException("Unknown enum type %s", enumtype);
00294 }
00295 
00296 /* =========== messages =========== */
00297 /** @class KickerInterface::KickMessage <interfaces/KickerInterface.h>
00298  * KickMessage Fawkes BlackBoard Interface Message.
00299  * 
00300     
00301  */
00302 
00303 
00304 /** Constructor with initial values.
00305  * @param ini_left initial value for left
00306  * @param ini_center initial value for center
00307  * @param ini_right initial value for right
00308  * @param ini_intensity initial value for intensity
00309  */
00310 KickerInterface::KickMessage::KickMessage(const bool ini_left, const bool ini_center, const bool ini_right, const uint32_t ini_intensity) : Message("KickMessage")
00311 {
00312   data_size = sizeof(KickMessage_data_t);
00313   data_ptr  = malloc(data_size);
00314   memset(data_ptr, 0, data_size);
00315   data      = (KickMessage_data_t *)data_ptr;
00316   data_ts   = (message_data_ts_t *)data_ptr;
00317   data->left = ini_left;
00318   data->center = ini_center;
00319   data->right = ini_right;
00320   data->intensity = ini_intensity;
00321   add_fieldinfo(IFT_BOOL, "left", 1, &data->left);
00322   add_fieldinfo(IFT_BOOL, "center", 1, &data->center);
00323   add_fieldinfo(IFT_BOOL, "right", 1, &data->right);
00324   add_fieldinfo(IFT_UINT32, "intensity", 1, &data->intensity);
00325 }
00326 /** Constructor */
00327 KickerInterface::KickMessage::KickMessage() : Message("KickMessage")
00328 {
00329   data_size = sizeof(KickMessage_data_t);
00330   data_ptr  = malloc(data_size);
00331   memset(data_ptr, 0, data_size);
00332   data      = (KickMessage_data_t *)data_ptr;
00333   data_ts   = (message_data_ts_t *)data_ptr;
00334   add_fieldinfo(IFT_BOOL, "left", 1, &data->left);
00335   add_fieldinfo(IFT_BOOL, "center", 1, &data->center);
00336   add_fieldinfo(IFT_BOOL, "right", 1, &data->right);
00337   add_fieldinfo(IFT_UINT32, "intensity", 1, &data->intensity);
00338 }
00339 
00340 /** Destructor */
00341 KickerInterface::KickMessage::~KickMessage()
00342 {
00343   free(data_ptr);
00344 }
00345 
00346 /** Copy constructor.
00347  * @param m message to copy from
00348  */
00349 KickerInterface::KickMessage::KickMessage(const KickMessage *m) : Message("KickMessage")
00350 {
00351   data_size = m->data_size;
00352   data_ptr  = malloc(data_size);
00353   memcpy(data_ptr, m->data_ptr, data_size);
00354   data      = (KickMessage_data_t *)data_ptr;
00355   data_ts   = (message_data_ts_t *)data_ptr;
00356 }
00357 
00358 /* Methods */
00359 /** Get left value.
00360  * True to kick with left kicker.
00361  * @return left value
00362  */
00363 bool
00364 KickerInterface::KickMessage::is_left() const
00365 {
00366   return data->left;
00367 }
00368 
00369 /** Get maximum length of left value.
00370  * @return length of left value, can be length of the array or number of 
00371  * maximum number of characters for a string
00372  */
00373 size_t
00374 KickerInterface::KickMessage::maxlenof_left() const
00375 {
00376   return 1;
00377 }
00378 
00379 /** Set left value.
00380  * True to kick with left kicker.
00381  * @param new_left new left value
00382  */
00383 void
00384 KickerInterface::KickMessage::set_left(const bool new_left)
00385 {
00386   data->left = new_left;
00387 }
00388 
00389 /** Get center value.
00390  * True to kick with central kicker.
00391  * @return center value
00392  */
00393 bool
00394 KickerInterface::KickMessage::is_center() const
00395 {
00396   return data->center;
00397 }
00398 
00399 /** Get maximum length of center value.
00400  * @return length of center value, can be length of the array or number of 
00401  * maximum number of characters for a string
00402  */
00403 size_t
00404 KickerInterface::KickMessage::maxlenof_center() const
00405 {
00406   return 1;
00407 }
00408 
00409 /** Set center value.
00410  * True to kick with central kicker.
00411  * @param new_center new center value
00412  */
00413 void
00414 KickerInterface::KickMessage::set_center(const bool new_center)
00415 {
00416   data->center = new_center;
00417 }
00418 
00419 /** Get right value.
00420  * True to kick with right kicker.
00421  * @return right value
00422  */
00423 bool
00424 KickerInterface::KickMessage::is_right() const
00425 {
00426   return data->right;
00427 }
00428 
00429 /** Get maximum length of right value.
00430  * @return length of right value, can be length of the array or number of 
00431  * maximum number of characters for a string
00432  */
00433 size_t
00434 KickerInterface::KickMessage::maxlenof_right() const
00435 {
00436   return 1;
00437 }
00438 
00439 /** Set right value.
00440  * True to kick with right kicker.
00441  * @param new_right new right value
00442  */
00443 void
00444 KickerInterface::KickMessage::set_right(const bool new_right)
00445 {
00446   data->right = new_right;
00447 }
00448 
00449 /** Get intensity value.
00450  * Intensity in the range [0..255].
00451  * @return intensity value
00452  */
00453 uint32_t
00454 KickerInterface::KickMessage::intensity() const
00455 {
00456   return data->intensity;
00457 }
00458 
00459 /** Get maximum length of intensity value.
00460  * @return length of intensity value, can be length of the array or number of 
00461  * maximum number of characters for a string
00462  */
00463 size_t
00464 KickerInterface::KickMessage::maxlenof_intensity() const
00465 {
00466   return 1;
00467 }
00468 
00469 /** Set intensity value.
00470  * Intensity in the range [0..255].
00471  * @param new_intensity new intensity value
00472  */
00473 void
00474 KickerInterface::KickMessage::set_intensity(const uint32_t new_intensity)
00475 {
00476   data->intensity = new_intensity;
00477 }
00478 
00479 /** Clone this message.
00480  * Produces a message of the same type as this message and copies the
00481  * data to the new message.
00482  * @return clone of this message
00483  */
00484 Message *
00485 KickerInterface::KickMessage::clone() const
00486 {
00487   return new KickerInterface::KickMessage(this);
00488 }
00489 /** @class KickerInterface::ResetCounterMessage <interfaces/KickerInterface.h>
00490  * ResetCounterMessage Fawkes BlackBoard Interface Message.
00491  * 
00492     
00493  */
00494 
00495 
00496 /** Constructor */
00497 KickerInterface::ResetCounterMessage::ResetCounterMessage() : Message("ResetCounterMessage")
00498 {
00499   data_size = sizeof(ResetCounterMessage_data_t);
00500   data_ptr  = malloc(data_size);
00501   memset(data_ptr, 0, data_size);
00502   data      = (ResetCounterMessage_data_t *)data_ptr;
00503   data_ts   = (message_data_ts_t *)data_ptr;
00504 }
00505 
00506 /** Destructor */
00507 KickerInterface::ResetCounterMessage::~ResetCounterMessage()
00508 {
00509   free(data_ptr);
00510 }
00511 
00512 /** Copy constructor.
00513  * @param m message to copy from
00514  */
00515 KickerInterface::ResetCounterMessage::ResetCounterMessage(const ResetCounterMessage *m) : Message("ResetCounterMessage")
00516 {
00517   data_size = m->data_size;
00518   data_ptr  = malloc(data_size);
00519   memcpy(data_ptr, m->data_ptr, data_size);
00520   data      = (ResetCounterMessage_data_t *)data_ptr;
00521   data_ts   = (message_data_ts_t *)data_ptr;
00522 }
00523 
00524 /* Methods */
00525 /** Clone this message.
00526  * Produces a message of the same type as this message and copies the
00527  * data to the new message.
00528  * @return clone of this message
00529  */
00530 Message *
00531 KickerInterface::ResetCounterMessage::clone() const
00532 {
00533   return new KickerInterface::ResetCounterMessage(this);
00534 }
00535 /** @class KickerInterface::GuideBallMessage <interfaces/KickerInterface.h>
00536  * GuideBallMessage Fawkes BlackBoard Interface Message.
00537  * 
00538     
00539  */
00540 
00541 
00542 /** Constructor with initial values.
00543  * @param ini_guide_ball_side initial value for guide_ball_side
00544  */
00545 KickerInterface::GuideBallMessage::GuideBallMessage(const GuideBallSideEnum ini_guide_ball_side) : Message("GuideBallMessage")
00546 {
00547   data_size = sizeof(GuideBallMessage_data_t);
00548   data_ptr  = malloc(data_size);
00549   memset(data_ptr, 0, data_size);
00550   data      = (GuideBallMessage_data_t *)data_ptr;
00551   data_ts   = (message_data_ts_t *)data_ptr;
00552   data->guide_ball_side = ini_guide_ball_side;
00553   add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "GuideBallSideEnum");
00554 }
00555 /** Constructor */
00556 KickerInterface::GuideBallMessage::GuideBallMessage() : Message("GuideBallMessage")
00557 {
00558   data_size = sizeof(GuideBallMessage_data_t);
00559   data_ptr  = malloc(data_size);
00560   memset(data_ptr, 0, data_size);
00561   data      = (GuideBallMessage_data_t *)data_ptr;
00562   data_ts   = (message_data_ts_t *)data_ptr;
00563   add_fieldinfo(IFT_ENUM, "guide_ball_side", 1, &data->guide_ball_side, "GuideBallSideEnum");
00564 }
00565 
00566 /** Destructor */
00567 KickerInterface::GuideBallMessage::~GuideBallMessage()
00568 {
00569   free(data_ptr);
00570 }
00571 
00572 /** Copy constructor.
00573  * @param m message to copy from
00574  */
00575 KickerInterface::GuideBallMessage::GuideBallMessage(const GuideBallMessage *m) : Message("GuideBallMessage")
00576 {
00577   data_size = m->data_size;
00578   data_ptr  = malloc(data_size);
00579   memcpy(data_ptr, m->data_ptr, data_size);
00580   data      = (GuideBallMessage_data_t *)data_ptr;
00581   data_ts   = (message_data_ts_t *)data_ptr;
00582 }
00583 
00584 /* Methods */
00585 /** Get guide_ball_side value.
00586  * Side where to guide the ball and erect the arm.
00587  * @return guide_ball_side value
00588  */
00589 KickerInterface::GuideBallSideEnum
00590 KickerInterface::GuideBallMessage::guide_ball_side() const
00591 {
00592   return data->guide_ball_side;
00593 }
00594 
00595 /** Get maximum length of guide_ball_side value.
00596  * @return length of guide_ball_side value, can be length of the array or number of 
00597  * maximum number of characters for a string
00598  */
00599 size_t
00600 KickerInterface::GuideBallMessage::maxlenof_guide_ball_side() const
00601 {
00602   return 1;
00603 }
00604 
00605 /** Set guide_ball_side value.
00606  * Side where to guide the ball and erect the arm.
00607  * @param new_guide_ball_side new guide_ball_side value
00608  */
00609 void
00610 KickerInterface::GuideBallMessage::set_guide_ball_side(const GuideBallSideEnum new_guide_ball_side)
00611 {
00612   data->guide_ball_side = new_guide_ball_side;
00613 }
00614 
00615 /** Clone this message.
00616  * Produces a message of the same type as this message and copies the
00617  * data to the new message.
00618  * @return clone of this message
00619  */
00620 Message *
00621 KickerInterface::GuideBallMessage::clone() const
00622 {
00623   return new KickerInterface::GuideBallMessage(this);
00624 }
00625 /** Check if message is valid and can be enqueued.
00626  * @param message Message to check
00627  * @return true if the message is valid, false otherwise.
00628  */
00629 bool
00630 KickerInterface::message_valid(const Message *message) const
00631 {
00632   const KickMessage *m0 = dynamic_cast<const KickMessage *>(message);
00633   if ( m0 != NULL ) {
00634     return true;
00635   }
00636   const ResetCounterMessage *m1 = dynamic_cast<const ResetCounterMessage *>(message);
00637   if ( m1 != NULL ) {
00638     return true;
00639   }
00640   const GuideBallMessage *m2 = dynamic_cast<const GuideBallMessage *>(message);
00641   if ( m2 != NULL ) {
00642     return true;
00643   }
00644   return false;
00645 }
00646 
00647 /// @cond INTERNALS
00648 EXPORT_INTERFACE(KickerInterface)
00649 /// @endcond
00650 
00651 
00652 } // end namespace fawkes
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends