Skip to content
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

Add flag to skip calculating and setting camera pose #523

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions rmf_building_map_tools/building_map/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def generate_nav_graphs(self):
nav_graphs[f'{i}'] = g
return nav_graphs

def generate_sdf_world(self, template_file):
def generate_sdf_world(self, template_file, skip_camera_pose):
""" Return an etree of this Building in SDF starting from a template"""
if template_file == "":
template_name = 'gz_world.sdf'
Expand Down Expand Up @@ -474,18 +474,20 @@ def generate_sdf_world(self, template_file):
crs_ele.text = self.global_transform.crs_name

gui_ele = world.find('gui')
c = self.center()
# Transforming camera to account for offsets if
# not in reference_image mode and when a floor polygon is defined.
if self.global_transform and c != (0, 0):
camera_pose = f'{c[0] - self.global_transform.x} \
{c[1]-20 - self.global_transform.y} 10 0 0.6 1.57'
else:
camera_pose = f'{c[0]} {c[1]-20} 10 0 0.6 1.57'
# add floor-toggle GUI plugin parameters
plugin_ele = gui_ele.find('.//plugin[@filename="MinimalScene"]')
camera_pose_ele = plugin_ele.find('camera_pose')
camera_pose_ele.text = camera_pose

if not skip_camera_pose:
c = self.center()
# Transforming camera to account for offsets if
# not in reference_image mode and when a floor polygon is defined.
if self.global_transform and c != (0, 0):
camera_pose = f'{c[0] - self.global_transform.x} \
{c[1]-20 - self.global_transform.y} 10 0 0.6 1.57'
else:
camera_pose = f'{c[0]} {c[1]-20} 10 0 0.6 1.57'
# add floor-toggle GUI plugin parameters
plugin_ele = gui_ele.find('.//plugin[@filename="MinimalScene"]')
camera_pose_ele = plugin_ele.find('camera_pose')
camera_pose_ele.text = camera_pose

toggle_floors_ele = SubElement(
gui_ele,
Expand Down
5 changes: 3 additions & 2 deletions rmf_building_map_tools/building_map/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def generate_sdf(
input_filename,
output_filename,
output_models_dir,
template_file
template_file,
skip_camera_pose
):
print('generating {} from {}'.format(output_filename, input_filename))

Expand All @@ -41,7 +42,7 @@ def generate_sdf(
building.generate_sdf_models(output_models_dir)

# generate a top-level SDF for convenience
sdf = building.generate_sdf_world(template_file)
sdf = building.generate_sdf_world(template_file, skip_camera_pose)

indent_etree(sdf)
sdf_str = str(ElementToString(sdf), 'utf-8')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
shared_parser.add_argument("--TEMPLATE_WORLD_FILE", type=str, default="",
help="Specify the template for"
+ " the base simulation.")
shared_parser.add_argument("--SKIP_CAMERA_POSE", action="store_true",
help="Skips calculating and setting the initial "
+ "camera view pose. This flag should only be used "
+ "if the template SDF file already has the camera "
+ "pose defined.")
# Create subparsers for Gazebo and Nav generation
gazebo_parser = subparsers.add_parser(
'gazebo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def main():
args.INPUT,
args.OUTPUT_WORLD,
args.OUTPUT_MODEL_DIR,
args.TEMPLATE_WORLD_FILE
args.TEMPLATE_WORLD_FILE,
args.SKIP_CAMERA_POSE
)

if args.command == "nav":
Expand Down
Loading