I recently started my course on ROS2 and i followed a course online. I got through the normal working and RVIZ and now i am working in gazebo simulations. I completed my code and launch file but when i run it my screen is rendered black. I am using ros2 jazzy and the gazebo start up is Harmonic.
The urdf file runs without any errors and other launch files run fine too. I only have the problem with Gazebo sim.
I tried the launch file as shown below
from launch import LaunchDescription
from launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValue
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable, IncludeLaunchDescription, LogInfo
from launch.substitutions import Command, LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource
import os
from pathlib import Path
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
arduinobot_description_dir = get_package_share_directory("arduinobot_des")
model_arg = DeclareLaunchArgument(
name="model",
default_value=os.path.join(get_package_share_directory("arduinobot_des"), "urdf", "arduinobot.urdf.xacro"),
description="Absolute path to the robot urdf file"
)
gazebo_resource_path = SetEnvironmentVariable(
name="GZ_SIM_RESOURCE_PATH",
value=[
str(Path(arduinobot_description_dir).parent.resolve()),
]
)
ros_distro = os.environ["ROS_DISTRO"]
is_ignition = "True" if ros_distro == "humble" else "False"
physics_engine = "" if ros_distro == "humble" else "--physics-engine gz-physics-bullet-featherstone-plugin"
robot_description = ParameterValue(Command([
"xacro ",
LaunchConfiguration("model"),
" is_ignition:=",
is_ignition
]),
value_type = str)
robot_state_publisher_node = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
parameters=[{"robot_description": robot_description,
"use_sim_time": True}]
)
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource([
os.path.join(
get_package_share_directory("ros_gz_sim"),
"launch"
), "/gz_sim.launch.py"]
),
launch_arguments=[
("gz_args", [" -v 4 -r empty.sdf ", physics_engine])
]
)
gz_spawn_entity = Node(
package="ros_gz_sim",
executable="create",
output="screen",
arguments=["-topic", "robot_description",
"-name", "arduinobot"]
)
gz_ros2_bridge = Node(
package="ros_gz_bridge",
executable="parameter_bridge",
arguments=[
"/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock"
]
)
return LaunchDescription([
model_arg,
gazebo_resource_path,
robot_state_publisher_node,
gazebo,
gz_ros2_bridge,
gz_spawn_entity,
])