Skip to content

Commit ca0d682

Browse files
renan028corot
authored andcommitted
g2o jazzy compatibility
1 parent 94abd58 commit ca0d682

File tree

7 files changed

+52
-16
lines changed

7 files changed

+52
-16
lines changed

teb_local_planner/include/teb_local_planner/g2o_types/edge_kinematics.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class EdgeKinematicsDiffDrive : public BaseTebBinaryEdge<2, double, VertexPose,
129129
double dd_error_2 = deltaS[1]*sin1;
130130
double dd_dev = penaltyBoundFromBelowDerivative(dd_error_1+dd_error_2, 0,0);
131131

132-
double dev_nh_abs = g2o::sign( ( cos(conf1->theta())+cos(conf2->theta()) ) * deltaS[1] -
132+
133+
double dev_nh_abs = sign( ( cos(conf1->theta())+cos(conf2->theta()) ) * deltaS[1] -
133134
( sin(conf1->theta())+sin(conf2->theta()) ) * deltaS[0] );
134135

135136
// conf1

teb_local_planner/include/teb_local_planner/g2o_types/edge_obstacle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class EdgeObstacle : public BaseTebUnaryEdge<1, const Obstacle*, VertexPose>
136136
double aux1 = -fabs(aux0) / dist;
137137
double dev_norm_x = deltaS[0]*aux1;
138138
double dev_norm_y = deltaS[1]*aux1;
139-
140-
double aux2 = cos(angdiff) * g2o::sign(aux0);
139+
140+
double aux2 = cos(angdiff) * sign(aux0);
141141
double aux3 = aux2 / dist_squared;
142142
double dev_proj_x = aux3 * deltaS[1] * dist;
143143
double dev_proj_y = -aux3 * deltaS[0] * dist;

teb_local_planner/include/teb_local_planner/misc.h

+37
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,43 @@ inline double fast_sigmoid(double x)
100100
return x / (1 + fabs(x));
101101
}
102102

103+
/**
104+
* sign function. (g2o::sign)
105+
* @return the sign of x. +1 for x > 0, -1 for x < 0, 0 for x == 0
106+
*/
107+
template <typename T>
108+
inline int sign(T x) {
109+
if (x > 0)
110+
return 1;
111+
else if (x < 0)
112+
return -1;
113+
else
114+
return 0;
115+
}
116+
117+
/**
118+
* average two angles
119+
*/
120+
inline double average_angle(double theta1, double theta2) {
121+
double x, y;
122+
123+
x = std::cos(theta1) + std::cos(theta2);
124+
y = std::sin(theta1) + std::sin(theta2);
125+
if (x == 0 && y == 0)
126+
return 0;
127+
else
128+
return std::atan2(y, x);
129+
}
130+
131+
/**
132+
* normalize the angle
133+
*/
134+
inline double normalize_theta(double theta) {
135+
const double result = fmod(theta + M_PI, 2.0 * M_PI);
136+
if (result <= 0.0) return result + M_PI;
137+
return result - M_PI;
138+
}
139+
103140
/**
104141
* @brief Calculate Euclidean distance between two 2D point datatypes
105142
* @param point1 object containing fields x and y

teb_local_planner/include/teb_local_planner/pose_se2.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#ifndef POSE_SE2_H_
4040
#define POSE_SE2_H_
4141

42-
#include <g2o/stuff/misc.h>
43-
4442
#include <Eigen/Core>
4543
#include "teb_local_planner/misc.h"
4644
#include <geometry_msgs/msg/pose.hpp>
@@ -254,7 +252,7 @@ class PoseSE2
254252
void scale(double factor)
255253
{
256254
_position *= factor;
257-
_theta = g2o::normalize_theta( _theta*factor );
255+
_theta = normalize_theta( _theta*factor );
258256
}
259257

260258
/**
@@ -266,7 +264,7 @@ class PoseSE2
266264
{
267265
_position.coeffRef(0) += pose_as_array[0];
268266
_position.coeffRef(1) += pose_as_array[1];
269-
_theta = g2o::normalize_theta( _theta + pose_as_array[2] );
267+
_theta = normalize_theta( _theta + pose_as_array[2] );
270268
}
271269

272270
/**
@@ -279,7 +277,7 @@ class PoseSE2
279277
void averageInPlace(const PoseSE2& pose1, const PoseSE2& pose2)
280278
{
281279
_position = (pose1._position + pose2._position)/2;
282-
_theta = g2o::average_angle(pose1._theta, pose2._theta);
280+
_theta = average_angle(pose1._theta, pose2._theta);
283281
}
284282

285283
/**
@@ -292,7 +290,7 @@ class PoseSE2
292290
*/
293291
static PoseSE2 average(const PoseSE2& pose1, const PoseSE2& pose2)
294292
{
295-
return PoseSE2( (pose1._position + pose2._position)/2 , g2o::average_angle(pose1._theta, pose2._theta) );
293+
return PoseSE2( (pose1._position + pose2._position)/2 , average_angle(pose1._theta, pose2._theta) );
296294
}
297295

