-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/precompute pathing #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
20c169b
0921637
3b06f1b
cda0872
48d1e39
d05b022
7e6634d
e1d5239
d2eb3e6
a6f8cd6
6deacc4
d1d8190
0bb8a9e
2111203
25e5f6b
d98f28a
6604c87
93f6ad0
b873ba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -619,7 +619,23 @@ RRTPoint getCurrentLoc(std::shared_ptr<MissionState> state) { | |
| return RRTPoint(start_xyz, start_angle); | ||
| } | ||
|
|
||
| MissionPath generateInitialPath(std::shared_ptr<MissionState> state) { | ||
| double calculateFinalAngle( | ||
| const MissionPath& path, | ||
| const std::optional<CartesianConverter<GPSProtoVec>> cartesianConverter) { | ||
|
|
||
| const auto& coords = path.get(); | ||
| if (coords.size() < 2) { | ||
| return 0.0; // should probably either have angle between now and point | ||
| // or use assert for force size >=2 | ||
| } | ||
|
|
||
| XYZCoord pt1 = cartesianConverter->toXYZ(coords[coords.size() - 2]); | ||
| XYZCoord pt2 = cartesianConverter->toXYZ(coords[coords.size() - 1]); | ||
|
Comment on lines
+626
to
+627
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I think its fine to keep it optional for our sanity, but then we should check the optional has a value before dereferencing it here |
||
|
|
||
| return std::atan2(pt2.y - pt1.y, pt2.x - pt1.x); | ||
| } | ||
|
|
||
| std::vector<GPSCoord> generateInitialPath(std::shared_ptr<MissionState> state) { | ||
| // first waypoint is start | ||
|
|
||
| // the other waypoitns is the goals | ||
|
|
@@ -653,13 +669,53 @@ MissionPath generateInitialPath(std::shared_ptr<MissionState> state) { | |
| output_coords.push_back(state->getCartesianConverter()->toLatLng(waypoint)); | ||
| } | ||
|
|
||
| return MissionPath(MissionPath::Type::FORWARD, output_coords); | ||
| return output_coords; | ||
| } | ||
|
|
||
| std::vector<GPSCoord> | ||
| generateNextWaypointPath(std::shared_ptr<MissionState> state, double start_angle) { | ||
| if (state->mission_params.getWaypoints().size() < 1) { | ||
| loguru::set_thread_name("Static Pathing"); | ||
| LOG_F(ERROR, "Not enough waypoints to generate a path, requires >=1, num waypoints: %s", | ||
| std::to_string(state->mission_params.getWaypoints().size()).c_str()); | ||
| return {}; | ||
| } | ||
|
|
||
| std::vector<XYZCoord> goals = state->mission_params.getWaypoints(); | ||
|
|
||
| if (state->config.pathing.rrt.generate_deviations) { | ||
| Environment mapping_bounds(state->mission_params.getAirdropBoundary(), {}, {}, goals, {}); | ||
| goals = generateRankedNewGoalsList(goals, mapping_bounds)[0]; | ||
| } | ||
|
|
||
| RRTPoint start(goals.back(), start_angle); | ||
|
|
||
| // add buffer to the start point so that we dont loopty loop | ||
| double buffer_m = state->config.pathing.upload_distance_buffer_m; | ||
| if (buffer_m > 0.0) { | ||
| start.coord.x += buffer_m * std::cos(start_angle); | ||
| start.coord.y += buffer_m * std::sin(start_angle); | ||
| } | ||
|
|
||
| RRT rrt(start, goals, SEARCH_RADIUS, state->mission_params.getFlightBoundary(), state->config, | ||
| {}, {}); | ||
|
|
||
| rrt.run(); | ||
|
|
||
| std::vector<XYZCoord> path = rrt.getPointsToGoal(); | ||
|
|
||
| std::vector<GPSCoord> output_coords; | ||
| for (const XYZCoord &waypoint : path) { | ||
| output_coords.push_back(state->getCartesianConverter()->toLatLng(waypoint)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unsafe optional reference with |
||
| } | ||
|
|
||
| return output_coords; | ||
| } | ||
|
|
||
| MissionPath generateSearchPath(std::shared_ptr<MissionState> state) { | ||
| std::vector<GPSCoord> generateSearchPath(std::shared_ptr<MissionState> state, double start_angle) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing a bounds check for the waypoints? I might be misinterpreting it but why is there a bounds check in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of waypoints must be greater than 1 for the code to execute generate SearchPath. |
||
| std::vector<GPSCoord> gps_coords; | ||
| if (state->config.pathing.coverage.method == AirdropCoverageMethod::Enum::FORWARD) { | ||
| RRTPoint start(state->mission_params.getWaypoints().back(), 0); | ||
| RRTPoint start(state->mission_params.getWaypoints().back(), start_angle); | ||
| double scan_radius = state->config.pathing.coverage.camera_vision_m; | ||
|
|
||
| ForwardCoveragePathing pathing(start, scan_radius, | ||
|
|
@@ -670,19 +726,19 @@ MissionPath generateSearchPath(std::shared_ptr<MissionState> state) { | |
| gps_coords.push_back(state->getCartesianConverter()->toLatLng(coord)); | ||
| } | ||
|
|
||
| return MissionPath(MissionPath::Type::FORWARD, gps_coords); | ||
| return gps_coords; | ||
| } else { // hover | ||
| HoverCoveragePathing pathing(state); | ||
|
|
||
| for (const auto &coord : pathing.run()) { | ||
| gps_coords.push_back(state->getCartesianConverter()->toLatLng(coord)); | ||
| } | ||
| return MissionPath(MissionPath::Type::HOVER, gps_coords, | ||
| state->config.pathing.coverage.hover.hover_time_s); | ||
| return gps_coords; | ||
| } | ||
| } | ||
|
|
||
| MissionPath generateAirdropApproach(std::shared_ptr<MissionState> state, const GPSCoord &goal) { | ||
| std::vector<GPSCoord> | ||
| generateAirdropApproach(std::shared_ptr<MissionState> state, const GPSCoord &goal) { | ||
| std::shared_ptr<MavlinkClient> mav = state->getMav(); | ||
| /* | ||
| Note: this function was neutered right before we attempted to fly at the 2024 competition | ||
|
|
@@ -725,5 +781,5 @@ MissionPath generateAirdropApproach(std::shared_ptr<MissionState> state, const G | |
| // gps_path.push_back(goal); | ||
| // gps_path.push_back(goal); | ||
|
|
||
| return MissionPath(MissionPath::Type::FORWARD, gps_path); | ||
| return gps_path; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cartesianConvertercan be a reference to avoid a copy