orca-robotics INTRODUCTION Overview Download and Install Quick Start Documentation Publications REPOSITORY Interfaces Components Libraries Utilities Software Map DEVELOPER Tutorials Examples Dev Guide Dashboard Wiki login/pass: orca/orca PEOPLE Contributors Users Project Download Mailing lists
|
vfh_algorithm.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2006 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef VFH_ALGORITHM_H 00012 #define VFH_ALGORITHM_H 00013 00014 #include <vector> 00015 #include "vfh_algorithmconfig.h" 00016 00017 namespace vfh { 00018 00019 // 00020 // Handles all the number-crunching required for VFH. 00021 // Originally came from Player. 00022 // 00023 class VFH_Algorithm 00024 { 00025 public: 00026 VFH_Algorithm( const VfhAlgorithmConfig &config ); 00027 ~VFH_Algorithm(); 00028 00029 // Choose a new speed and turnrate based on the given laser data and current speed. 00030 // 00031 // Units/Senses: 00032 // - goal_direction in degrees, 0deg is to the right. 00033 // - goal_distance in mm. 00034 // - goal_distance_tolerance in mm. 00035 // 00036 static const int REQUIRED_NUM_RANGES = 361; 00037 int Update_VFH( double laser_ranges[REQUIRED_NUM_RANGES][2], 00038 int current_speed, 00039 float goal_direction, 00040 float goal_distance, 00041 float goal_distance_tolerance, 00042 int &chosen_speed, 00043 int &chosen_turnrate ); 00044 00045 // Angle to goal, in degrees. 0deg is to our right. 00046 float GetDesiredAngle() { return Desired_Angle; } 00047 float GetPickedAngle() { return Picked_Angle; } 00048 00049 // Max Turnrate depends on speed 00050 int GetMaxTurnrate( int speed ); 00051 int GetCurrentMaxSpeed() { return Current_Max_Speed; } 00052 00053 // Set methods 00054 void SetCurrentMaxSpeed( int Current_Max_Speed ); 00055 void SetTurnrateThreshold( int turnrate_threshold ) { TURNRATE_THRESHOLD = turnrate_threshold; } 00056 00057 // The Histogram. 00058 // This is public so that monitoring tools can get at it; it shouldn't 00059 // be modified externally. 00060 // Sweeps in an anti-clockwise direction. 00061 float *Hist; 00062 00063 private: 00064 00065 // Functions 00066 00067 int Init(); 00068 00069 int VFH_Allocate(); 00070 00071 float Delta_Angle(int a1, int a2); 00072 float Delta_Angle(float a1, float a2); 00073 int Bisect_Angle(int angle1, int angle2); 00074 00075 bool Cant_Turn_To_Goal(); 00076 00077 // Returns 0 if something got inside the safety distance, else 1. 00078 int Calculate_Cells_Mag( double laser_ranges[REQUIRED_NUM_RANGES][2], int speed ); 00079 // Returns 0 if something got inside the safety distance, else 1. 00080 int Build_Primary_Polar_Histogram( double laser_ranges[REQUIRED_NUM_RANGES][2], int speed ); 00081 int Build_Binary_Polar_Histogram(int speed); 00082 int Build_Masked_Polar_Histogram(int speed); 00083 int Select_Candidate_Angle(); 00084 int Select_Direction(); 00085 int Set_Motion( int &speed, int &turnrate, int current_speed ); 00086 00087 // Minimum turning radius at this speed, in millimeters 00088 int MinTurningRadius( int speed ); 00089 00090 void Print_Cells_Dir(); 00091 void Print_Cells_Mag(); 00092 void Print_Cells_Dist(); 00093 void Print_Cells_Sector(); 00094 void Print_Cells_Enlargement_Angle(); 00095 void Print_Hist(); 00096 00097 // Returns the speed index into Cell_Sector, for a given speed in mm/sec. 00098 // This exists so that only a few (potentially large) Cell_Sector tables must be stored. 00099 int Get_Speed_Index( int speed ); 00100 00101 // Returns the safety dist in mm for this speed. 00102 int Get_Safety_Dist( int speed ); 00103 00104 float Get_Binary_Hist_Low( int speed ); 00105 float Get_Binary_Hist_High( int speed ); 00106 00107 // Data 00108 00109 int CENTER_X; // cells 00110 int CENTER_Y; // cells 00111 int HIST_SIZE; // sectors (over 360deg) 00112 00113 float CELL_WIDTH; // millimeters 00114 int WINDOW_DIAMETER; // cells 00115 int SECTOR_ANGLE; // degrees 00116 float SAFETY_DIST_0MS; // millimeters 00117 float SAFETY_DIST_1MS; // millimeters 00118 int Current_Max_Speed; // mm/sec 00119 int MAX_SPEED; // mm/sec 00120 int MAX_SPEED_NARROW_OPENING; // mm/sec 00121 int MAX_SPEED_WIDE_OPENING; // mm/sec 00122 int MAX_ACCELERATION; // mm/sec/sec 00123 00124 int NUM_CELL_SECTOR_TABLES; 00125 00126 // Scale turnrate linearly between these two, but threashold. 00127 int MAX_TURNRATE_0MS; // deg/sec 00128 int MAX_TURNRATE_1MS; // deg/sec 00129 int TURNRATE_THRESHOLD; // deg/sec 00130 double MIN_TURN_RADIUS_SAFETY_FACTOR; 00131 float Binary_Hist_Low_0ms, Binary_Hist_High_0ms; 00132 float Binary_Hist_Low_1ms, Binary_Hist_High_1ms; 00133 float U1, U2; 00134 float ROBOT_RADIUS; // millimeters 00135 float Desired_Angle, Dist_To_Goal, Goal_Distance_Tolerance; 00136 float Picked_Angle, Last_Picked_Angle; 00137 int Max_Speed_For_Picked_Angle; 00138 00139 // Radius of dis-allowed circles, either side of the robot, which 00140 // we can't enter due to our minimum turning radius. 00141 float Blocked_Circle_Radius; 00142 00143 std::vector<std::vector<float> > Cell_Direction; 00144 std::vector<std::vector<float> > Cell_Base_Mag; 00145 std::vector<std::vector<float> > Cell_Mag; 00146 std::vector<std::vector<float> > Cell_Dist; // millimetres 00147 std::vector<std::vector<float> > Cell_Enlarge; 00148 00149 // Cell_Sector[x][y] is a vector of indices to sectors that are effected if cell (x,y) contains 00150 // an obstacle. 00151 // Cell enlargement is taken into account. 00152 // Acess as: Cell_Sector[speed_index][x][y][sector_index] 00153 std::vector<std::vector<std::vector<std::vector<int> > > > Cell_Sector; 00154 std::vector<float> Candidate_Angle; 00155 std::vector<int> Candidate_Speed; 00156 00157 double dist_eps; 00158 double ang_eps; 00159 00160 float *Last_Binary_Hist; 00161 00162 int last_chosen_speed; 00163 }; 00164 00165 } 00166 00167 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)