Laser360Interface.cpp

00001
00002 /***************************************************************************
00003  *  Laser360Interface.cpp - Fawkes BlackBoard Interface - Laser360Interface
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/Laser360Interface.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstring>
00029 #include <cstdlib>
00030
00031 namespace fawkes {
00032 
00033 /** @class Laser360Interface <interfaces/Laser360Interface.h>
00034  * Laser360Interface Fawkes BlackBoard Interface.
00035  * 
00036       This interface provides access to data of a laser scanner that produces
00037       360 beams per scan.
00038     
00039  * @ingroup FawkesInterfaces
00040  */
00041
00042
00043 
00044 /** Constructor */
00045 Laser360Interface::Laser360Interface() : Interface()
00046 {
00047   data_size = sizeof(Laser360Interface_data_t);
00048   data_ptr  = malloc(data_size);
00049   data      = (Laser360Interface_data_t *)data_ptr;
00050   memset(data_ptr, 0, data_size);
00051   add_fieldinfo(IFT_FLOAT, "distances", 360, &data->distances);
00052   unsigned char tmp_hash[] = {0xc4, 0x7a, 0xf3, 0xa0, 0x4, 0x6, 0x97, 0x1d, 0xdb, 0x17, 0xfe, 0x5e, 0xd0, 0x9b, 0xa, 0xa3};
00053   set_hash(tmp_hash);
00054 }
00055 
00056 /** Destructor */
00057 Laser360Interface::~Laser360Interface()
00058 {
00059   free(data_ptr);
00060 }
00061 /* Methods */
00062 /** Get distances value.
00063  * 
00064       The distances in meter of the beams.
00065     
00066  * @return distances value
00067  */
00068 float *
00069 Laser360Interface::distances() const
00070 {
00071   return data->distances;
00072 }
00073 
00074 /** Get distances value at given index.
00075  * 
00076       The distances in meter of the beams.
00077     
00078  * @param index index of value
00079  * @return distances value
00080  * @exception Exception thrown if index is out of bounds
00081  */
00082 float
00083 Laser360Interface::distances(unsigned int index) const
00084 {
00085   if (index > 360) {
00086     throw Exception("Index value %u out of bounds (0..360)", index);
00087   }
00088   return data->distances[index];
00089 }
00090 
00091 /** Get maximum length of distances value.
00092  * @return length of distances value, can be length of the array or number of 
00093  * maximum number of characters for a string
00094  */
00095 size_t
00096 Laser360Interface::maxlenof_distances() const
00097 {
00098   return 360;
00099 }
00100 
00101 /** Set distances value.
00102  * 
00103       The distances in meter of the beams.
00104     
00105  * @param new_distances new distances value
00106  */
00107 void
00108 Laser360Interface::set_distances(const float * new_distances)
00109 {
00110   memcpy(data->distances, new_distances, sizeof(float) * 360);
00111 }
00112 
00113 /** Set distances value at given index.
00114  * 
00115       The distances in meter of the beams.
00116     
00117  * @param new_distances new distances value
00118  * @param index index for of the value
00119  */
00120 void
00121 Laser360Interface::set_distances(unsigned int index, const float new_distances)
00122 {
00123   if (index > 360) {
00124     throw Exception("Index value %u out of bounds (0..360)", index);
00125   }
00126   data->distances[index] = new_distances;
00127 }
00128 /* =========== message create =========== */
00129 Message *
00130 Laser360Interface::create_message(const char *type) const
00131 {
00132   throw UnknownTypeException("The given type '%s' does not match any known "
00133                              "message type for this interface type.", type);
00134 }
00135
00136 
00137 /** Copy values from other interface.
00138  * @param other other interface to copy values from
00139  */
00140 void
00141 Laser360Interface::copy_values(const Interface *other)
00142 {
00143   const Laser360Interface *oi = dynamic_cast<const Laser360Interface *>(other);
00144   if (oi == NULL) {
00145     throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
00146                                 type(), other->type());
00147   }
00148   memcpy(data, oi->data, sizeof(Laser360Interface_data_t));
00149 }
00150
00151 /* =========== messages =========== */
00152 /** Check if message is valid and can be enqueued.
00153  * @param message Message to check
00154  */
00155 bool
00156 Laser360Interface::message_valid(const Message *message) const
00157 {
00158   return false;
00159 }
00160 
00161 /// @cond INTERNALS
00162 EXPORT_INTERFACE(Laser360Interface)
00163 /// @endcond
00164 
00165
00166 } // end namespace fawkes