Add distance sensor to drone model in gazebo

How can i add distance sensor to simulation model in gazebo, sub and publish it in ROS. I really hope someone did and helped me

There is already a quadrotor model with lidar installed: PX4-SITL_gazebo/iris_opt_flow.sdf at b968405a617005ba0a793a8b4703913d4c6eff5f · PX4/PX4-SITL_gazebo · GitHub

There are a lot of posts that explain how to publish gazebo messages into ros such as https://answers.gazebosim.org/question/18881/publish-a-gazebo-message-into-a-ros-topic/

Thanks for your feedback, I tried it but I can’t find its topic, I don’t know what I’m doing wrong?

in iris.sdf

    <!--lidar-->
    <include>
      <uri>model://lidar</uri>
      <pose>0 0 -0.05 0 0 0</pose>
    </include>

    <joint name="lidar_joint" type="fixed">
      <parent>iris::base_link</parent>
      <child>lidar::link</child>
    </joint>

plugin of lidar


        <plugin name="LaserPlugin" filename="libgazebo_lidar_plugin.so">
          <robotNamespace>LaseDistance</robotNamespace>
          <min_distance>0.2</min_distance>
          <max_distance>15.0</max_distance>
          <topicName>/sensor_distance/distance</topicName>
          <frameName>/sensor_distance</frameName>
        </plugin>

image

rostopic list 
/clock
/diagnostics
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/performance_metrics
/gazebo/set_link_state
/gazebo/set_model_state
/iris_fpv_cam/usb_cam/camera_info
/iris_fpv_cam/usb_cam/image_raw
/iris_fpv_cam/usb_cam/image_raw/compressed
/iris_fpv_cam/usb_cam/image_raw/compressed/parameter_descriptions
/iris_fpv_cam/usb_cam/image_raw/compressed/parameter_updates
/iris_fpv_cam/usb_cam/image_raw/compressedDepth
/iris_fpv_cam/usb_cam/image_raw/compressedDepth/parameter_descriptions
/iris_fpv_cam/usb_cam/image_raw/compressedDepth/parameter_updates
/iris_fpv_cam/usb_cam/image_raw/theora
/iris_fpv_cam/usb_cam/image_raw/theora/parameter_descriptions
/iris_fpv_cam/usb_cam/image_raw/theora/parameter_updates
/iris_fpv_cam/usb_cam/parameter_descriptions
/iris_fpv_cam/usb_cam/parameter_updates
/mavlink/from
/mavlink/gcs_ip
/mavlink/to
/mavros/actuator_control
/mavros/adsb/send
/mavros/adsb/vehicle
/mavros/altitude
/mavros/battery
/mavros/battery2
/mavros/cam_imu_sync/cam_imu_stamp
/mavros/camera/image_captured
/mavros/companion_process/status
/mavros/debug_value/debug
/mavros/debug_value/debug_vector
/mavros/debug_value/named_value_float
/mavros/debug_value/named_value_int
/mavros/debug_value/send
/mavros/esc_info
/mavros/esc_status
/mavros/esc_telemetry
/mavros/estimator_status
/mavros/extended_state
/mavros/fake_gps/mocap/tf
/mavros/geofence/waypoints
/mavros/global_position/compass_hdg
/mavros/global_position/global
/mavros/global_position/gp_lp_offset
/mavros/global_position/gp_origin
/mavros/global_position/home
/mavros/global_position/local
/mavros/global_position/raw/fix
/mavros/global_position/raw/gps_vel
/mavros/global_position/raw/satellites
/mavros/global_position/rel_alt
/mavros/global_position/set_gp_origin
/mavros/gps_input/gps_input
/mavros/gps_rtk/rtk_baseline
/mavros/gps_rtk/send_rtcm
/mavros/gpsstatus/gps1/raw
/mavros/gpsstatus/gps1/rtk
/mavros/gpsstatus/gps2/raw
/mavros/gpsstatus/gps2/rtk
/mavros/hil/actuator_controls
/mavros/hil/controls
/mavros/hil/gps
/mavros/hil/imu_ned
/mavros/hil/optical_flow
/mavros/hil/rc_inputs
/mavros/hil/state
/mavros/home_position/home
/mavros/home_position/set
/mavros/imu/data
/mavros/imu/data_raw
/mavros/imu/diff_pressure
/mavros/imu/mag
/mavros/imu/static_pressure
/mavros/imu/temperature_baro
/mavros/imu/temperature_imu
/mavros/landing_target/lt_marker
/mavros/landing_target/pose
/mavros/landing_target/pose_in
/mavros/local_position/accel
/mavros/local_position/odom
/mavros/local_position/pose
/mavros/local_position/pose_cov
/mavros/local_position/velocity_body
/mavros/local_position/velocity_body_cov
/mavros/local_position/velocity_local
/mavros/log_transfer/raw/log_data
/mavros/log_transfer/raw/log_entry
/mavros/mag_calibration/report
/mavros/mag_calibration/status
/mavros/manual_control/control
/mavros/manual_control/send
/mavros/mission/reached
/mavros/mission/waypoints
/mavros/mocap/pose
/mavros/mount_control/command
/mavros/mount_control/orientation
/mavros/mount_control/status
/mavros/nav_controller_output
/mavros/obstacle/send
/mavros/odometry/in
/mavros/odometry/out
/mavros/onboard_computer/status
/mavros/param/param_value
/mavros/play_tune
/mavros/px4flow/ground_distance
/mavros/px4flow/raw/optical_flow_rad
/mavros/px4flow/raw/send
/mavros/px4flow/temperature
/mavros/radio_status
/mavros/rallypoint/waypoints
/mavros/rc/in
/mavros/rc/out
/mavros/rc/override
/mavros/setpoint_accel/accel
/mavros/setpoint_attitude/cmd_vel
/mavros/setpoint_attitude/thrust
/mavros/setpoint_position/global
/mavros/setpoint_position/global_to_local
/mavros/setpoint_position/local
/mavros/setpoint_raw/attitude
/mavros/setpoint_raw/global
/mavros/setpoint_raw/local
/mavros/setpoint_raw/target_attitude
/mavros/setpoint_raw/target_global
/mavros/setpoint_raw/target_local
/mavros/setpoint_trajectory/desired
/mavros/setpoint_trajectory/local
/mavros/setpoint_velocity/cmd_vel
/mavros/setpoint_velocity/cmd_vel_unstamped
/mavros/state
/mavros/statustext/recv
/mavros/statustext/send
/mavros/target_actuator_control
/mavros/terrain/report
/mavros/time_reference
/mavros/timesync_status
/mavros/trajectory/desired
/mavros/trajectory/generated
/mavros/trajectory/path
/mavros/tunnel/in
/mavros/tunnel/out
/mavros/vfr_hud
/mavros/vision_pose/pose
/mavros/vision_pose/pose_cov
/mavros/vision_speed/speed_twist_cov
/mavros/wind_estimation
/rosout
/rosout_agg
/tf
/tf_static

