64 gradx_ =
new float[xs * ys];
65 grady_ =
new float[xs * ys];
68 bool GradientPath::getPath(
float* potential,
double start_x,
double start_y,
double goal_x,
double goal_y, std::vector<std::pair<float, float> >& path) {
69 std::pair<float, float> current;
73 float dx = goal_x - (int)goal_x;
74 float dy = goal_y - (int)goal_y;
76 memset(
gradx_, 0, ns *
sizeof(
float));
77 memset(
grady_, 0, ns *
sizeof(
float));
82 double nx = stc %
xs_ + dx, ny = stc /
xs_ + dy;
84 if (fabs(nx - start_x) < .5 && fabs(ny - start_y) < .5) {
85 current.first = start_x;
86 current.second = start_y;
87 path.push_back(current);
91 if (stc < xs_ || stc >
xs_ * ys_ -
xs_)
93 printf(
"[PathCalc] Out of bounds\n");
102 path.push_back(current);
104 bool oscillation_detected =
false;
105 int npath = path.size();
106 if (npath > 2 && path[npath - 1].first == path[npath - 3].first
107 && path[npath - 1].second == path[npath - 3].second) {
108 ROS_DEBUG(
"[PathCalc] oscillation detected, attempting fix.");
109 oscillation_detected =
true;
112 int stcnx = stc +
xs_;
113 int stcpx = stc -
xs_;
119 || oscillation_detected) {
120 ROS_DEBUG(
"[Path] Pot fn boundary, following grid (%0.1f/%d)", potential[stc], (
int) path.size());
123 int minp = potential[stc];
125 if (potential[st] < minp) {
126 minp = potential[st];
130 if (potential[st] < minp) {
131 minp = potential[st];
135 if (potential[st] < minp) {
136 minp = potential[st];
140 if (potential[st] < minp) {
141 minp = potential[st];
145 if (potential[st] < minp) {
146 minp = potential[st];
150 if (potential[st] < minp) {
151 minp = potential[st];
155 if (potential[st] < minp) {
156 minp = potential[st];
160 if (potential[st] < minp) {
161 minp = potential[st];
172 ROS_DEBUG(
"[PathCalc] No path found, high potential");
188 float x1 = (1.0 - dx) *
gradx_[stc] + dx *
gradx_[stc + 1];
189 float x2 = (1.0 - dx) *
gradx_[stcnx] + dx *
gradx_[stcnx + 1];
190 float x = (1.0 - dy) * x1 + dy * x2;
191 float y1 = (1.0 - dx) *
grady_[stc] + dx *
grady_[stc + 1];
192 float y2 = (1.0 - dx) *
grady_[stcnx] + dx *
grady_[stcnx + 1];
193 float y = (1.0 - dy) * y1 + dy * y2;
197 "[Path] %0.2f,%0.2f %0.2f,%0.2f %0.2f,%0.2f %0.2f,%0.2f; final x=%.3f, y=%.3f\n",
gradx_[stc],
grady_[stc],
gradx_[stc+1],
grady_[stc+1],
gradx_[stcnx],
grady_[stcnx],
gradx_[stcnx+1],
grady_[stcnx+1], x, y);
200 if (x == 0.0 && y == 0.0) {
272 float cv = potential[n];
280 else if (potential[n + 1] <
POT_HIGH)
293 dx += potential[n - 1] - cv;
295 dx += cv - potential[n + 1];
299 dy += potential[n -
xs_] - cv;
301 dy += cv - potential[n +
xs_];
305 float norm = hypot(dx, dy);
void setSize(int xs, int ys)
unsigned char lethal_cost_
float gradCell(float *potential, int n)
TFSIMD_FORCE_INLINE const tfScalar & y() const
GradientPath(PotentialCalculator *p_calc)
int getIndex(int x, int y)
TFSIMD_FORCE_INLINE const tfScalar & x() const
virtual void setSize(int xs, int ys)
bool getPath(float *potential, double start_x, double start_y, double end_x, double end_y, std::vector< std::pair< float, float > > &path)