AlgoVFH.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00027 /*
00028  *  Orca-Components: Components for robotics.
00029  *  
00030  *  Copyright (C) 2004
00031  *  
00032  *  This program is free software; you can redistribute it and/or
00033  *  modify it under the terms of the GNU General Public License
00034  *  as published by the Free Software Foundation; either version 2
00035  *  of the License, or (at your option) any later version.
00036  *  
00037  *  This program is distributed in the hope that it will be useful,
00038  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00039  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00040  *  GNU General Public License for more details.
00041  *  
00042  *  You should have received a copy of the GNU General Public License
00043  *  along with this program; if not, write to the Free Software
00044  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00045  */
00046 
00048 /* @{ */
00049 
00050 
00051 #ifndef __VFH_ALGO_H
00052 #define __VFH_ALGO_H
00053 
00054 #include <baselib.h>
00055 
00056 #include <vector>
00057 #include <math.h>
00058 //#include <libplayercore/playercore.h>
00059 
00060 
00061 
00065 class VFH_Algorithm
00066 {
00067 public:
00087     VFH_Algorithm( Decimal cell_size,
00088                    int window_diameter,
00089                    int sector_angle,
00090                    Decimal safety_dist_0ms,
00091                    Decimal safety_dist_1ms, 
00092                    int max_speed,
00093                    int max_speed_narrow_opening,
00094                    int max_speed_wide_opening,
00095                    int max_acceleration,
00096                    int min_turnrate,
00097                    int max_turnrate_0ms,
00098                    int max_turnrate_1ms,
00099                    Decimal min_turn_radius_safety_factor,
00100                    Decimal free_space_cutoff_0ms,
00101                    Decimal obs_cutoff_0ms,
00102                    Decimal free_space_cutoff_1ms,
00103                    Decimal obs_cutoff_1ms,
00104                    Decimal weight_desired_dir,
00105                    Decimal weight_current_dir );
00106 
00107     ~VFH_Algorithm();
00108 
00109     int Init();
00110     
00119     int Update_VFH( Decimal laser_ranges[361][2], 
00120                     int current_speed,  
00121                     Decimal goal_direction,
00122                     Decimal goal_distance,
00123                     Decimal goal_distance_tolerance,
00124                     int &chosen_speed, 
00125                     int &chosen_turnrate );
00126 
00127     // Get methods
00130     int   GetMinTurnrate() { return MIN_TURNRATE; }
00131     
00132   // Angle to goal, in degrees.  0deg is to our right.
00135     Decimal GetDesiredAngle() { return Desired_Angle; }
00136   
00139     Decimal GetPickedAngle() { return Picked_Angle; }
00140 
00141     // Max Turnrate depends on speed
00145     int GetMaxTurnrate( int speed );
00146   
00149     int GetCurrentMaxSpeed() { return Current_Max_Speed; }
00150 
00151     // Set methods
00155     void SetRobotRadius( Decimal robot_radius ) { this->ROBOT_RADIUS = robot_radius; }
00156     
00160   void SetMinTurnrate( int min_turnrate ) { MIN_TURNRATE = min_turnrate; }
00161   
00165   void SetCurrentMaxSpeed( int Current_Max_Speed );
00166 
00167     // The Histogram.
00168     // This is public so that monitoring tools can get at it; it shouldn't
00169     // be modified externally.
00170     // Sweeps in an anti-clockwise direction.
00171     Decimal *Hist;
00172 
00173 private:
00174 
00175     // Functions
00178     int VFH_Allocate();
00179 
00184   Decimal Delta_Angle(int a1, int a2);
00185     
00190   Decimal Delta_Angle(Decimal a1, Decimal a2);
00191     
00196   int Bisect_Angle(int angle1, int angle2);
00197 
00200     bool Cant_Turn_To_Goal();
00201 
00206     int Calculate_Cells_Mag( Decimal laser_ranges[361][2], int speed );
00207 
00212     int Build_Primary_Polar_Histogram( Decimal laser_ranges[361][2], int speed );
00213   
00217     int Build_Binary_Polar_Histogram(int speed);
00218   
00222     int Build_Masked_Polar_Histogram(int speed);
00223   
00226     int Select_Candidate_Angle();
00227   
00230     int Select_Direction();
00231   
00238   int Set_Motion( int &speed, int &turnrate, int current_speed, int current_turnrate);
00239 
00240     // AB: This doesn't seem to be implemented anywhere...
00241     // int Read_Min_Turning_Radius_From_File(char *filename);
00244   void Print_Cells_Dir();
00245   
00248     void Print_Cells_Mag();
00249   
00252     void Print_Cells_Dist();
00253   
00256     void Print_Cells_Sector();
00257   
00260     void Print_Cells_Enlargement_Angle();
00261   
00264     void Print_Hist();
00265 
00266     // Returns the speed index into Cell_Sector, for a given speed in mm/sec.
00267     // This exists so that only a few (potentially large) Cell_Sector tables must be stored.
00271     int Get_Speed_Index( int speed );
00272 
00273     // Returns the safety dist in mm for this speed.
00277     int Get_Safety_Dist( int speed );
00278   
00282     Decimal Get_Binary_Hist_Low( int speed );
00283   
00287     Decimal Get_Binary_Hist_High( int speed );
00288 
00289     // Data
00290 
00291     Decimal ROBOT_RADIUS;           // millimeters
00292     int CENTER_X;                 // cells
00293     int CENTER_Y;                 // cells
00294     int HIST_SIZE;                // sectors (over 360deg)
00295 
00296     Decimal CELL_WIDTH;             // millimeters
00297     int WINDOW_DIAMETER;          // cells
00298     int SECTOR_ANGLE;             // degrees
00299     Decimal SAFETY_DIST_0MS;        // millimeters
00300     Decimal SAFETY_DIST_1MS;        // millimeters
00301     int Current_Max_Speed;        // mm/sec
00302     int MAX_SPEED;                // mm/sec
00303     int MAX_SPEED_NARROW_OPENING; // mm/sec
00304     int MAX_SPEED_WIDE_OPENING;   // mm/sec
00305     int MAX_ACCELERATION;         // mm/sec/sec
00306     int MIN_TURNRATE;             // deg/sec -- not actually used internally
00307 
00308     int NUM_CELL_SECTOR_TABLES;
00309 
00310     // Scale turnrate linearly between these two
00311     int MAX_TURNRATE_0MS;       // deg/sec
00312     int MAX_TURNRATE_1MS;       // deg/sec
00313     Decimal MIN_TURN_RADIUS_SAFETY_FACTOR;
00314     Decimal Binary_Hist_Low_0ms, Binary_Hist_High_0ms;
00315     Decimal Binary_Hist_Low_1ms, Binary_Hist_High_1ms;
00316     Decimal U1, U2;
00317     Decimal Desired_Angle, Dist_To_Goal, Goal_Distance_Tolerance;
00318     Decimal Picked_Angle, Last_Picked_Angle;
00319     int   Max_Speed_For_Picked_Angle;
00320 
00321     // Radius of dis-allowed circles, either side of the robot, which
00322     // we can't enter due to our minimum turning radius.
00323     Decimal Blocked_Circle_Radius;
00324 
00325     std::vector<std::vector<Decimal> > Cell_Direction;
00326     std::vector<std::vector<Decimal> > Cell_Base_Mag;
00327     std::vector<std::vector<Decimal> > Cell_Mag;
00328     std::vector<std::vector<Decimal> > Cell_Dist;      // millimetres
00329     std::vector<std::vector<Decimal> > Cell_Enlarge;
00330 
00331     // Cell_Sector[x][y] is a vector of indices to sectors that are effected if cell (x,y) contains
00332     // an obstacle.  
00333     // Cell enlargement is taken into account.
00334     // Acess as: Cell_Sector[speed_index][x][y][sector_index]
00335     std::vector<std::vector<std::vector<std::vector<int> > > > Cell_Sector;
00336     std::vector<Decimal> Candidate_Angle;
00337     std::vector<int> Candidate_Speed;
00338 
00339     Decimal dist_eps;
00340     Decimal ang_eps;
00341 
00342     Decimal *Last_Binary_Hist;
00343 
00344     // Minimum turning radius at different speeds, in millimeters
00345     std::vector<int> Min_Turning_Radius;
00346 
00347     // Keep track of last update, so we can monitor acceleration
00348     timeval last_update_time;
00349 
00350     int last_chosen_speed;
00351   int last_chosen_turnrate;
00352 };
00353 
00354 #endif
00355 
00356 /* @} */

Generated on Mon Feb 20 07:01:06 2017 for MIP by  doxygen 1.5.6