-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added main optimization loop for local path with Ceres. No tunning pe…
…rformed
- Loading branch information
1 parent
2a02afe
commit 7d01fea
Showing
9 changed files
with
438 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
include/local_planner_optimizer/ceres_constraint_dist_to_obstacle.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef CERES_CONSTRAINTS_DIST_TO_OBSTACLE | ||
#define CERES_CONSTRAINTS_DIST_TO_OBSTACLE | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include "utils/ros/ROSInterfaces.hpp" | ||
#include "utils/SaveDataVariantToFile.hpp" | ||
#include "utils/misc.hpp" | ||
#include "utils/geometry_utils.hpp" | ||
#include "utils/metrics.hpp" | ||
#include <ros/ros.h> | ||
|
||
#include <heuristic_planners/Vec3i.h> | ||
#include <heuristic_planners/CoordinateList.h> | ||
|
||
#include "Grid3D/local_grid3d.hpp" | ||
|
||
#include <ceres/ceres.h> | ||
|
||
using ceres::SizedCostFunction; | ||
using ceres::CostFunction; | ||
using ceres::Problem; | ||
using ceres::Solve; | ||
using ceres::Solver; | ||
|
||
class ObstacleDistanceCostFunctor : public SizedCostFunction<1, 3> | ||
{ | ||
public: | ||
ObstacleDistanceCostFunctor(Local_Grid3d* grid_, double weight): g_3D(grid_), weight_(weight) | ||
{} | ||
|
||
virtual ~ObstacleDistanceCostFunctor(void) | ||
{} | ||
|
||
virtual bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const | ||
{ | ||
residuals[0] = 0; | ||
float x = parameters[0][0] * g_3D->m_resolution; | ||
float y = parameters[0][1] * g_3D->m_resolution; | ||
float z = parameters[0][2] * g_3D->m_resolution; | ||
float dist_; | ||
if(g_3D->isIntoMap(x, y, z)) | ||
{ | ||
TrilinearParams p = g_3D->computeDistInterpolation(x, y, z); | ||
dist_ = p.a0 + p.a1*x + p.a2*y + p.a3*z + p.a4*x*y + p.a5*x*z + p.a6*y*z + p.a7*x*y*z; | ||
if(fabsf(dist_) > 0.01) | ||
residuals[0] = 1/dist_; | ||
else | ||
residuals[0] = 100.0; | ||
if (jacobians != nullptr && jacobians[0] != nullptr) | ||
{ | ||
int cte = -1/(dist_*dist_); | ||
jacobians[0][0] = cte*(p.a1 + p.a4*y + p.a5*z + p.a7*y*z); | ||
jacobians[0][1] = cte*(p.a2 + p.a4*x + p.a6*z + p.a7*x*z); | ||
jacobians[0][2] = cte*(p.a3 + p.a5*x + p.a6*y + p.a7*x*y); | ||
} | ||
} | ||
else // This might give an error | ||
{ | ||
std::cout << "Ceres found point outside map" << std::endl; | ||
if (jacobians != nullptr && jacobians[0] != nullptr) | ||
{ | ||
jacobians[0][0] = 0.0; | ||
jacobians[0][1] = 0.0; | ||
jacobians[0][2] = 0.0; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
double weight_; | ||
Local_Grid3d* g_3D; | ||
|
||
private: | ||
}; | ||
|
||
#endif |
51 changes: 51 additions & 0 deletions
51
include/local_planner_optimizer/ceres_constraint_path_length.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef CERES_CONSTRAINTS_PATH_LEGTH | ||
#define CERES_CONSTRAINTS_PATH_LEGTH | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include "utils/ros/ROSInterfaces.hpp" | ||
#include "utils/SaveDataVariantToFile.hpp" | ||
#include "utils/misc.hpp" | ||
#include "utils/geometry_utils.hpp" | ||
#include "utils/metrics.hpp" | ||
#include <ros/ros.h> | ||
|
||
#include <heuristic_planners/Vec3i.h> | ||
#include <heuristic_planners/CoordinateList.h> | ||
|
||
#include "Grid3D/local_grid3d.hpp" | ||
|
||
#include <ceres/ceres.h> | ||
|
||
using ceres::AutoDiffCostFunction; | ||
using ceres::CostFunction; | ||
using ceres::Problem; | ||
using ceres::Solve; | ||
using ceres::Solver; | ||
|
||
class PathLengthFunctor { | ||
|
||
public: | ||
PathLengthFunctor(double weight): weight_(weight) {} | ||
|
||
template <typename T> | ||
bool operator()(const T* const stateWP1, const T* const stateWP2, T* residual) const { | ||
|
||
T dx = stateWP2[0] - stateWP1[0]; | ||
T dy = stateWP2[1] - stateWP1[1]; | ||
T dz = stateWP2[2] - stateWP1[2]; | ||
|
||
residual[0] = weight_* (dx * dx + dy * dy + dz * dz); | ||
|
||
return true; | ||
} | ||
|
||
double weight_; | ||
|
||
private: | ||
|
||
|
||
}; | ||
|
||
#endif |
51 changes: 51 additions & 0 deletions
51
include/local_planner_optimizer/ceres_constraint_wp_equidistance.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef CERES_CONSTRAINTS_WP_EQUIDISTANCE | ||
#define CERES_CONSTRAINTS_WP_EQUIDISTANCE | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include "utils/ros/ROSInterfaces.hpp" | ||
#include "utils/SaveDataVariantToFile.hpp" | ||
#include "utils/misc.hpp" | ||
#include "utils/geometry_utils.hpp" | ||
#include "utils/metrics.hpp" | ||
#include <ros/ros.h> | ||
|
||
#include <heuristic_planners/Vec3i.h> | ||
#include <heuristic_planners/CoordinateList.h> | ||
|
||
#include "Grid3D/local_grid3d.hpp" | ||
|
||
#include <ceres/ceres.h> | ||
|
||
using ceres::AutoDiffCostFunction; | ||
using ceres::CostFunction; | ||
using ceres::Problem; | ||
using ceres::Solve; | ||
using ceres::Solver; | ||
|
||
class EquidistanceFunctor { | ||
|
||
public: | ||
EquidistanceFunctor(double d_target, double weight): d_target_(d_target), weight_(weight) {} | ||
|
||
template <typename T> | ||
bool operator()(const T* const stateWP1, const T* const stateWP2, T* residual) const { | ||
|
||
T dx = stateWP2[0] - stateWP1[0]; | ||
T dy = stateWP2[1] - stateWP1[1]; | ||
T dz = stateWP2[2] - stateWP1[2]; | ||
|
||
residual[0] = weight_* (dx * dx + dy * dy + dz * dz - T(d_target_)); | ||
|
||
return true; | ||
} | ||
|
||
double d_target_, weight_; | ||
|
||
private: | ||
|
||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef CERESOPT_HPP | ||
#define CERESOPT_HPP | ||
|
||
#include <iostream> | ||
#include "utils/ros/ROSInterfaces.hpp" | ||
#include "utils/SaveDataVariantToFile.hpp" | ||
#include "utils/misc.hpp" | ||
#include "utils/geometry_utils.hpp" | ||
#include "utils/metrics.hpp" | ||
#include <ros/ros.h> | ||
|
||
#include <heuristic_planners/Vec3i.h> | ||
#include <heuristic_planners/CoordinateList.h> | ||
|
||
#include "Grid3D/local_grid3d.hpp" | ||
|
||
#include <ceres/ceres.h> | ||
|
||
#include "local_planner_optimizer/ceres_constraint_dist_to_obstacle.hpp" | ||
#include "local_planner_optimizer/ceres_constraint_wp_equidistance.hpp" | ||
#include "local_planner_optimizer/ceres_constraint_path_length.hpp" | ||
|
||
using ceres::AutoDiffCostFunction; | ||
using ceres::NumericDiffCostFunction; | ||
using ceres::CENTRAL; | ||
using ceres::FORWARD; | ||
using ceres::RIDDERS; | ||
using ceres::CostFunction; | ||
using ceres::Problem; | ||
using ceres::Solve; | ||
using ceres::Solver; | ||
using ceres::LossFunction; | ||
using ceres::CauchyLoss; | ||
|
||
struct parameterBlockWP{ | ||
double parameter[3]; | ||
}; | ||
|
||
namespace Ceresopt{ | ||
Planners::utils::CoordinateList ceresOptimizer(Planners::utils::CoordinateList initial_path, Local_Grid3d &_grid); | ||
} | ||
|
||
|
||
#endif // CERESOPT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.