Laser720Interface.cpp

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_FLOAT, "distances", 720, &data->distances);
00053   add_fieldinfo(IFT_BOOL, "clockwise_angle", 1, &data->clockwise_angle);
00054   unsigned char tmp_hash[] = {0x8a, 0x9, 0x94, 0x1a, 0xe4, 0x3c, 0xa5, 0xde, 0x5, 0xe7, 0x8c, 0x6e, 0x3b, 0x7f, 0x34, 0x5};
00055   set_hash(tmp_hash);
00056 }
00057 
00058 /** Destructor */
00059 Laser720Interface::~Laser720Interface()
00060 {
00061   free(data_ptr);
00062 }
00063 /* Methods */
00064 /** Get distances value.
00065  * 
00066       The distances in meter of the beams.
00067     
00068  * @return distances value
00069  */
00070 float *
00071 Laser720Interface::distances() const
00072 {
00073   return data->distances;
00074 }
00075 
00076 /** Get distances value at given index.
00077  * 
00078       The distances in meter of the beams.
00079     
00080  * @param index index of value
00081  * @return distances value
00082  * @exception Exception thrown if index is out of bounds
00083  */
00084 float
00085 Laser720Interface::distances(unsigned int index) const
00086 {
00087   if (index > 720) {
00088     throw Exception("Index value %u out of bounds (0..720)", index);
00089   }
00090   return data->distances[index];
00091 }
00092 
00093 /** Get maximum length of distances value.
00094  * @return length of distances value, can be length of the array or number of 
00095  * maximum number of characters for a string
00096  */
00097 size_t
00098 Laser720Interface::maxlenof_distances() const
00099 {
00100   return 720;
00101 }
00102 
00103 /** Set distances value.
00104  * 
00105       The distances in meter of the beams.
00106     
00107  * @param new_distances new distances value
00108  */
00109 void
00110 Laser720Interface::set_distances(const float * new_distances)
00111 {
00112   memcpy(data->distances, new_distances, sizeof(float) * 720);
00113   data_changed = true;
00114 }
00115 
00116 /** Set distances value at given index.
00117  * 
00118       The distances in meter of the beams.
00119     
00120  * @param new_distances new distances value
00121  * @param index index for of the value
00122  */
00123 void
00124 Laser720Interface::set_distances(unsigned int index, const float new_distances)
00125 {
00126   if (index > 720) {
00127     throw Exception("Index value %u out of bounds (0..720)", index);
00128   }
00129   data->distances[index] = new_distances;
00130 }
00131 /** Get clockwise_angle value.
00132  * 
00133       True if the angle grows clockwise.
00134     
00135  * @return clockwise_angle value
00136  */
00137 bool
00138 Laser720Interface::is_clockwise_angle() const
00139 {
00140   return data->clockwise_angle;
00141 }
00142 
00143 /** Get maximum length of clockwise_angle value.
00144  * @return length of clockwise_angle value, can be length of the array or number of 
00145  * maximum number of characters for a string
00146  */
00147 size_t
00148 Laser720Interface::maxlenof_clockwise_angle() const
00149 {
00150   return 1;
00151 }
00152 
00153 /** Set clockwise_angle value.
00154  * 
00155       True if the angle grows clockwise.
00156     
00157  * @param new_clockwise_angle new clockwise_angle value
00158  */
00159 void
00160 Laser720Interface::set_clockwise_angle(const bool new_clockwise_angle)
00161 {
00162   data->clockwise_angle = new_clockwise_angle;
00163   data_changed = true;
00164 }
00165 
00166 /* =========== message create =========== */
00167 Message *
00168 Laser720Interface::create_message(const char *type) const
00169 {
00170   throw UnknownTypeException("The given type '%s' does not match any known "
00171                              "message type for this interface type.", type);
00172 }
00173 
00174 
00175 /** Copy values from other interface.
00176  * @param other other interface to copy values from
00177  */
00178 void
00179 Laser720Interface::copy_values(const Interface *other)
00180 {
00181   const Laser720Interface *oi = dynamic_cast<const Laser720Interface *>(other);
00182   if (oi == NULL) {
00183     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00184                                 type(), other->type());
00185   }
00186   memcpy(data, oi->data, sizeof(Laser720Interface_data_t));
00187 }
00188 
00189 const char *
00190 Laser720Interface::enum_tostring(const char *enumtype, int val) const
00191 {
00192   throw UnknownTypeException("Unknown enum type %s", enumtype);
00193 }
00194 
00195 /* =========== messages =========== */
00196 /** Check if message is valid and can be enqueued.
00197  * @param message Message to check
00198  * @return true if the message is valid, false otherwise.
00199  */
00200 bool
00201 Laser720Interface::message_valid(const Message *message) const
00202 {
00203   return false;
00204 }
00205 
00206 /// @cond INTERNALS
00207 EXPORT_INTERFACE(Laser720Interface)
00208 /// @endcond
00209 
00210 
00211 } // end namespace fawkes