Fawkes API  Fawkes Development Version
roboshape_colli.h
1 
2 /***************************************************************************
3  * roboshape_colli.h - RoboShape class for colli with precalculated data
4  *
5  * Created: Fri Oct 18 15:16:23 2013
6  * Copyright 2002 Stefan Jacobs
7  * 2013-2014 Bahram Maleki-Fard
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_COLLI_UTILS_ROB_ROBOSHAPE_COLLI_H_
24 #define __PLUGINS_COLLI_UTILS_ROB_ROBOSHAPE_COLLI_H_
25 
26 #include "roboshape.h"
27 
28 #include <utils/math/angle.h>
29 
30 #include <cmath>
31 #include <vector>
32 
33 namespace fawkes
34 {
35 #if 0 /* just to make Emacs auto-indent happy */
36 }
37 #endif
38 
39 class Logger;
40 class Configuration;
41 
42 /** @class RoboShapeColli <plugins/colli/utils/rob/roboshape_colli.h>
43  * This class is mainly the same as the basic class with the difference
44  * that all data is precalculated or estimated.
45  */
46 
47 class RoboShapeColli : public RoboShape
48 {
49  public:
50  RoboShapeColli( const char * cfg_prefix,
51  Logger* logger,
52  Configuration* config,
53  int readings_per_degree = 1 ) throw (int);
55 
56  ///\brief Returns the robots length for a specific angle.
57  float get_robot_length_for_rad( float anglerad );
58 
59  ///\brief Returns the robots length for a specific angle.
60  float get_robot_length_for_deg( float angledeg );
61 
62  private:
63  // precalculated robot size data
64  std::vector< float > robot_lengths_;
65 
66  unsigned int resolution_;
67 };
68 
69 
70 /* ************************************************************************************************* */
71 /* IMPLEMENTATION DETAILS, DO NOT CARE! */
72 /* ************************************************************************************************* */
73 
74 /** Constructor
75  * @param cfg_prefix The prefix of the config node, where the roboshape values are found
76  * @param logger Pointer to the fawkes logger
77  * @param config Pointer to the fawkes configuration.
78  * @param readings_per_degree Readings per degree constant (default=1)
79  */
80 inline
81 RoboShapeColli::RoboShapeColli( const char * cfg_prefix,
82  Logger* logger,
83  Configuration* config,
84  int readings_per_degree ) throw (int)
85  : RoboShape( cfg_prefix, logger, config)
86 {
87  resolution_ = readings_per_degree;
88  for ( int i = 0; i < 360*readings_per_degree; i++ ) {
89  float anglerad = (i / readings_per_degree) * M_PI / 180.f;
90  robot_lengths_.push_back( this->RoboShape::get_robot_length_for_rad( anglerad ) );
91  }
92 }
93 
94 /** Destructor */
95 inline
97 {
98  robot_lengths_.clear();
99 }
100 
101 /** Returns the robots length for a specific angle.
102  * @param anglerad is the angle in radians.
103  * @return the length in this direction.
104  */
105 inline float
107 {
108  return (this->get_robot_length_for_deg( rad2deg( anglerad ) ));
109 }
110 
111 /** Returns the robots length for a specific angle.
112  * @param angledeg is the angle in degree.
113  * @return the length in this direction.
114  */
115 inline float
117 {
118  int number = (int)(angledeg*resolution_);
119  return robot_lengths_[number];
120 }
121 
122 } // namespace fawkes
123 
124 #endif
float get_robot_length_for_deg(float angledeg)
Returns the robots length for a specific angle.
float get_robot_length_for_rad(float anglerad)
Returns the robots length for a specific angle.
float get_robot_length_for_rad(float anglerad)
return the length of the robot for a specific angle
Definition: roboshape.cpp:274
Fawkes library namespace.
RoboShapeColli(const char *cfg_prefix, Logger *logger, Configuration *config, int readings_per_degree=1)
Constructor.
~RoboShapeColli()
Destructor.
RoboShape(const char *cfg_prefix, fawkes::Logger *logger, fawkes::Configuration *config)
Constructor.
Definition: roboshape.cpp:49
float rad2deg(float rad)
Convert an angle given in radians to degrees.
Definition: angle.h:48
This is a class containing all roboshape information.
Definition: roboshape.h:35
This class is mainly the same as the basic class with the difference that all data is precalculated o...
Interface for configuration handling.
Definition: config.h:67
Interface for logging.
Definition: logger.h:34