LoRobot.C

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/io/LoRobot.C
00003    \brief This file defines the non-inline member functions of the
00004    lobot::Robot class.
00005 */
00006 
00007 // //////////////////////////////////////////////////////////////////// //
00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00009 // University of Southern California (USC) and the iLab at USC.         //
00010 // See http://iLab.usc.edu for information about this project.          //
00011 // //////////////////////////////////////////////////////////////////// //
00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00014 // in Visual Environments, and Applications'' by Christof Koch and      //
00015 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00016 // pending; application number 09/912,225 filed July 23, 2001; see      //
00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00018 // //////////////////////////////////////////////////////////////////// //
00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00022 // redistribute it and/or modify it under the terms of the GNU General  //
00023 // Public License as published by the Free Software Foundation; either  //
00024 // version 2 of the License, or (at your option) any later version.     //
00025 //                                                                      //
00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00029 // PURPOSE.  See the GNU General Public License for more details.       //
00030 //                                                                      //
00031 // You should have received a copy of the GNU General Public License    //
00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00034 // Boston, MA 02111-1307 USA.                                           //
00035 // //////////////////////////////////////////////////////////////////// //
00036 //
00037 // Primary maintainer for this file: mviswana usc edu
00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoRobot.C $
00039 // $Id: LoRobot.C 13593 2010-06-21 23:26:06Z mviswana $
00040 //
00041 
00042 //------------------------------ HEADERS --------------------------------
00043 
00044 // lobot headers
00045 #include "Robots/LoBot/io/LoRobot.H"
00046 #include "Robots/LoBot/util/LoMath.H"
00047 
00048 //----------------------------- NAMESPACE -------------------------------
00049 
00050 namespace lobot {
00051 
00052 //-------------------------- INITIALIZATION -----------------------------
00053 
00054 Robot::
00055 Robot(const ModelManager& mgr, const std::string& device, int baud_rate)
00056    : m_serial(mgr, device, baud_rate)
00057 {}
00058 
00059 Robot::Sensors::Sensors()
00060    : m_time_stamp(0),
00061      m_speed(0), m_heading(0),
00062      m_motor_pwm(0), m_servo_pwm(0), m_rpm(0),
00063      m_bump(0), m_wheel_drops(0),
00064      m_walls(0), m_wall_signal(0),
00065      m_cliff(0),
00066      m_infrared(0),
00067      m_distance(0), m_angle(0),
00068      m_battery_charge(0),
00069      m_requested_speed(0), m_requested_radius(0)
00070 {
00071    m_cliff_signals[LEFT_SIGNAL]  = 0 ;
00072    m_cliff_signals[RIGHT_SIGNAL] = 0 ;
00073    m_cliff_signals[FRONT_LEFT_SIGNAL]  = 0 ;
00074    m_cliff_signals[FRONT_RIGHT_SIGNAL] = 0 ;
00075 }
00076 
00077 Robot::Sensors::Sensors(const Robot::Sensors& S)
00078    : m_time_stamp(S.m_time_stamp),
00079      m_speed(S.m_speed), m_heading(S.m_heading),
00080      m_motor_pwm(S.m_motor_pwm), m_servo_pwm(S.m_servo_pwm), m_rpm(S.m_rpm),
00081      m_bump(S.m_bump), m_wheel_drops(S.m_wheel_drops),
00082      m_walls(S.m_walls), m_wall_signal(S.m_wall_signal),
00083      m_cliff(S.m_cliff),
00084      m_infrared(S.m_infrared),
00085      m_distance(S.m_distance), m_angle(S.m_angle),
00086      m_battery_charge(S.m_battery_charge),
00087      m_requested_speed(S.m_requested_speed),
00088      m_requested_radius(S.m_requested_radius)
00089 {
00090    m_cliff_signals[LEFT_SIGNAL]  = S.m_cliff_signals[LEFT_SIGNAL] ;
00091    m_cliff_signals[RIGHT_SIGNAL] = S.m_cliff_signals[RIGHT_SIGNAL] ;
00092    m_cliff_signals[FRONT_LEFT_SIGNAL]  = S.m_cliff_signals[FRONT_LEFT_SIGNAL] ;
00093    m_cliff_signals[FRONT_RIGHT_SIGNAL] = S.m_cliff_signals[FRONT_RIGHT_SIGNAL];
00094 }
00095 
00096 //-------------------------- SENSOR UPDATES -----------------------------
00097 
00098 void Robot::add_hook(const Robot::SensorHook& H)
00099 {
00100    AutoMutex M(m_sensor_hooks_mutex) ;
00101    m_sensor_hooks.push_back(H) ;
00102 }
00103 
00104 class trigger_hook {
00105    const Robot::Sensors& m_sensors ;
00106 public:
00107    trigger_hook(const Robot::Sensors& S) : m_sensors(S) {}
00108    void operator()(const Robot::SensorHook& H) const {
00109       //LERROR("triggering sensor hook for packet @ %lld",
00110              //m_sensors.time_stamp()) ;
00111       H.first(m_sensors, H.second) ;
00112    }
00113 } ;
00114 
00115 void Robot::update()
00116 {
00117    if (update_sensors()) {
00118       AutoMutex M(m_sensor_hooks_mutex) ;
00119       std::for_each(m_sensor_hooks.begin(), m_sensor_hooks.end(),
00120                     trigger_hook(m_sensors)) ;
00121    }
00122 }
00123 
00124 //-------------------------- MOTOR COMMANDS -----------------------------
00125 
00126 void Robot::off()
00127 {
00128    turn(0) ;
00129    drive(0, 0) ;
00130 }
00131 
00132 //------------------------ MOTOR STATE QUERIES --------------------------
00133 
00134 bool Robot::stopped() const
00135 {
00136    return is_zero(current_speed()) ;
00137 }
00138 
00139 //----------------------------- CLEAN-UP --------------------------------
00140 
00141 Robot::~Robot(){}
00142 
00143 //-----------------------------------------------------------------------
00144 
00145 } // end of namespace encapsulating this file's definitions
00146 
00147 //-----------------------------------------------------------------------
00148 
00149 /* So things look consistent in everyone's emacs... */
00150 /* Local Variables: */
00151 /* indent-tabs-mode: nil */
00152 /* End: */
Generated on Sun May 8 08:05:54 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3