00001 /** 00002 \file Robots/LoBot/misc/LoOdometry.H 00003 \brief A simple structure for holding lobot's odometry data. 00004 00005 This file defines a class that provides a convenient odometry-related 00006 API for the SLAM related parts of Robolocust. 00007 */ 00008 00009 // //////////////////////////////////////////////////////////////////// // 00010 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00011 // by the University of Southern California (USC) and the iLab at USC. // 00012 // See http://iLab.usc.edu for information about this project. // 00013 // //////////////////////////////////////////////////////////////////// // 00014 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00015 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00016 // in Visual Environments, and Applications'' by Christof Koch and // 00017 // Laurent Itti, California Institute of Technology, 2001 (patent // 00018 // pending; application number 09/912,225 filed July 23, 2001; see // 00019 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00020 // //////////////////////////////////////////////////////////////////// // 00021 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00024 // redistribute it and/or modify it under the terms of the GNU General // 00025 // Public License as published by the Free Software Foundation; either // 00026 // version 2 of the License, or (at your option) any later version. // 00027 // // 00028 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00029 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00030 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00031 // PURPOSE. See the GNU General Public License for more details. // 00032 // // 00033 // You should have received a copy of the GNU General Public License // 00034 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00035 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00036 // Boston, MA 02111-1307 USA. // 00037 // //////////////////////////////////////////////////////////////////// // 00038 // 00039 // Primary maintainer for this file: mviswana usc edu 00040 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/slam/LoOdometry.H $ 00041 // $Id: LoOdometry.H 13478 2010-05-25 03:54:43Z mviswana $ 00042 // 00043 00044 #ifndef LOBOT_ODOMETRY_DOT_H 00045 #define LOBOT_ODOMETRY_DOT_H 00046 00047 //------------------------------ HEADERS -------------------------------- 00048 00049 // Standard C++ headers 00050 #include <utility> 00051 00052 //----------------------------- NAMESPACE ------------------------------- 00053 00054 namespace lobot { 00055 00056 //------------------------- CLASS DEFINITION ---------------------------- 00057 00058 /** 00059 \class lobot::Odometry 00060 \brief A simple API for various odometry-related operations. 00061 00062 This class stores the distance and angle returned by lobot's low-level 00063 motor system. It also provides an API for accumulating these odometric 00064 parameters and for maintaining and testing against certain thresholds. 00065 */ 00066 class Odometry { 00067 /// lobot's odometry consists of distance traveled and angle turned. 00068 /// We simply stuff both these quantities into an STL pair. 00069 typedef std::pair<int, int> OdometryData ; 00070 00071 /// As the robot moves, the low-level layers will report odometric 00072 /// updates in terms of the amount of distance and turn since the 00073 /// previous update (i.e., deltas). Additionally, this class can also 00074 /// keep track of the total displacement and turn. 00075 OdometryData m_delta, m_total ; 00076 00077 /// This class can be used to check when the low-level odometry 00078 /// crosses some predefined thresholds. This data member stores the 00079 /// afore-mentioned thresholds. 00080 OdometryData m_thresholds ; 00081 00082 public: 00083 /// Initialization. 00084 Odometry() ; 00085 00086 /// This method updates the current odometric values using the 00087 /// supplied ones. 00088 void add(int distance, int angle) ; 00089 00090 /// This method allows clients to set some threshold values. Later, 00091 /// clients can check if these thresholds have been crossed or not. 00092 void set_thresholds(int distance, int angle) { 00093 m_thresholds.first = distance ; 00094 m_thresholds.second = angle ; 00095 } 00096 00097 /// Convenience function for setting thresholds specified in an STL 00098 /// pair. 00099 void set_thresholds(const std::pair<int, int>& T) { 00100 set_thresholds(T.first, T.second) ; 00101 } 00102 00103 /// This method checks if the total distance or angle have crossed the 00104 /// thresholds set by the client. 00105 bool thresholds_crossed() const ; 00106 00107 /// Often, after the robot has traveled a certain distance and/or 00108 /// turned by some predefined amount, the higher layers of the robot's 00109 /// controller will want to perform some action (e.g., SLAM update, 00110 /// scan matching) and then reset the odometry so that the tracking 00111 /// can begin anew. 00112 /// 00113 /// This method resets the odometry as described above. 00114 void reset() { 00115 m_delta.first = m_delta.second = m_total.first = m_total.second = 0 ; 00116 } 00117 00118 /// This method returns the net displacement recorded by this odometry 00119 /// packet. 00120 int displacement() const {return m_delta.first ;} 00121 00122 /// This method returns the net rotation recorded by this odometry 00123 /// packet. 00124 int rotation() const {return m_delta.second ;} 00125 } ; 00126 00127 //----------------------------------------------------------------------- 00128 00129 } // end of namespace encapsulating this file's definitions 00130 00131 #endif 00132 00133 /* So things look consistent in everyone's emacs... */ 00134 /* Local Variables: */ 00135 /* indent-tabs-mode: nil */ 00136 /* End: */