00001 /** 00002 \file Robots/LoBot/irccm/LoDrive.h 00003 \brief Driving API for Robolocust iRobot Create Command Module control 00004 program. 00005 00006 This file defines an API for driving the iRobot Create using the Open 00007 Interface. These functions accept the high-level drive commands issued 00008 by the higher layers of the Robolocust controller and convert them to 00009 their equivalent Open Interface byte sequences. 00010 */ 00011 00012 /* 00013 ************************************************************************ 00014 * The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 * 00015 * by the University of Southern California (USC) and the iLab at USC. * 00016 * See http://iLab.usc.edu for information about this project. * 00017 * * 00018 * Major portions of the iLab Neuromorphic Vision Toolkit are protected * 00019 * under the U.S. patent ``Computation of Intrinsic Perceptual Saliency * 00020 * in Visual Environments, and Applications'' by Christof Koch and * 00021 * Laurent Itti, California Institute of Technology, 2001 (patent * 00022 * pending; application number 09/912,225 filed July 23, 2001; see * 00023 * http://pair.uspto.gov/cgi-bin/final/home.pl for current status). * 00024 ************************************************************************ 00025 * This file is part of the iLab Neuromorphic Vision C++ Toolkit. * 00026 * * 00027 * The iLab Neuromorphic Vision C++ Toolkit is free software; you can * 00028 * redistribute it and/or modify it under the terms of the GNU General * 00029 * Public License as published by the Free Software Foundation; either * 00030 * version 2 of the License, or (at your option) any later version. * 00031 * * 00032 * The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope * 00033 * that it will be useful, but WITHOUT ANY WARRANTY; without even the * 00034 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * 00035 * PURPOSE. See the GNU General Public License for more details. * 00036 * * 00037 * You should have received a copy of the GNU General Public License * 00038 * along with the iLab Neuromorphic Vision C++ Toolkit; if not, write * 00039 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * 00040 * Boston, MA 02111-1307 USA. * 00041 ************************************************************************ 00042 */ 00043 00044 /* 00045 Primary maintainer for this file: mviswana usc edu 00046 $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/irccm/LoDrive.h $ 00047 $Id: LoDrive.h 13769 2010-08-08 01:34:02Z mviswana $ 00048 */ 00049 00050 #ifndef LOBOT_IRCCM_DRIVE_DOT_H 00051 #define LOBOT_IRCCM_DRIVE_DOT_H 00052 00053 /*-------------------------- INITIALIZATION ---------------------------*/ 00054 00055 /// Initialize the drive system. 00056 /// 00057 /// The main function must call lo_init_drive() during initialization to 00058 /// ensure that the drive module's acceleration/deceleration 00059 /// functionality is setup properly. Internally, acceleration and 00060 /// deceleration are implemented using the ATmega168's Timer2 via the 00061 /// low-level controller's 10ms "generalized timer" callback mechanism. 00062 /// This function basically registers the callback function that 00063 /// implements the acceleration/deceleration feature with the timer 00064 /// module. 00065 void lo_init_drive(void) ; 00066 00067 /*--------------------- HIGH-LEVEL DRIVE COMMANDS ---------------------*/ 00068 00069 /// This command can be used by the high-level controller to have the 00070 /// robot continue to do whatever it is currently doing. This is useful 00071 /// when the high level doesn't have any real drive commands queued and 00072 /// ready for the low level. Without this NOP, the low-level controller 00073 /// will halt the robot if it doesn't receive a valid command within its 00074 /// timeout window. 00075 void lo_nop(int) ; 00076 00077 /// lobot's high-level controller works in terms of driving forwards, 00078 /// backwards and stopping as distinct commands for the robot. These 00079 /// functions implement the high-level drive commands using the generic 00080 /// lo_drive function. 00081 //@{ 00082 void lo_forward(int) ; 00083 void lo_reverse(int) ; 00084 void lo_stop(int) ; 00085 //@} 00086 00087 /// lobot's high-level controller works in terms of steering the robot 00088 /// using distinct left, right and straight commands. lobot also supports 00089 /// in-place turns, i.e., spinning. 00090 /// 00091 /// These functions implement the high-level steering commands using the 00092 /// generic lo_drive function. 00093 //@{ 00094 void lo_left(int turn_radius) ; 00095 void lo_right(int turn_radius) ; 00096 void lo_straight(int) ; 00097 void lo_cmd_spin(int angle) ; 00098 //@} 00099 00100 /*--------------------- LOW-LEVEL DRIVE COMMANDS ----------------------*/ 00101 00102 /// This function implements a "general" drive command that takes a 00103 /// speed and turn radius and converts it to the right set of Open 00104 /// Interface byte sequences. Additionally, this function takes a flag 00105 /// indicating whether the drive should be smooth (i.e., make use of the 00106 /// acceleration/deceleration functionality implemented by this module) 00107 /// or immediate (i.e., just implement the drive command without any 00108 /// acceleration/deceleration). 00109 void lo_drive(int speed, int turn_radius, char smooth) ; 00110 00111 /// This function executes an immediate stop. 00112 /// 00113 /// The high-level drive commands go through an acceleration/deceleration 00114 /// function to achieve the stated drive speed. However, when the 00115 /// low-level controller senses a dangerous situation (e.g., wheel drops, 00116 /// cliffs or bumps), it responds by taking appropriate action and then 00117 /// informing the high level with a suitable ACK message. When responding 00118 /// to low-level events, the low-level controller cannot afford to effect 00119 /// smooth acceleration/decelaration because that might cause big 00120 /// problems. Consider, for example, the robot approaching the edge of a 00121 /// stairway. When the cliff sensors fire, the robot has to stop 00122 /// immediately, pronto, right now, this very instant! If it were to 00123 /// decelerate smoothly, it would just topple down the stairs... 00124 /// 00125 /// This stop function allows low-level sensor reaction functions to 00126 /// bypass the acceleration/deceleration functions that are used by the 00127 /// high-level drive commands. 00128 #define lo_stop_immediate() lo_drive(0, LOBOT_OI_DRIVE_STRAIGHT, 0) 00129 00130 /// This function backs up the robot by the specified amount at the 00131 /// specified speed. It returns the actual amount backed up. 00132 /// 00133 /// NOTE: Positive values for the backup speed and distance parameters 00134 /// will result in moving the robot forward instead of backing it up. 00135 int lo_backup(int speed, int distance) ; 00136 00137 /// This function spins the robot in-place by the specified angle at the 00138 /// specified speed. It returns the actual amount spun. 00139 /// 00140 /// Positive values for the spin angle result in ccw turns; negative 00141 /// angles result in cw turns. 00142 int lo_spin(int speed, int angle) ; 00143 00144 /*---------------------------- DRIVE STATE ----------------------------*/ 00145 00146 /// Returns true if the robot is currently stopped; false if the robot is 00147 /// currently moving. 00148 char lo_stopped(void) ; 00149 00150 /// This function can be used to temporarily suspend the drive module's 00151 /// acceleration/deceleration functionality. It works by inhibiting the 00152 /// 10ms generalized timer's interrupts. It is required because the 10ms 00153 /// timer is used to ramp the speed up or down as necessary and issue 00154 /// Open Interface drive commands. 00155 /// 00156 /// However, if the low-level controller is currently talking to the high 00157 /// level via the Command Module's USB port, these drive commands will 00158 /// get routed to the wrong serial destination. Thus, when the low-level 00159 /// controller is busy interacting with the high level, it will need to 00160 /// ensure that the drive module doesn't issue any drive commands related 00161 /// to acceleration/deceleration. 00162 #define lo_suspend_ramping() lo_suspend_timer10() 00163 00164 /// This function can be used to resume the drive module's temporarily 00165 /// suspended acceleration/deceleration functionality. It works by 00166 /// reenabling the 10ms generalized timer's interrupts. It is required 00167 /// because the 10ms timer is used to ramp the speed up or down as 00168 /// necessary and issue Open Interface drive commands. 00169 /// 00170 /// However, if the low-level controller is currently talking to the high 00171 /// level via the Command Module's USB port, these drive commands will 00172 /// get routed to the wrong serial destination. Thus, when the low-level 00173 /// controller is busy interacting with the high level, it will need to 00174 /// ensure that the drive module doesn't issue any drive commands related 00175 /// to acceleration/deceleration. Once the low level is done talking to 00176 /// the high level, it will have to resume the speed ramping operations 00177 /// to ensure that the robot moves smoothly instead of jerking about as 00178 /// it starts and stops. 00179 #define lo_resume_ramping() lo_resume_timer10() 00180 00181 /*---------------------------------------------------------------------*/ 00182 00183 #endif