Skip to content

Commit f342caa

Browse files
committed
Random ball spawn at safe positions, remove ball from world SDF
1 parent 84983b5 commit f342caa

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
<sdf version="1.6">
3+
<model name="ball">
4+
<link name="link">
5+
<inertial><mass>0.1</mass><inertia><ixx>0.0001</ixx><iyy>0.0001</iyy><izz>0.0001</izz></inertia></inertial>
6+
<collision name="collision">
7+
<geometry><sphere><radius>0.1</radius></sphere></geometry>
8+
</collision>
9+
<visual name="visual">
10+
<geometry><sphere><radius>0.1</radius></sphere></geometry>
11+
<material><ambient>1 0.2 0.2 1</ambient><diffuse>1 0.2 0.2 1</diffuse></material>
12+
</visual>
13+
</link>
14+
</model>
15+
</sdf>

ros2_ws/interbotix_xslocobot_descriptions/worlds/locobot_world.sdf

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,5 @@
278278
</link>
279279
</model>
280280

281-
<model name="ball">
282-
<pose>3.0 3.0 0.1 0 0 0</pose>
283-
<link name="link">
284-
<inertial><mass>0.1</mass><inertia><ixx>0.0001</ixx><iyy>0.0001</iyy><izz>0.0001</izz></inertia></inertial>
285-
<collision name="collision">
286-
<geometry><sphere><radius>0.1</radius></sphere></geometry>
287-
</collision>
288-
<visual name="visual">
289-
<geometry><sphere><radius>0.1</radius></sphere></geometry>
290-
<material><ambient>1 0.2 0.2 1</ambient><diffuse>1 0.2 0.2 1</diffuse></material>
291-
</visual>
292-
</link>
293-
</model>
294-
295281
</world>
296282
</sdf>

ros2_ws/locobot_gazebo/launch/locobot_gazebo.launch.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import os
22
import subprocess
3+
import random
4+
5+
# Safe ball spawn positions (clear of obstacles)
6+
SAFE_POSITIONS = [
7+
(3.0, 3.0), (3.0, -3.0), (-3.0, 3.0), (-3.0, -3.0),
8+
(3.5, 0.0), (-3.5, 0.0), (0.0, 3.5), (0.0, -3.5),
9+
(2.0, 3.5), (3.5, 2.0), (-2.0, 3.5), (3.5, -2.0),
10+
]
311
from ament_index_python.packages import get_package_share_directory
412
from launch import LaunchDescription
513
from launch.actions import IncludeLaunchDescription, SetEnvironmentVariable, TimerAction
@@ -128,6 +136,24 @@ def generate_launch_description():
128136
),
129137

130138

139+
TimerAction(
140+
period=6.0,
141+
actions=[
142+
Node(
143+
package='ros_gz_sim',
144+
executable='create',
145+
arguments=[
146+
'-name', 'ball',
147+
'-file', os.path.join(desc_pkg, 'worlds', 'ball.sdf'),
148+
'-x', str((_pos := random.choice(SAFE_POSITIONS))[0]),
149+
'-y', str(_pos[1]),
150+
'-z', '0.1',
151+
],
152+
output='screen',
153+
),
154+
]
155+
),
156+
131157
TimerAction(
132158
period=8.0,
133159
actions=[

0 commit comments

Comments
 (0)