@huytd_2910 Gazebo does not automatically publish it’s topic

You can check the gazebo topics with gz topic -l

I tried and but can’t publish to ros topic?

gz topic -l
/gazebo/LaseDistance/iris_fpv_cam/link/lidar
/gazebo/default/atmosphere
/gazebo/default/diagnostics
/gazebo/default/factory
/gazebo/default/factory/light
/gazebo/default/gui
/gazebo/default/gzclient_camera/cmd
/gazebo/default/iris_fpv_cam/baro
/gazebo/default/iris_fpv_cam/camera/link/irlock
/gazebo/default/iris_fpv_cam/fpv_cam/link/camera/cmd
/gazebo/default/iris_fpv_cam/fpv_cam/link/camera/image
/gazebo/default/iris_fpv_cam/fpv_cam/link/wrench
/gazebo/default/iris_fpv_cam/gazebo/command/motor_speed
/gazebo/default/iris_fpv_cam/groundtruth
/gazebo/default/iris_fpv_cam/imu
/gazebo/default/iris_fpv_cam/iris/base_link/wrench
/gazebo/default/iris_fpv_cam/iris/gps0/link/gps
/gazebo/default/iris_fpv_cam/iris/gps0/link/wrench
/gazebo/default/iris_fpv_cam/iris/imu_link/wrench
/gazebo/default/iris_fpv_cam/iris/rotor_0/wrench
/gazebo/default/iris_fpv_cam/iris/rotor_1/wrench
/gazebo/default/iris_fpv_cam/iris/rotor_2/wrench
/gazebo/default/iris_fpv_cam/iris/rotor_3/wrench
/gazebo/default/iris_fpv_cam/lidar/link/laser/scan
/gazebo/default/iris_fpv_cam/lidar/link/wrench
/gazebo/default/iris_fpv_cam/link/gps0
/gazebo/default/iris_fpv_cam/link/lidar
/gazebo/default/iris_fpv_cam/link/sonar
/gazebo/default/iris_fpv_cam/mag
/gazebo/default/iris_fpv_cam/px4flow/link/opticalFlow
/gazebo/default/iris_fpv_cam/sonar/link/default/iris_fpv_cam/sonar/link/sonarsensor_collision/contacts
/gazebo/default/iris_fpv_cam/sonar/link/sonar/sonar
/gazebo/default/iris_fpv_cam/sonar/link/wrench
/gazebo/default/iris_fpv_cam/vision_odom
/gazebo/default/joint
/gazebo/default/light/modify
/gazebo/default/log/control
/gazebo/default/log/status
/gazebo/default/model/info
/gazebo/default/model/modify
/gazebo/default/physics
/gazebo/default/physics/contacts
/gazebo/default/playback_control
/gazebo/default/pose/info
/gazebo/default/pose/local/info
/gazebo/default/pose/modify
/gazebo/default/request
/gazebo/default/response
/gazebo/default/roads
/gazebo/default/scene
/gazebo/default/selection
/gazebo/default/sensor
/gazebo/default/skeleton_pose/info
/gazebo/default/sky
/gazebo/default/undo_redo
/gazebo/default/user_camera/joy_pose
/gazebo/default/user_camera/joy_twist
/gazebo/default/user_camera/pose
/gazebo/default/user_cmd
/gazebo/default/user_cmd_stats
/gazebo/default/video_stream
/gazebo/default/visual
/gazebo/default/wind
/gazebo/default/world_control
/gazebo/default/world_stats
/gazebo/default/world_wind
/gazebo/motor_failure_num
/gazebo/performance_metrics
/gazebo/server/control
/gazebo/world/modify