-
Notifications
You must be signed in to change notification settings - Fork 28
Re-Introduces Occupancy Grid Export #389
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
e729cba
7c3e16f
8fbbebb
f7064e5
1189cb0
eabde95
45c1166
bea3134
d445dbc
2e40884
6923669
4f15f8c
d8686df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ use crate::{ | |
| layers::ZLayer, | ||
| mapf_rse::{MAPFDebugDisplay, NegotiationRequest}, | ||
| site::{Category, LevelElevation, NameOfSite, SiteAssets}, | ||
| workspace::WorkspaceSaver, | ||
| }; | ||
| use bevy::{ | ||
| ecs::{hierarchy::ChildOf, relationship::AncestorIter}, | ||
|
|
@@ -41,9 +42,10 @@ impl Plugin for OccupancyPlugin { | |
| fn build(&self, app: &mut App) { | ||
| app.add_event::<CalculateGridRequest>() | ||
| .add_event::<NegotiationRequest>() | ||
| .add_event::<ExportGridRequest>() | ||
| .init_resource::<MAPFDebugDisplay>() | ||
| .init_resource::<OccupancyInfo>() | ||
| .add_systems(Update, handle_calculate_grid_request); | ||
| .add_systems(Update, (handle_mapf_request, handle_export_request)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -128,6 +130,14 @@ impl GridRange { | |
| } | ||
| } | ||
|
|
||
| pub fn width(&self) -> usize { | ||
| self.min[0].abs_diff(self.max[0]) as usize | ||
| } | ||
|
|
||
| pub fn height(&self) -> usize { | ||
| self.min[1].abs_diff(self.max[1]) as usize | ||
| } | ||
|
|
||
| pub fn include(&mut self, cell: Cell) { | ||
| self.min[0] = self.min[0].min(cell.x); | ||
| self.min[1] = self.min[1].min(cell.y); | ||
|
|
@@ -154,6 +164,9 @@ impl GridRange { | |
| } | ||
| } | ||
|
|
||
| #[derive(Event)] | ||
| pub struct ExportGridRequest(pub f32); | ||
arjo129 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #[derive(Event)] | ||
| pub struct CalculateGridRequest; | ||
|
|
||
|
|
@@ -185,7 +198,50 @@ enum Group { | |
| None, | ||
| } | ||
|
|
||
| fn handle_calculate_grid_request( | ||
| fn handle_export_request( | ||
|
Member
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. I'm generally not too excited about this function since it's pretty much the exact same as the one below, with one line of difference in "what we do after My preference would be to refactor them into a single function, on top of my head I can think of a few ways:
First is quick and easy, second is possibly not a great idea, third would probably be the best but a bit more work to implement.
Member
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. I had done 1 earlier (before having to rewrite the entire PR): #389 (comment) 2 will make the code unnecessarily complex. 3 is a fair deal more of work but probably the correct way to handle it. |
||
| mut request: EventReader<ExportGridRequest>, | ||
| //occupancy_info: Res<OccupancyInfo>, | ||
arjo129 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| robots: Query<Entity, With<Robot>>, | ||
| mut commands: Commands, | ||
| bodies: Query<(Entity, &Mesh3d, &Aabb, &GlobalTransform)>, | ||
| meta: Query<( | ||
| Option<&ChildOf>, | ||
| Option<&Category>, | ||
| Option<&ComputedVisualCue>, | ||
| )>, | ||
| child_of: Query<&ChildOf>, | ||
| levels: Query<Entity, With<LevelElevation>>, | ||
| sites: Query<(), With<NameOfSite>>, | ||
| mut meshes: ResMut<Assets<Mesh>>, | ||
| assets: Res<SiteAssets>, | ||
| grids: Query<Entity, With<Grid>>, | ||
| display_mapf_debug: Res<MAPFDebugDisplay>, | ||
| mut workspace_saver: WorkspaceSaver, | ||
| ) { | ||
| if let Some(export_req) = request.read().last() { | ||
| let grid = CalculateGrid { | ||
| cell_size: export_req.0, | ||
| ignore: robots.iter().collect(), | ||
| ..default() | ||
| }; | ||
| calculate_grid( | ||
| &grid, | ||
| &mut commands, | ||
| &bodies, | ||
| &meta, | ||
| &child_of, | ||
| &levels, | ||
| &sites, | ||
| &mut meshes, | ||
| &assets, | ||
| &grids, | ||
| &display_mapf_debug, | ||
| ); | ||
| workspace_saver.export_occupancy_to_dialog(); | ||
| } | ||
| } | ||
|
|
||
| fn handle_mapf_request( | ||
| mut request: EventReader<CalculateGridRequest>, | ||
| occupancy_info: Res<OccupancyInfo>, | ||
| robots: Query<Entity, With<Robot>>, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.