Jaime Ferreira
Jaime Ferreira

Reputation: 33

Gazebo LiDAR sensor not publishing topic

First let me just say robotics is not my area of study so pardon me for any miss use of terms.
I am building a small self driving diferential robot using a raspberry pi 5 and a lidar sensor.
For now I am just trying to get a ROS2 robot working with gazebo, and so far I have already build a robot that I can control using my keyboard, so now I am trying to integrate the LiDAR.
I am using ROS2 Jazzy Jalisco with Gazebo harmonic, and most of the documentation is for other version which is causing me some issues.
Bellow is URDF file for my robot, where it uses the gz-sim-sensors-system plugin, but when I run this, I can still control the robot on gz but when I run "ros2 topic list" there's no "/scan" or "/lidar" topic to subscribe.
Any help here is appreciated!

<?xml version="1.0"?>

<robot name="differential_drive_robot" xmlns:xacro="http://www.ros.org/wiki/xacro">

    <!-- Robot Parameters -->
    <xacro:property name="PI" value="3.14159265"/>
    <xacro:property name="body_length" value="0.5"/>
    <xacro:property name="body_width" value="0.3"/>
    <xacro:property name="body_height" value="0.1"/>
    <xacro:property name="body_density" value="7850.0"/> <!-- Steel -->
    <xacro:property name="body_mass" value="${body_density * body_length * body_height * body_width}"/>
    <xacro:property name="body_inertia_x" value="${1.0/12.0 * body_mass * (body_height*body_height + body_width*body_width)}"/>
    <xacro:property name="body_inertia_y" value="${1.0/12.0 * body_mass * (body_length*body_length + body_height*body_height)}"/>
    <xacro:property name="body_inertia_z" value="${1.0/12.0 * body_mass * (body_length*body_length + body_width*body_width)}"/>

    <xacro:property name="wheel_radius" value="0.1"/>
    <xacro:property name="wheel_width" value="0.05"/>
    <xacro:property name="wheel_separation" value="${body_width + wheel_width}"/>
    <xacro:property name="wheel_offset" value="${body_length/2 - wheel_radius}"/>
    <xacro:property name="wheel_density" value="900"/> <!-- Ruber -->
    <xacro:property name="wheel_mass" value="${wheel_density * PI * wheel_radius * wheel_radius * wheel_width}"/>
    <xacro:property name="wheel_inertia_x" value="${1.0/12.0 * wheel_mass * (3*wheel_radius*wheel_radius + wheel_width*wheel_width)}"/>
    <xacro:property name="wheel_inertia_y" value="${1.0/12.0 * wheel_mass * (3*wheel_radius*wheel_radius + wheel_width*wheel_width)}"/>
    <xacro:property name="wheel_inertia_z" value="${1.0/2.0 * wheel_mass * wheel_radius * wheel_radius}"/>

    <xacro:property name="caster_radius" value="0.1"/>
    <xacro:property name="caster_offset" value="${body_length/2 - caster_radius}"/>
    <xacro:property name="caster_density" value="0.1"/>
    <xacro:property name="caster_mass" value="${caster_density * 4.0/3.0 * PI * caster_radius * caster_radius * caster_radius}"/>
    <xacro:property name="caster_inertia_x" value="${2.0/5.0 * caster_mass * caster_radius * caster_radius}"/>
    <xacro:property name="caster_inertia_y" value="${2.0/5.0 * caster_mass * caster_radius * caster_radius}"/>
    <xacro:property name="caster_inertia_z" value="${2.0/5.0 * caster_mass * caster_radius * caster_radius}"/>

    <!-- Control Parameters -->    
    <xacro:property name="max_linear_acceleration" value="10"/>

    <!-- Links -->

    <!-- Body Link -->
    <link name="body_link">
        <visual>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
            <geometry>
                <box size="${body_length} ${body_width} ${body_height}"/>
            </geometry>
            <material name="body_material">
                <color rgba="0.25 0.25 0.25 1.0"/>
            </material>
        </visual>
        <collision>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
            <geometry>
                <box size="${body_length} ${body_width} ${body_height}"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="10"/>
            <inertia ixx="${body_inertia_x}" ixy="0.0" ixz="0.0" iyy="${body_inertia_y}" iyz="0" izz="${body_inertia_z}"/>
            <origin xyz="0 0 0" rpy="0 0 0"/>
        </inertial>
    </link>

    <!-- Left Wheel -->
    <link name="left_wheel_link">
        <visual>
            <origin xyz="0.0 0.0 0.0" rpy="1.570795 0.0 0.0"/>
            <geometry>
                <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
            </geometry>
            <material name="wheel_material">
                <color rgba="0.0 0.0 0.0 1.0"/>
            </material>
        </visual>
        <collision>
            <origin xyz="0.0 0.0 0.0" rpy="1.570795 0.0 0.0"/>
            <geometry>
                <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="2"/>
            <inertia ixx="${wheel_inertia_x}" ixy="0.0" ixz="0.0" iyy="${wheel_inertia_y}" iyz="0" izz="${wheel_inertia_z}"/>
            <origin xyz="0.0 0.0 0.0" rpy="1.570795 0.0 0.0"/>
        </inertial>
    </link>

    <!-- Right Wheel -->
    <link name="right_wheel_link">
        <visual>
            <origin xyz="0.0 0.0 0.0" rpy="1.570795 0.0 0.0"/>
            <geometry>
                <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
            </geometry>
            <material name="wheel_material">
                <color rgba="0.0 0.0 0.0 1.0"/>
            </material>
        </visual>
        <collision>
            <origin xyz="0.0 0.0 0.0" rpy="1.570795 0.0 0.0"/>
            <geometry>
                <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="2"/>
            <inertia ixx="${wheel_inertia_x}" ixy="0.0" ixz="0.0" iyy="${wheel_inertia_y}" iyz="0" izz="${wheel_inertia_z}"/>
            <origin xyz="0.0 0.0 0.0" rpy="1.570795 0.0 0.0"/>
        </inertial>
    </link>

    <!-- Caster Wheel -->
    <link name="caster_link">
        <visual>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
            <geometry>
                <sphere radius="${caster_radius}"/>
            </geometry>
            <material name="caster_material">
                <color rgba="0.0 0.0 0.0 1.0"/>
            </material>
        </visual>
        <collision>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
            <geometry>
                <sphere radius="${caster_radius}"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="0.5"/>
            <inertia ixx="${caster_inertia_x}" ixy="0.0" ixz="0.0" iyy="${caster_inertia_y}" iyz="0" izz="${caster_inertia_z}"/>
            <origin xyz="0 0 0" rpy="0 0 0"/>
        </inertial>
    </link>
    
    <!--Lidar Link-->
    <link name="lidar_link">
        <inertial>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <mass value="0.125"/>
            <inertia ixx="0.001"  ixy="0"  ixz="0" iyy="0.001" iyz="0" izz="0.001" />
        </inertial>

        <collision>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
            <cylinder radius="0.0508" length="0.055"/>
            </geometry>
        </collision>

        <visual>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
            <cylinder radius="0.0508" length="0.055"/>
            </geometry>
        </visual>
    </link>




    <!-- Joints -->
    <joint name="lidar_joint" type="fixed">
        <parent link="body_link"/>
        <child link="lidar_link"/>
        <origin xyz="0 0 ${body_height / 2 + 0.055 / 2}" rpy="0 0 0"/>
    </joint>


    <!-- Left Wheel Joint -->
    <joint name="left_wheel_joint" type="continuous">
        <origin xyz="-${wheel_offset} ${wheel_separation/2} -${wheel_radius/2}" rpy="0 0 0"/>
        <parent link="body_link"/>
        <child link="left_wheel_link"/>
        <axis xyz="0 1 0"/>
        <limit effort="100" velocity="10.0"/>
        <dynamics damping="0.1" friction="0.1"/>
    </joint>

    <!-- Right Wheel Joint -->
    <joint name="right_wheel_joint" type="continuous">
        <origin xyz="-${wheel_offset} ${-wheel_separation/2} -${wheel_radius/2}" rpy="0 0 0"/>
        <parent link="body_link"/>
        <child link="right_wheel_link"/>
        <axis xyz="0 1 0"/>
        <limit effort="100" velocity="10.0"/>
        <dynamics damping="0.1" friction="0.1"/>
    </joint>

    <!-- Caster Wheel Joint (fixed) -->
    <joint name="caster_joint" type="fixed">
        <origin xyz="${caster_offset} 0 -${caster_radius/2}" rpy="0 0 0"/>
        <parent link="body_link"/>
        <child link="caster_link"/>
    </joint>




    <!-- Gazebo Parameters -->
    <gazebo reference="body_link">
        <mu1>1.0</mu1>
        <mu2>1.0</mu2>
    </gazebo>

    <gazebo reference="right_wheel_link">
        <mu1>1.0</mu1>
        <mu2>1.0</mu2>
    </gazebo>

    <gazebo reference="left_wheel_link">
        <mu1>1.0</mu1>
        <mu2>1.0</mu2>
    </gazebo>

    <gazebo reference="caster_link">
        <mu1>0.000001</mu1>
        <mu2>0.000001</mu2>
    </gazebo>

    <gazebo reference="lidar_link">
        <sensor name="lidar" type="ray">
            <topic>lidar</topic>
            <always_on>true</always_on>
            <visualize>true</visualize>
            <update_rate>5</update_rate>
            <ray>
            <scan>
                <horizontal>
                <samples>360</samples>
                <resolution>1.000000</resolution>
                <min_angle>0.000000</min_angle>
                <max_angle>6.280000</max_angle>
                </horizontal>
            </scan>
            <range>
                <min>0.120000</min>
                <max>3.5</max>
                <resolution>0.015000</resolution>
            </range>
            <noise>
                <type>gaussian</type>
                <mean>0.0</mean>
                <stddev>0.01</stddev>
            </noise>
            </ray>
            <plugin
                filename="gz-sim-sensors-system"
                name="gz::sim::systems::Sensors">
                <render_engine>ogre2</render_engine>
            </plugin>
        </sensor>
    </gazebo>

    <!-- Gazebo Plugins -->
    <gazebo>
        <plugin filename="gz-sim-diff-drive-system" name="gz::sim::systems::DiffDrive">
            <right_joint>right_wheel_joint</right_joint>
            <left_joint>left_wheel_joint</left_joint>
            <wheel_separation>${wheel_separation}</wheel_separation>
            <wheel_radius>${wheel_radius}</wheel_radius>
            <max_linear_acceleration>${max_linear_acceleration}</max_linear_acceleration>
            <odom_publish_frequency>100</odom_publish_frequency>
            <topic>cmd_vel</topic>
            <odom_topic>odom</odom_topic>
        </plugin>

        <plugin filename="gz-sim-joint-state-publisher-system" name="gz::sim::systems::JointStatePublisher">
            <topic>joint_states</topic>
            <joint_name>right_wheel_joint</joint_name>
            <joint_name>left_wheel_joint</joint_name>
        </plugin>
    </gazebo>

</robot>

Upvotes: 0

Views: 154

Answers (0)

Related Questions