ugv_nav4d
PreComputedMotions.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "DiscreteTheta.hpp"
4 #include "Mobility.hpp"
5 #include <limits>
6 #include <stdexcept>
7 #include <vector>
8 #include <base/Pose.hpp>
9 #include <maps/grid/Index.hpp>
10 #include <sbpl_spline_primitives/SbplSplineMotionPrimitives.hpp>
11 
12 namespace ugv_nav4d
13 {
14 
16 {
17  base::Pose2D pose;
18  maps::grid::Index cell;
19 };
20 
22 {
23  maps::grid::Index cell;
24  std::vector<base::Pose2D> poses;
25 };
26 
27 
28 class Motion
29 {
30 public:
31 
34  static double costScaleFactor;
35 
36  enum Type {
41  };
42 
43  Motion(unsigned int numAngles = 0) : endTheta(0, numAngles),startTheta(0, numAngles), baseCost(0), id(std::numeric_limits<size_t>::max()) {};
44 
45  static int calculateCost(double translationalDist, double angularDist, double translationVelocity, double angularVelocity, double costMultiplier);
46 
47  int xDiff;
48  int yDiff;
51 
53 
59  std::vector<PoseWithCell> intermediateStepsTravMap;
60 
66  std::vector<PoseWithCell> intermediateStepsObstMap;
67 
76  std::vector<CellWithPoses> fullSplineSamples;
77 
78  int baseCost; //time the robot needs to follow the primivite scaled by some factors
79  int costMultiplier;//is used to scale the baseCost (can be used to punish certain motions)
80  double translationlDist; //translational length of the motion
81  double angularDist; //angular length of the motion
82 
83  size_t id;
84 
85 };
86 
88 {
89  //indexed by discrete start theta
90  std::vector<std::vector<Motion> > thetaToMotion;
91  std::vector<Motion> idToMotion;
92  sbpl_spline_primitives::SbplSplineMotionPrimitives primitives;
93  Mobility mobilityConfig;
94 public:
99  PreComputedMotions(const sbpl_spline_primitives::SplinePrimitivesConfig& primitiveConfig,
100  const Mobility& mobilityConfig);
101 
102  void readMotionPrimitives(const sbpl_spline_primitives::SbplSplineMotionPrimitives& primGen,
103  const Mobility& mobilityConfig,
104  double obstGridResolution, double travGridResolution);
105 
106  void computeMotions(double obstGridResolution, double travGridResolution);
107 
108  void setMotionForTheta(const Motion &motion, const DiscreteTheta &theta);
109 
110  void preComputeCost(Motion &motion);
111 
112  const std::vector<Motion> &getMotionForStartTheta(const DiscreteTheta &theta) const;
113 
114  const Motion &getMotion(std::size_t id) const;
115 
116  const sbpl_spline_primitives::SbplSplineMotionPrimitives& getPrimitives() const;
117 
119  static double calculateCurvatureFromRadius(const double r);
120 private:
121 
122  void sampleOnResolution(double gridResolution, base::geometry::Spline2 spline, std::vector< ugv_nav4d::PoseWithCell >& result, std::vector< ugv_nav4d::CellWithPoses >& fullResult);
123 
124  base::Pose2D getPointClosestToCellMiddle(const ugv_nav4d::CellWithPoses& cwp, const double gridResolution);
125 
126 
127  void computeSplinePrimCost(const sbpl_spline_primitives::SplinePrimitive& prim,
128  const Mobility& mobilityConfig, Motion& outMotion) const;
129 
130 };
131 
132 
133 }
Definition: DiscreteTheta.hpp:7
Definition: PreComputedMotions.hpp:29
int xDiff
Definition: PreComputedMotions.hpp:47
Motion(unsigned int numAngles=0)
Definition: PreComputedMotions.hpp:43
std::vector< PoseWithCell > intermediateStepsTravMap
Definition: PreComputedMotions.hpp:59
Type type
Definition: PreComputedMotions.hpp:52
Type
Definition: PreComputedMotions.hpp:36
@ MOV_POINTTURN
Definition: PreComputedMotions.hpp:39
@ MOV_BACKWARD
Definition: PreComputedMotions.hpp:38
@ MOV_LATERAL
Definition: PreComputedMotions.hpp:40
@ MOV_FORWARD
Definition: PreComputedMotions.hpp:37
static double costScaleFactor
Definition: PreComputedMotions.hpp:34
static int calculateCost(double translationalDist, double angularDist, double translationVelocity, double angularVelocity, double costMultiplier)
Definition: PreComputedMotions.cpp:296
DiscreteTheta endTheta
Definition: PreComputedMotions.hpp:49
std::vector< CellWithPoses > fullSplineSamples
Definition: PreComputedMotions.hpp:76
int baseCost
Definition: PreComputedMotions.hpp:78
DiscreteTheta startTheta
Definition: PreComputedMotions.hpp:50
double translationlDist
Definition: PreComputedMotions.hpp:80
int yDiff
Definition: PreComputedMotions.hpp:48
double angularDist
Definition: PreComputedMotions.hpp:81
size_t id
Definition: PreComputedMotions.hpp:83
std::vector< PoseWithCell > intermediateStepsObstMap
Definition: PreComputedMotions.hpp:66
int costMultiplier
Definition: PreComputedMotions.hpp:79
Definition: PreComputedMotions.hpp:88
void setMotionForTheta(const Motion &motion, const DiscreteTheta &theta)
Definition: PreComputedMotions.cpp:190
static double calculateCurvatureFromRadius(const double r)
Definition: PreComputedMotions.cpp:324
void readMotionPrimitives(const sbpl_spline_primitives::SbplSplineMotionPrimitives &primGen, const Mobility &mobilityConfig, double obstGridResolution, double travGridResolution)
Definition: PreComputedMotions.cpp:92
void preComputeCost(Motion &motion)
const Motion & getMotion(std::size_t id) const
Definition: PreComputedMotions.cpp:314
const sbpl_spline_primitives::SbplSplineMotionPrimitives & getPrimitives() const
Definition: PreComputedMotions.cpp:319
void computeMotions(double obstGridResolution, double travGridResolution)
Definition: PreComputedMotions.cpp:20
const std::vector< Motion > & getMotionForStartTheta(const DiscreteTheta &theta) const
Definition: PreComputedMotions.cpp:353
PreComputedMotions(const sbpl_spline_primitives::SplinePrimitivesConfig &primitiveConfig, const Mobility &mobilityConfig)
Definition: PreComputedMotions.cpp:12
Definition: Dijkstra.cpp:8
Definition: PreComputedMotions.hpp:22
maps::grid::Index cell
Definition: PreComputedMotions.hpp:23
std::vector< base::Pose2D > poses
Definition: PreComputedMotions.hpp:24
Definition: Mobility.hpp:12
Definition: PreComputedMotions.hpp:16
maps::grid::Index cell
Definition: PreComputedMotions.hpp:18
base::Pose2D pose
Definition: PreComputedMotions.hpp:17