Gazebo - ashBabu/Utilities GitHub Wiki
Gazebo has been undergoing major revisions. The old gazebo is called gazebo classic and the newer one is called gazebo with fortress, garden and harmonic (being the latest as on 15 Mar 2024) subtags.
If the following is NOT provided in the .launch.py
file, robot_state_publisher
throws error
import os
if "GZ_SIM_RESOURCE_PATH" in os.environ:
gz_sim_resource_path = os.environ["GZ_SIM_RESOURCE_PATH"]
if "SDF_PATH" in os.environ:
sdf_path = os.environ["SDF_PATH"]
os.environ["SDF_PATH"] = sdf_path + ":" + gz_sim_resource_path
else:
os.environ["SDF_PATH"] = gz_sim_resource_path
[robot_state_publisher-3] Error [Utils.cc:176] Tried to use callback in sdf::findFile(), but the callback is empty. Did you call sdf::setFindCallback()?Error [Utils.cc:176] Tried to use callback in sdf::findFile(), but the callback is empty. Did you call sdf::setFindCallback()?[ERROR] [1736263895.620012837] [sdformat_urdf]: Unable to find uri[model://diff_drive]
[robot_state_publisher-3] [ERROR] [1736263895.621460566] [sdformat_urdf]: Unable to find uri[model://okdo]
[robot_state_publisher-3] [ERROR] [1736263895.621467999] [sdformat_urdf]: A model must have at least one link.
[robot_state_publisher-3] [ERROR] [1736263895.621470236] [sdformat_urdf]: A model must have at least one link.
[robot_state_publisher-3] [ERROR] [1736263895.621472112] [sdformat_urdf]: FrameAttachedToGraph error: scope context name[] does not match __model__ or world.
[robot_state_publisher-3] [ERROR] [1736263895.621474878] [sdformat_urdf]: relative_to name[okdo_sensor] specified by joint with name[diff_drive_okdo_joint] does not match a nested model, link, joint, or frame name in model with name[diff_drive_with_ouster_camera].
[robot_state_publisher-3] [ERROR] [1736263895.621477233] [sdformat_urdf]: PoseRelativeToGraph error, Vertex with name [diff_drive_with_ouster_camera::diff_drive_okdo_joint] is disconnected; it should have 1 incoming edge in MODEL relative_to graph.
export GZ_SIM_RESOURCE_PATH=$GZ_SIM_RESOURCE_PATH:/home/ash/gazebo_models/common_models
The common_models
directory has 3 other folders, grass_plane
, home_1
and sun_2
where each of these directories contain a model.config
and a model.sdf
. So this can be called in another world.sdf
file as follows
<?xml version="1.0" ?>
<sdf version="1.5">
<world name="default">
<physics name="1ms" type="ignore">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<!-- A global light source -->
<include>
<uri>model://sun_2</uri>
</include>
<!-- A ground plane -->
<include>
<static>true</static>
<pose>0 0 0 0 0 0</pose>
<uri>model://grass_plane</uri>
</include>
<include>
<static>true</static>
<pose>-37.5 -37.5 0.01 0 0 0</pose>
<uri>model://home_1</uri>
</include>
</world>
</sdf>
-
gz sim world.sdf
should bring up gazebo
- ros_topic_name: "tf"
gz_topic_name: "/gz/tf"
ros_type_name: "tf2_msgs/msg/TFMessage"
gz_type_name: "gz.msgs.Pose_V"
direction: GZ_TO_ROS
The above will publish odom --> base_link
to ROS and can be visualized using ros2 run rqt_tftree rqt_tftree
- Model building can be done using the sdformat
- An example
<?xml version="1.0" ?>
<sdf version="1.9">
<world name="map">
<physics name="1ms" type="ignore">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<plugin filename="gz-sim-physics-system"
name="gz::sim::systems::Physics">
</plugin>
<plugin filename="gz-sim-sensors-system"
name="gz::sim::systems::Sensors">
<render_engine>ogre2</render_engine>
</plugin>
<plugin filename="gz-sim-user-commands-system"
name="gz::sim::systems::UserCommands">
</plugin>
<plugin filename="gz-sim-scene-broadcaster-system"
name="gz::sim::systems::SceneBroadcaster">
</plugin>
<plugin filename="gz-sim-air-pressure-system"
name="gz::sim::systems::AirPressure">
</plugin>
<plugin filename="gz-sim-air-speed-system"
name="gz::sim::systems::AirSpeed">
</plugin>
<plugin filename="gz-sim-altimeter-system"
name="gz::sim::systems::Altimeter">
</plugin>
<plugin filename="gz-sim-imu-system"
name="gz::sim::systems::Imu">
</plugin>
<plugin filename="gz-sim-magnetometer-system"
name="gz::sim::systems::Magnetometer">
</plugin>
<plugin filename="gz-sim-navsat-system"
name="gz::sim::systems::NavSat">
</plugin>
<scene>
<ambient>1.0 1.0 1.0</ambient>
<background>0.8 0.8 0.8</background>
<sky></sky>
</scene>
<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
<pose>0 0 10 0 0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.8 0.8 0.8 1</specular>
<attenuation>
<range>1000</range>
<constant>0.9</constant>
<linear>0.01</linear>
<quadratic>0.001</quadratic>
</attenuation>
<direction>-0.5 0.1 -0.9</direction>
</light>
<spherical_coordinates>
<latitude_deg>-35.3632621</latitude_deg>
<longitude_deg>149.1652374</longitude_deg>
<elevation>10.0</elevation>
<heading_deg>0</heading_deg>
<surface_model>EARTH_WGS84</surface_model>
</spherical_coordinates>
<model name="floor">
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>100 100</size>
</plane>
</geometry>
<surface>
<friction>
<ode>
<mu>100</mu>
<mu2>50</mu2>
</ode>
</friction>
</surface>
</collision>
<visual name="visual">
<cast_shadows>false</cast_shadows>
<geometry>
<plane>
<normal>0 0 1</normal>
<size>100 100</size>
</plane>
</geometry>
<material>
<diffuse>0.8 0.3 0.3 1</diffuse>
</material>
</visual>
</link>
</model>
<model name='maze'>
<static>1</static>
<link name='Wall_0'>
<pose degrees="true">-10 -10 0 0 0 90</pose>
<collision name='Wall_0_Collision'>
<pose>10 0 1.25 0 0 0</pose>
<geometry>
<box>
<size>20 0.2 4</size>
</box>
</geometry>
</collision>
<visual name='Wall_0_Visual'>
<pose>10 0 1.25 0 0 0</pose>
<geometry>
<box>
<size>20 0.2 4</size>
</box>
</geometry>
<material>
<diffuse>0.699999988 0.699999988 0.699999988 1</diffuse>
</material>
</visual>
</link>
<link name='Wall_6'>
<pose>-4 -4 0 0 0 0</pose>
<collision name='Wall_6_Collision'>
<pose>7 0 1.25 0 0 0</pose>
<geometry>
<box>
<size>14 0.2 4</size>
</box>
</geometry>
</collision>
<visual name='Wall_6_Visual'>
<pose>7 0 1.25 0 0 0</pose>
<geometry>
<box>
<size>14 0.2 4</size>
</box>
</geometry>
<material>
<diffuse>0.699999988 0.699999988 0.699999988 1</diffuse>
</material>
</visual>
</link>
</model>
<include>
<pose degrees="true">0 0 0.5 0 0 0</pose>
<!-- <uri>model://iris_with_ouster</uri>-->
<uri>package://sensor_simulation/models/iris_with_ouster/model.sdf</uri>
<name>iris_with_ouster</name>
</include>
</world>
</sdf>
- Open the folder containing the above sdf file
- In a terminal window,
gz sim name.sdf
(for gazebo garden, harmonic) orign gazebo name.sdf
(for gazebo fortress) - To list topics,
gz/ign topic -l
- To echo topics,
gz/ign topic -e -t topic_name
- Gazebo shows only published topics and no subscribed topics
- Needs
ros_gz_bridge
to have communication between gazebo and ros. More info