@@ -95,6 +95,32 @@ elif [ "$PX4_SIMULATOR" = "gz" ] || [ "$(param show -q SIM_GZ_EN)" = "1" ]; then
95
95
echo " INFO [init] Starting gz gui"
96
96
${gz_command} ${gz_sub_command} -g > /dev/null 2>&1 &
97
97
fi
98
+
99
+ # Wait for Gazebo world to be ready before proceeding
100
+ check_scene_info () {
101
+ SERVICE_INFO=$( ${gz_command} service -i --service " /world/${PX4_GZ_WORLD} /scene/info" 2>&1 )
102
+ if echo " $SERVICE_INFO " | grep -q " Service providers" ; then
103
+ return 0
104
+ else
105
+ return 1
106
+ fi
107
+ }
108
+
109
+ ATTEMPTS=30
110
+ while [ $ATTEMPTS -gt 0 ]; do
111
+ if check_scene_info; then
112
+ echo " INFO [init] Gazebo world is ready"
113
+ break
114
+ fi
115
+ ATTEMPTS=$(( ATTEMPTS- 1 ))
116
+ if [ $ATTEMPTS -eq 0 ]; then
117
+ echo " ERROR [init] Timed out waiting for Gazebo world"
118
+ exit 1
119
+ fi
120
+ echo " INFO [init] Waiting for Gazebo world..."
121
+ sleep 1
122
+ done
123
+
98
124
else
99
125
# Gazebo is already running
100
126
echo " INFO [init] gazebo already running world: ${gz_world} "
@@ -131,51 +157,26 @@ elif [ "$PX4_SIMULATOR" = "gz" ] || [ "$(param show -q SIM_GZ_EN)" = "1" ]; then
131
157
--reptype gz.msgs.Boolean --timeout 5000 \
132
158
--req " sdf_filename: \" ${PX4_GZ_MODELS} /${MODEL_NAME} /model.sdf\" , name: \" ${MODEL_NAME_INSTANCE} \" , allow_renaming: false${POSE_ARG} " > /dev/null 2>&1
133
159
160
+ # Wait for model to spawn
161
+ sleep 1
162
+
134
163
# Start gz_bridge
135
164
if ! gz_bridge start -w " ${PX4_GZ_WORLD} " -n " ${MODEL_NAME_INSTANCE} " ; then
136
165
echo " ERROR [init] gz_bridge failed to start and spawn model"
137
166
exit 1
138
167
fi
139
168
140
169
# Set physics parameters for faster-than-realtime simulation if needed
141
- check_scene_info () {
142
- SERVICE_INFO=$( ${gz_command} service -i --service " /world/${PX4_GZ_WORLD} /scene/info" 2>&1 )
143
- if echo " $SERVICE_INFO " | grep -q " Service providers" ; then
144
- return 0
145
- else
146
- return 1
147
- fi
148
- }
149
-
150
- ATTEMPTS=30
151
- while [ $ATTEMPTS -gt 0 ]; do
152
- if check_scene_info; then
153
- echo " INFO [init] Gazebo world is ready"
154
- break
155
- fi
156
- ATTEMPTS=$(( ATTEMPTS- 1 ))
157
- if [ $ATTEMPTS -eq 0 ]; then
158
- echo " ERROR [init] Timed out waiting for Gazebo world"
159
- exit 1
160
- fi
161
- echo " INFO [init] Waiting for Gazebo world..."
162
- sleep 1
163
- done
164
-
165
170
if [ -n " ${PX4_SIM_SPEED_FACTOR} " ]; then
166
171
echo " INFO [init] Setting simulation speed factor: ${PX4_SIM_SPEED_FACTOR} "
167
172
${gz_command} service -s " /world/${PX4_GZ_WORLD} /set_physics" --reqtype gz.msgs.Physics \
168
173
--reptype gz.msgs.Boolean --timeout 5000 \
169
174
--req " real_time_factor: ${PX4_SIM_SPEED_FACTOR} " > /dev/null 2>&1
170
175
fi
171
176
172
-
173
177
# Set up camera to follow the model if requested
174
178
if [ -n " ${PX4_GZ_FOLLOW} " ]; then
175
179
176
- # Wait for model to spawn
177
- sleep 1
178
-
179
180
echo " INFO [init] Setting camera to follow ${MODEL_NAME_INSTANCE} "
180
181
181
182
# Set camera to follow the model
0 commit comments