Skip to content

Commit a62b230

Browse files
committed
Backport changes
1 parent a4c0322 commit a62b230

File tree

4 files changed

+708
-303
lines changed

4 files changed

+708
-303
lines changed

terrain_navigation_ros/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ find_package(catkin REQUIRED dynamic_reconfigure)
77
generate_dynamic_reconfigure_options(
88
cfg/HeightRateTuning.cfg
99
)
10+
find_package(Boost REQUIRED COMPONENTS serialization system filesystem)
11+
1012

1113
find_package(catkin REQUIRED COMPONENTS
1214
roscpp
@@ -41,8 +43,8 @@ include_directories(
4143
add_library(${PROJECT_NAME}
4244
src/terrain_planner.cpp
4345
)
44-
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_gencfg)
45-
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${GeographicLib_LIBRARIES} ${OMPL_LIBRARIES})
46+
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_gencfg ${Boost_LIBRARIES})
47+
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${GeographicLib_LIBRARIES} ${OMPL_LIBRARIES} ${Boost_LIBRARIES})
4648

4749
add_executable(terrain_planner_node
4850
src/terrain_planner_node.cpp

terrain_navigation_ros/include/terrain_navigation_ros/terrain_planner.h

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
#include <ros/callback_queue.h>
4545
#include <ros/ros.h>
46-
#include "terrain_planner/terrain_ompl_rrt.h"
4746

4847
#include <geographic_msgs/GeoPointStamped.h>
4948
#include <geometry_msgs/PoseStamped.h>
@@ -52,6 +51,7 @@
5251
#include <mavros_msgs/State.h>
5352
#include <mavros_msgs/WaypointList.h>
5453
#include <nav_msgs/Path.h>
54+
#include <sensor_msgs/NavSatFix.h>
5555
#include <visualization_msgs/Marker.h>
5656

5757
#include <Eigen/Dense>
@@ -61,10 +61,10 @@
6161

6262
#include "terrain_planner/common.h"
6363
#include "terrain_planner/maneuver_library.h"
64-
// #include "terrain_planner/mcts_planner.h"
65-
#include "terrain_planner/primitive_planner.h"
64+
#include "terrain_planner/terrain_ompl_rrt.h"
6665
#include "terrain_planner/visualization.h"
6766

67+
#include <planner_msgs/SetPlannerState.h>
6868
#include <planner_msgs/SetService.h>
6969
#include <planner_msgs/SetString.h>
7070
#include <planner_msgs/SetVector3.h>
@@ -73,11 +73,11 @@
7373
#include <GeographicLib/LocalCartesian.hpp>
7474

7575
#include <dynamic_reconfigure/server.h>
76-
#include "terrain_navigation_ros/HeightRateTuningConfig.h"
76+
// #include "terrain_navigation_ros/HeightRateTuningConfig.h"
7777

78-
enum class SETPOINT_MODE { STATE, PATH };
78+
enum class PLANNER_MODE { ACTIVE_MAPPING, EMERGENCY_ABORT, EXHAUSTIVE, GLOBAL, GLOBAL_REPLANNING, RANDOM, RETURN };
7979

80-
enum class PLANNER_MODE { EXHAUSTIVE, MCTS, GLOBAL, GLOBAL_REPLANNING, RANDOM };
80+
enum class PLANNER_STATE { HOLD = 1, NAVIGATE = 2, ROLLOUT = 3, ABORT = 4, RETURN = 5 };
8181

8282
class TerrainPlanner {
8383
public:
@@ -88,9 +88,11 @@ class TerrainPlanner {
8888
private:
8989
void cmdloopCallback(const ros::TimerEvent &event);
9090
void statusloopCallback(const ros::TimerEvent &event);
91+
void plannerloopCallback(const ros::TimerEvent &event);
9192
void publishTrajectory(std::vector<Eigen::Vector3d> trajectory);
9293
// States from vehicle
93-
void mavposeCallback(const geometry_msgs::PoseStamped &msg);
94+
void mavLocalPoseCallback(const geometry_msgs::PoseStamped &msg);
95+
void mavGlobalPoseCallback(const sensor_msgs::NavSatFix &msg);
9496
void mavtwistCallback(const geometry_msgs::TwistStamped &msg);
9597
void mavstateCallback(const mavros_msgs::State::ConstPtr &msg);
9698
void mavGlobalOriginCallback(const geographic_msgs::GeoPointStampedConstPtr &msg);
@@ -103,9 +105,11 @@ class TerrainPlanner {
103105
bool setCurrentSegmentCallback(planner_msgs::SetService::Request &req, planner_msgs::SetService::Response &res);
104106
bool setStartLoiterCallback(planner_msgs::SetService::Request &req, planner_msgs::SetService::Response &res);
105107
bool setPlanningCallback(planner_msgs::SetVector3::Request &req, planner_msgs::SetVector3::Response &res);
108+
bool setPlannerStateCallback(planner_msgs::SetPlannerState::Request &req,
109+
planner_msgs::SetPlannerState::Response &res);
106110
bool setPathCallback(planner_msgs::SetVector3::Request &req, planner_msgs::SetVector3::Response &res);
107111

108-
void MapPublishOnce();
112+
void MapPublishOnce(const ros::Publisher &pub, const grid_map::GridMap &map);
109113
void publishPositionHistory(ros::Publisher &pub, const Eigen::Vector3d &position,
110114
std::vector<geometry_msgs::PoseStamped> &history_vector);
111115
void publishPositionSetpoints(const ros::Publisher &pub, const Eigen::Vector3d &position,
@@ -117,20 +121,45 @@ class TerrainPlanner {
117121
void publishVelocityMarker(const ros::Publisher &pub, const Eigen::Vector3d &position,
118122
const Eigen::Vector3d &velocity);
119123
void publishPathSetpoints(const Eigen::Vector3d &position, const Eigen::Vector3d &velocity);
120-
void publishVehiclePose(const Eigen::Vector3d &position, const Eigen::Vector4d &attitude);
121-
void publishViewpoints(std::vector<ViewPoint> &viewpoint_vector);
122124
void publishPathSegments(ros::Publisher &pub, Path &trajectory);
123125
void publishGoal(const ros::Publisher &pub, const Eigen::Vector3d &position, const double radius,
124126
Eigen::Vector3d color = Eigen::Vector3d(1.0, 1.0, 0.0), std::string name_space = "goal");
127+
void publishRallyPoints(const ros::Publisher &pub, const std::vector<Eigen::Vector3d> &positions, const double radius,
128+
Eigen::Vector3d color = Eigen::Vector3d(1.0, 1.0, 0.0),
129+
std::string name_space = "rallypoints");
130+
visualization_msgs::Marker getGoalMarker(const int id, const Eigen::Vector3d &position, const double radius,
131+
const Eigen::Vector3d color);
125132
void generateCircle(const Eigen::Vector3d end_position, const Eigen::Vector3d end_velocity,
126133
const Eigen::Vector3d center_pos, PathSegment &trajectory);
127-
void dynamicReconfigureCallback(terrain_navigation_ros::HeightRateTuningConfig &config, uint32_t level);
134+
// void dynamicReconfigureCallback(terrain_navigation_ros::HeightRateTuningConfig &config, uint32_t level);
135+
136+
void printPlannerState(PLANNER_STATE state) {
137+
switch (state) {
138+
case PLANNER_STATE::HOLD: // Fallthrough
139+
std::cout << "PLANNER_STATE::HOLD" << std::endl;
140+
break;
141+
case PLANNER_STATE::NAVIGATE: // Fallthrough
142+
std::cout << "PLANNER_STATE::NAVIGATE" << std::endl;
143+
break;
144+
case PLANNER_STATE::ROLLOUT:
145+
std::cout << "PLANNER_STATE::ROLLOUT" << std::endl;
146+
break;
147+
case PLANNER_STATE::ABORT:
148+
std::cout << "PLANNER_STATE::ABORT" << std::endl;
149+
break;
150+
}
151+
}
152+
153+
Eigen::Vector4d rpy2quaternion(double roll, double pitch, double yaw);
154+
155+
PLANNER_STATE finiteStateMachine(const PLANNER_STATE current_state, const PLANNER_STATE query_state);
128156

129157
ros::NodeHandle nh_;
130158
ros::NodeHandle nh_private_;
131159
ros::Publisher vehicle_path_pub_;
132160
ros::Publisher grid_map_pub_;
133161
ros::Publisher vehicle_pose_pub_;
162+
ros::Publisher camera_pose_pub_;
134163
ros::Publisher posehistory_pub_;
135164
ros::Publisher referencehistory_pub_;
136165
ros::Publisher position_setpoint_pub_;
@@ -139,13 +168,16 @@ class TerrainPlanner {
139168
ros::Publisher path_target_pub_;
140169
ros::Publisher planner_status_pub_;
141170
ros::Publisher goal_pub_;
171+
ros::Publisher rallypoint_pub_;
142172
ros::Publisher candidate_goal_pub_;
143173
ros::Publisher candidate_start_pub_;
144174
ros::Publisher viewpoint_pub_;
175+
ros::Publisher planned_viewpoint_pub_;
145176
ros::Publisher tree_pub_;
146177
ros::Publisher vehicle_velocity_pub_;
147178
ros::Publisher path_segment_pub_;
148-
ros::Subscriber mavpose_sub_;
179+
ros::Subscriber mavlocalpose_sub_;
180+
ros::Subscriber mavglobalpose_sub_;
149181
ros::Subscriber mavtwist_sub_;
150182
ros::Subscriber mavstate_sub_;
151183
ros::Subscriber mavmission_sub_;
@@ -160,42 +192,49 @@ class TerrainPlanner {
160192
ros::ServiceServer setplanning_serviceserver_;
161193
ros::ServiceServer updatepath_serviceserver_;
162194
ros::ServiceServer setcurrentsegment_serviceserver_;
195+
ros::ServiceServer setplannerstate_service_server_;
163196
ros::ServiceClient msginterval_serviceclient_;
164197

165-
ros::Timer cmdloop_timer_, statusloop_timer_;
198+
ros::Timer cmdloop_timer_, statusloop_timer_, plannerloop_timer_;
166199
ros::Time plan_time_;
167200
ros::Time last_triggered_time_;
168201
Eigen::Vector3d goal_pos_{Eigen::Vector3d(0.0, 0.0, 20.0)};
169202
Eigen::Vector3d start_pos_{Eigen::Vector3d(0.0, 0.0, 20.0)};
203+
Eigen::Vector3d home_position_{Eigen::Vector3d(0.0, 0.0, 20.0)};
204+
double home_position_radius_{0.0};
170205
Eigen::Vector3d tracking_error_{Eigen::Vector3d::Zero()};
206+
ros::CallbackQueue plannerloop_queue_;
171207
ros::CallbackQueue statusloop_queue_;
172208
ros::CallbackQueue cmdloop_queue_;
209+
std::unique_ptr<ros::AsyncSpinner> plannerloop_spinner_;
173210
std::unique_ptr<ros::AsyncSpinner> statusloop_spinner_;
174211
std::unique_ptr<ros::AsyncSpinner> cmdloop_spinner_;
175212

176-
dynamic_reconfigure::Server<terrain_navigation_ros::HeightRateTuningConfig> server;
177-
dynamic_reconfigure::Server<terrain_navigation_ros::HeightRateTuningConfig>::CallbackType f;
213+
// dynamic_reconfigure::Server<terrain_navigation_ros::HeightRateTuningConfig> server;
214+
// dynamic_reconfigure::Server<terrain_navigation_ros::HeightRateTuningConfig>::CallbackType f;
178215

179-
SETPOINT_MODE setpoint_mode_{SETPOINT_MODE::STATE};
180216
PLANNER_MODE planner_mode_{PLANNER_MODE::EXHAUSTIVE};
217+
PLANNER_STATE planner_state_{PLANNER_STATE::HOLD};
218+
PLANNER_STATE query_planner_state_{PLANNER_STATE::HOLD};
181219

182220
std::shared_ptr<ManeuverLibrary> maneuver_library_;
183-
// std::shared_ptr<MctsPlanner> mcts_planner_;
184-
std::shared_ptr<PrimitivePlanner> primitive_planner_;
185221
std::shared_ptr<TerrainMap> terrain_map_;
222+
186223
std::shared_ptr<fw_planning::spaces::DubinsAirplaneStateSpace> dubins_state_space_;
187224
// std::shared_ptr<ViewUtilityMap> viewutility_map_;
188225
std::shared_ptr<TerrainOmplRrt> global_planner_;
189226
std::shared_ptr<Profiler> planner_profiler_;
190227
Path reference_primitive_;
191228
Path candidate_primitive_;
229+
Path rollout_primitive_;
192230
mavros_msgs::State current_state_;
193231
std::optional<GeographicLib::LocalCartesian> enu_;
194232

195233
std::mutex goal_mutex_; // protects g_i
196234

197235
std::vector<Eigen::Vector3d> vehicle_position_history_;
198236
std::vector<ViewPoint> added_viewpoint_list;
237+
std::vector<ViewPoint> planned_viewpoint_list;
199238
std::vector<geometry_msgs::PoseStamped> posehistory_vector_;
200239
std::vector<geometry_msgs::PoseStamped> referencehistory_vector_;
201240
std::vector<ViewPoint> viewpoints_;
@@ -204,11 +243,14 @@ class TerrainPlanner {
204243
Eigen::Vector4d vehicle_attitude_{Eigen::Vector4d(1.0, 0.0, 0.0, 0.0)};
205244
Eigen::Vector3d last_planning_position_{Eigen::Vector3d::Zero()};
206245
Eigen::Vector3d previous_start_position_{Eigen::Vector3d::Zero()};
246+
Eigen::Vector3d previous_return_start_position_{Eigen::Vector3d::Zero()};
207247
Eigen::Vector3d mission_loiter_center_{Eigen::Vector3d::Zero()};
208248

249+
std::vector<Eigen::Vector3d> rally_points;
250+
209251
// Altitude tracking loop parameters
210252
/// TODO: This needs to be handed over to TECS
211-
double K_z_{0.5};
253+
double K_z_{2.0};
212254
double cruise_speed_{20.0};
213255
double max_climb_rate_control_{5.0};
214256

@@ -229,6 +271,8 @@ class TerrainPlanner {
229271
bool map_initialized_{false};
230272
bool planner_enabled_{false};
231273
bool problem_updated_{true};
274+
bool found_solution_{false};
275+
bool found_return_solution_{false};
232276
};
233277

234278
#endif
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/****************************************************************************
2+
*
3+
* Copyright (c) 2023 Jaeyoung Lim. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
* 3. Neither the name terrain-navigation nor the names of its contributors may be
16+
* used to endorse or promote products derived from this software
17+
* without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
****************************************************************************/
33+
34+
#ifndef TERRAIN_NAVIGATION_ROS_VISUALIZATION_H
35+
#define TERRAIN_NAVIGATION_ROS_VISUALIZATION_H
36+
37+
#include <ros/ros.h>
38+
#include <Eigen/Dense>
39+
40+
#include <geometry_msgs/Pose.h>
41+
#include <visualization_msgs/Marker.h>
42+
#include <visualization_msgs/MarkerArray.h>
43+
44+
inline geometry_msgs::Point toPoint(const Eigen::Vector3d &p) {
45+
geometry_msgs::Point position;
46+
position.x = p(0);
47+
position.y = p(1);
48+
position.z = p(2);
49+
return position;
50+
}
51+
52+
inline void publishVehiclePose(const ros::Publisher pub, const Eigen::Vector3d &position,
53+
const Eigen::Vector4d &attitude, std::string mesh_resource_path) {
54+
Eigen::Vector4d mesh_attitude =
55+
quatMultiplication(attitude, Eigen::Vector4d(std::cos(M_PI / 2), 0.0, 0.0, std::sin(M_PI / 2)));
56+
geometry_msgs::Pose vehicle_pose = vector3d2PoseMsg(position, mesh_attitude);
57+
visualization_msgs::Marker marker;
58+
marker.header.stamp = ros::Time::now();
59+
marker.header.frame_id = "map";
60+
marker.type = visualization_msgs::Marker::MESH_RESOURCE;
61+
marker.ns = "my_namespace";
62+
marker.mesh_resource = "package://terrain_planner/" + mesh_resource_path;
63+
marker.scale.x = 10.0;
64+
marker.scale.y = 10.0;
65+
marker.scale.z = 10.0;
66+
marker.color.a = 0.5; // Don't forget to set the alpha!
67+
marker.color.r = 0.5;
68+
marker.color.g = 0.5;
69+
marker.color.b = 0.5;
70+
marker.pose = vehicle_pose;
71+
pub.publish(marker);
72+
}
73+
74+
inline visualization_msgs::Marker Viewpoint2MarkerMsg(int id, ViewPoint &viewpoint,
75+
Eigen::Vector3d color = Eigen::Vector3d(0.0, 0.0, 1.0)) {
76+
double scale{15}; // Size of the viewpoint markers
77+
visualization_msgs::Marker marker;
78+
marker.header.frame_id = "map";
79+
marker.header.stamp = ros::Time();
80+
marker.ns = "my_namespace";
81+
marker.id = id;
82+
marker.type = visualization_msgs::Marker::LINE_LIST;
83+
marker.action = visualization_msgs::Marker::ADD;
84+
const Eigen::Vector3d position = viewpoint.getCenterLocal();
85+
std::vector<geometry_msgs::Point> points;
86+
std::vector<Eigen::Vector3d> corner_ray_vectors = viewpoint.getCornerRayVectors();
87+
std::vector<Eigen::Vector3d> vertex;
88+
for (auto &corner_ray : corner_ray_vectors) {
89+
vertex.push_back(position + scale * corner_ray);
90+
}
91+
92+
for (size_t i = 0; i < vertex.size(); i++) {
93+
points.push_back(toPoint(position)); // Viewpoint center
94+
points.push_back(toPoint(vertex[i]));
95+
points.push_back(toPoint(vertex[i]));
96+
points.push_back(toPoint(vertex[(i + 1) % vertex.size()]));
97+
}
98+
99+
marker.points = points;
100+
marker.pose.orientation.x = 0.0;
101+
marker.pose.orientation.y = 0.0;
102+
marker.pose.orientation.z = 0.0;
103+
marker.pose.orientation.w = 1.0;
104+
marker.scale.x = 1.0;
105+
marker.scale.y = 1.0;
106+
marker.scale.z = 1.0;
107+
marker.color.a = 1.0; // Don't forget to set the alpha!
108+
marker.color.r = color(0);
109+
marker.color.g = color(1);
110+
marker.color.b = color(2);
111+
return marker;
112+
}
113+
114+
inline void publishCameraView(const ros::Publisher pub, const Eigen::Vector3d &position,
115+
const Eigen::Vector4d &attitude) {
116+
visualization_msgs::Marker marker;
117+
ViewPoint viewpoint(-1, position, attitude);
118+
marker = Viewpoint2MarkerMsg(viewpoint.getIndex(), viewpoint);
119+
pub.publish(marker);
120+
}
121+
122+
inline void publishViewpoints(const ros::Publisher pub, std::vector<ViewPoint> &viewpoint_vector,
123+
Eigen::Vector3d color = Eigen::Vector3d(0.0, 0.0, 1.0)) {
124+
visualization_msgs::MarkerArray msg;
125+
126+
std::vector<visualization_msgs::Marker> marker;
127+
visualization_msgs::Marker mark;
128+
mark.action = visualization_msgs::Marker::DELETEALL;
129+
marker.push_back(mark);
130+
msg.markers = marker;
131+
pub.publish(msg);
132+
133+
std::vector<visualization_msgs::Marker> viewpoint_marker_vector;
134+
int i = 0;
135+
for (auto viewpoint : viewpoint_vector) {
136+
viewpoint_marker_vector.insert(viewpoint_marker_vector.begin(), Viewpoint2MarkerMsg(i, viewpoint, color));
137+
i++;
138+
}
139+
msg.markers = viewpoint_marker_vector;
140+
pub.publish(msg);
141+
}
142+
143+
#endif

0 commit comments

Comments
 (0)