Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
Environment.h
Go to the documentation of this file.
1#pragma once
2
3#include <ompl/base/ScopedState.h>
4
5#include "base/Primitives.h"
6#include "utils/Stopwatch.hpp"
7
9 public:
11 virtual ~Environment() = default;
12
13 void setStart(const Point &point);
14 const Point &start() const { return _start; }
15
16 void setGoal(const Point &point);
17 const Point &goal() const { return _goal; }
18
19 virtual bool collides(double x, double y) { return true; }
20 virtual bool collides(const Polygon &polygon) { return true; }
21 bool collides(const Point &p) { return collides(p.x, p.y); }
22 bool collides(const ompl::geometric::PathGeometric &trajectory);
23 bool collides(const ob::State *state) {
24 const auto *s = state->as<State>();
25 return collides(s->getX(), s->getY());
26 }
27
31 bool checkValidity(const ob::State *state);
32
33 inline const ob::RealVectorBounds &bounds() const { return _bounds; }
34 inline double width() const { return _bounds.high.at(0) - _bounds.low.at(0); }
35 inline double height() const {
36 return _bounds.high.at(1) - _bounds.low.at(1);
37 }
38
49 virtual double distance(double x, double y) { return -1; }
50
60 double distance(const ob::State *state) {
61 const auto *s = state->as<State>();
62 return distance(s->getX(), s->getY());
63 }
64
68 double bilinearDistance(double x, double y, double cellSize = 1);
69 double bilinearDistance(const Point &point, double cellSize = 1) {
70 return bilinearDistance(point.x, point.y, cellSize);
71 }
72 double bilinearDistance(const ob::State *state, double cellSize = 1) {
73 const auto *s = state->as<State>();
74 return bilinearDistance(s->getX(), s->getY());
75 }
76
86 bool distanceGradient(double x, double y, double &dx, double &dy,
87 double p = 0.1, double cellSize = 1);
88
89 virtual std::string name() const { return "Base map"; }
90
98
99 bool thetasDefined() const { return _thetas_defined; }
100 void setThetas(double start, double goal);
101
104
105 ompl::base::ScopedState<ob::SE2StateSpace> startScopedState() const;
106 ompl::base::ScopedState<ob::SE2StateSpace> goalScopedState() const;
107
108 ob::RealVectorBounds getBounds() const {return _bounds;}
109
110 double startTheta() const { return _start_theta; }
111 double goalTheta() const { return _goal_theta; }
112
113 virtual void to_json(nlohmann::json &j) {
114 j["type"] = "base";
115 j["width"] = width();
116 j["height"] = height();
117 j["start"] = start();
118 j["goal"] = goal();
119 j["name"] = name();
120 }
121
125 virtual double unit() const { return 1; }
126
128 double elapsedCollisionTime() const { return _collision_timer.elapsed(); }
129
130 protected:
133 double _start_theta{0};
134 double _goal_theta{0};
135 bool _thetas_defined{false};
136
137 ob::RealVectorBounds _bounds{2};
138
140};
ob::SE2StateSpace::StateType State
Definition: Primitives.h:12
Definition: Environment.h:8
double bilinearDistance(const Point &point, double cellSize=1)
Definition: Environment.h:69
double goalTheta() const
Definition: Environment.h:111
bool thetasDefined() const
Definition: Environment.h:99
virtual ~Environment()=default
double width() const
Definition: Environment.h:34
virtual double distance(double x, double y)
Compute distance from xy-coordinate to the closest obstacle if possible.
Definition: Environment.h:49
bool checkValidity(const ob::State *state)
Used by planners to determine if the state is valid or not.
Definition: Environment.cpp:22
Stopwatch _collision_timer
Definition: Environment.h:139
virtual void to_json(nlohmann::json &j)
Definition: Environment.h:113
double bilinearDistance(double x, double y, double cellSize=1)
Bilinear filtering of distance.
Definition: Environment.cpp:43
virtual bool collides(double x, double y)
Definition: Environment.h:19
bool distanceGradient(double x, double y, double &dx, double &dy, double p=0.1, double cellSize=1)
Computes negative gradient of distance field at position x, y.
Definition: Environment.cpp:66
ompl::base::State * goalState() const
Definition: Environment.h:103
virtual std::string name() const
Definition: Environment.h:89
double startTheta() const
Definition: Environment.h:110
double _start_theta
Definition: Environment.h:133
ob::RealVectorBounds _bounds
Definition: Environment.h:137
void setThetas(double start, double goal)
Definition: Environment.cpp:129
ob::RealVectorBounds getBounds() const
Definition: Environment.h:108
ompl::base::ScopedState< ob::SE2StateSpace > startScopedState() const
Definition: Environment.cpp:109
bool collides(const Point &p)
Definition: Environment.h:21
bool _thetas_defined
Definition: Environment.h:135
double height() const
Definition: Environment.h:35
Point _goal
Definition: Environment.h:132
void setStart(const Point &point)
Definition: Environment.cpp:137
Environment()
Definition: Environment.cpp:149
void estimateStartGoalOrientations()
Estimates potentially suitable theta values for the start and goal state by running a simple line sea...
Definition: Environment.cpp:79
ompl::base::ScopedState< ob::SE2StateSpace > goalScopedState() const
Definition: Environment.cpp:119
virtual double unit() const
Unit, e.g.
Definition: Environment.h:125
void setGoal(const Point &point)
Definition: Environment.cpp:143
double bilinearDistance(const ob::State *state, double cellSize=1)
Definition: Environment.h:72
double distance(const ob::State *state)
Compute distance of a state to the closest obstacle if possible.
Definition: Environment.h:60
virtual bool collides(const Polygon &polygon)
Definition: Environment.h:20
bool collides(const ob::State *state)
Definition: Environment.h:23
double _goal_theta
Definition: Environment.h:134
Point _start
Definition: Environment.h:131
double elapsedCollisionTime() const
Definition: Environment.h:128
ompl::base::State * startState() const
Definition: Environment.h:102
const Point & goal() const
Definition: Environment.h:17
const Point & start() const
Definition: Environment.h:14
void resetCollisionTimer()
Definition: Environment.h:127
const ob::RealVectorBounds & bounds() const
Definition: Environment.h:33
Stopwatch implementation to measure elapsed time.
Definition: Stopwatch.hpp:8
void reset()
Stops the timer and sets elapsed time to zero.
Definition: Stopwatch.hpp:23
double elapsed() const
Elapsed time in seconds.
Definition: Stopwatch.hpp:41
Definition: Primitives.h:42
double x
Definition: Primitives.h:43
ompl::base::State * toState(double theta=0) const
Definition: Primitives.cpp:21
double y
Definition: Primitives.h:43
Definition: Primitives.h:145