Skip to content

Commit b220833

Browse files
author
bitbots
committed
Variable Robot
1 parent b700b41 commit b220833

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/bitbots_misc/bitbots_bringup/launch/mujoco_simulation.launch.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,28 @@ def generate_domain_bridge_config(robot_domain: int, output_dir: Path) -> Path:
9292
return config_path
9393

9494

95-
def generate_world_xml(num_robots: int, package_share: str) -> Path:
95+
def generate_world_xml(num_robots: int, package_share: str, robot_type: str) -> Path:
9696
"""Generate MuJoCo world XML with the correct number of robots."""
9797
template_path = Path(package_share) / "xml" / "adult_field.xml"
9898
output_path = Path(package_share) / "xml" / "generated_world.xml"
99+
offset = 6 * (1/num_robots) # this makes the offset be the default value when there are 4 robots and increse the less robots there are
99100

100101
with open(template_path) as f:
101102
template = f.read()
102103

103104
# Replace placeholder with actual robot count
104-
world_xml = template.replace("{{NUM_ROBOTS}}", str(num_robots))
105+
world_xml = template.replace("{{NUM_ROBOTS}}", str(num_robots)).replace("{{OFFSET}}", str(offset)).replace("{{ROBOT_TYPE}}", robot_type)
106+
105107

106108
with open(output_path, "w") as f:
107109
f.write(world_xml)
108-
109110
return output_path
110111

111112

112113
def launch_setup(context):
113114
"""Dynamically set up launches based on num_robots."""
114115
num_robots = int(LaunchConfiguration("num_robots").perform(context))
116+
robot_type = str(LaunchConfiguration("robot_type").perform(context))
115117
package_share = get_package_share_directory("bitbots_mujoco_sim")
116118
bridge_config_dir = Path(package_share) / "config" / "domain_bridges"
117119

@@ -122,7 +124,7 @@ def launch_setup(context):
122124
if value: # Only pass if not empty string
123125
teamplayer_args.append(f"{arg_name}:={value}")
124126

125-
world_file = generate_world_xml(num_robots, package_share)
127+
world_file = generate_world_xml(num_robots, package_share, robot_type)
126128

127129
actions = []
128130

@@ -188,8 +190,15 @@ def generate_launch_description():
188190
default_value="1",
189191
description="Number of robots in the simulation",
190192
),
193+
DeclareLaunchArgument(
194+
"robot_type",
195+
default_value="wolfgang",
196+
description="Set the type of robot used (wolfgang, piplus, x02)",
197+
),
191198
]
192199

200+
201+
193202
# Add all teamplayer arguments with empty default (means use teamplayer's default)
194203
for arg_name, description in TEAMPLAYER_ARGS:
195204
declared_args.append(

src/bitbots_simulation/bitbots_mujoco_sim/xml/adult_field.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<light cutoff="100" diffuse="1 1 1" dir="-0 0 -1.3" directional="true" exponent="1" pos="0 0 1.3" specular=".1 .1 .1"/>
2222
<geom material="pitch" name="pitch" pos="0 0 0" size="8 5.5 1" type="plane"/>
2323

24-
<replicate count="{{NUM_ROBOTS}}" sep="_" offset="0.5 0 0">
24+
<replicate count="{{NUM_ROBOTS}}" sep="_" offset="{{OFFSET}} 0 0">
2525
<frame pos="1 -4.5 0.0" euler="0 0 1.57">
26-
<attach model="wolfgang" prefix="robot_"/>
26+
<attach model="{{ROBOT_TYPE}}" prefix="robot_"/>
2727
</frame>
2828
</replicate>
2929

0 commit comments

Comments
 (0)