298296
/**
@@ -310,7 +308,7 @@ class PoseSE2
310308
_position.x() = new_x;
311309
_position.y() = new_y;
312310
if (adjust_theta)
313-
_theta = g2o::normalize_theta(_theta+angle);
311+
_theta = normalize_theta(_theta+angle);
314312
}
315313

316314
///@}
@@ -341,7 +339,7 @@ class PoseSE2
341339
PoseSE2& operator+=(const PoseSE2& rhs)
342340
{
343341
_position += rhs._position;
344-
_theta = g2o::normalize_theta(_theta + rhs._theta);
342+
_theta = normalize_theta(_theta + rhs._theta);
345343
return *this;
346344
}
347345

@@ -362,7 +360,7 @@ class PoseSE2
362360
PoseSE2& operator-=(const PoseSE2& rhs)
363361
{
364362
_position -= rhs._position;
365-
_theta = g2o::normalize_theta(_theta - rhs._theta);
363+
_theta = normalize_theta(_theta - rhs._theta);
366364
return *this;
367365
}
368366

teb_local_planner/src/optimal_planner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ void TebOptimalPlanner::extractVelocity(const PoseSE2& pose1, const PoseSE2& pos
11131113
Eigen::Vector2d conf1dir( cos(pose1.theta()), sin(pose1.theta()) );
11141114
// translational velocity
11151115
double dir = deltaS.dot(conf1dir);
1116-
vx = (double) g2o::sign(dir) * deltaS.norm()/dt;
1116+
vx = (double) sign(dir) * deltaS.norm()/dt;
11171117
vy = 0;
11181118
}
11191119
else // holonomic robot

teb_local_planner/src/recovery_behaviors.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <limits>
4242
#include <functional>
4343
#include <numeric>
44-
#include <g2o/stuff/misc.h>
44+
#include "teb_local_planner/misc.h"
4545

4646
namespace teb_local_planner
4747
{
@@ -99,7 +99,7 @@ bool FailureDetector::detect(double v_eps, double omega_eps)
9999
{
100100
v_mean += buffer_[i].v;
101101
omega_mean += buffer_[i].omega;
102-
if ( i>0 && g2o::sign(buffer_[i].omega) != g2o::sign(buffer_[i-1].omega) )
102+
if ( i>0 && sign(buffer_[i].omega) != sign(buffer_[i-1].omega) )
103103
++omega_zero_crossings;
104104
}
105105
v_mean /= n;

teb_local_planner/src/teb_local_planner_ros.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ double TebLocalPlannerROS::convertTransRotVelToSteeringAngle(double v, double om
939939
double radius = v/omega;
940940

941941
if (fabs(radius) < min_turning_radius)
942-
radius = double(g2o::sign(radius)) * min_turning_radius;
942+
radius = double(sign(radius)) * min_turning_radius;
943943

944944
return std::atan(wheelbase / radius);
945945
}

0 commit comments

Comments
 (0)