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
33namespace fawkes {
34
35class Logger;
36class Configuration;
37
38/** @class RoboShapeColli <plugins/colli/utils/rob/roboshape_colli.h>
39 * This class is mainly the same as the basic class with the difference
40 * that all data is precalculated or estimated.
41 */
42
44{
45public:
46 RoboShapeColli(const char * cfg_prefix,
47 Logger * logger,
48 Configuration *config,
49 int readings_per_degree = 1);
51
52 ///\brief Returns the robots length for a specific angle.
53 float get_robot_length_for_rad(float anglerad);
54
55 ///\brief Returns the robots length for a specific angle.
56 float get_robot_length_for_deg(float angledeg);
57
58private:
59 // precalculated robot size data
60 std::vector<float> robot_lengths_;
61
62 unsigned int resolution_;
63};
64
65/* ************************************************************************************************* */
66/* IMPLEMENTATION DETAILS, DO NOT CARE! */
67/* ************************************************************************************************* */
68
69/** Constructor
70 * @param cfg_prefix The prefix of the config node, where the roboshape values are found
71 * @param logger Pointer to the fawkes logger
72 * @param config Pointer to the fawkes configuration.
73 * @param readings_per_degree Readings per degree constant (default=1)
74 */
75inline RoboShapeColli::RoboShapeColli(const char * cfg_prefix,
76 Logger * logger,
77 Configuration *config,
78 int readings_per_degree)
79: RoboShape(cfg_prefix, logger, config)
80{
81 resolution_ = readings_per_degree;
82 for (int i = 0; i < 360 * readings_per_degree; i++) {
83 float anglerad = (i / readings_per_degree) * M_PI / 180.f;
84 robot_lengths_.push_back(this->RoboShape::get_robot_length_for_rad(anglerad));
85 }
86}
87
88/** Destructor */
90{
91 robot_lengths_.clear();
92}
93
94/** Returns the robots length for a specific angle.
95 * @param anglerad is the angle in radians.
96 * @return the length in this direction.
97 */
98inline float
100{
101 return (this->get_robot_length_for_deg(rad2deg(anglerad)));
102}
103
104/** Returns the robots length for a specific angle.
105 * @param angledeg is the angle in degree.
106 * @return the length in this direction.
107 */
108inline float
110{
111 int number = (int)(angledeg * resolution_);
112 return robot_lengths_[number];
113}
114
115} // namespace fawkes
116
117#endif
Interface for configuration handling.
Definition: config.h:68
Interface for logging.
Definition: logger.h:42
This class is mainly the same as the basic class with the difference that all data is precalculated o...
~RoboShapeColli()
Destructor.
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.
RoboShapeColli(const char *cfg_prefix, Logger *logger, Configuration *config, int readings_per_degree=1)
Constructor.
This is a class containing all roboshape information.
Definition: roboshape.h:32
float get_robot_length_for_rad(float anglerad)
return the length of the robot for a specific angle
Definition: roboshape.cpp:254
Fawkes library namespace.
float rad2deg(float rad)
Convert an angle given in radians to degrees.
Definition: angle.h:46