3

I am trying to create an one line laser sensor to project in a object and being capable to visualize the laser over a camera image on Gazebo simulation environment but I am not being able to make it work.

The only example I found in internet was this on Gazebo answers but unfortunately it is not working and not even generating some ERROR LOG. Does anyone already made a line laser visible on camera images for Gazebo?

Below is the example found on link above.

    <gazebo reference="your_link">
        <projector name="projector_wg6802418">
            <pose>0 0 0 0 0 ${pi/2}</pose>
            <texture>your_img.png</texture>
            <fov>0.5</fov>
            <near_clip>1</near_clip>
            <far_clip>10</far_clip>
         </projector>
    </gazebo>
    <gazebo>
         <plugin name="projector" filename="libgazebo_ros_projector.so">
             <projector>projector_wg6802418</projector>
             <alwaysOn>true</alwaysOn>
             <updateRate>10.0</updateRate>
             <!-- Apparently the 2 lines below does not affect anything -->
             <textureName></textureName>
             <filterTextureName></filterTextureName>
             <!-- end -->
             <textureTopicName>/projector/image</textureTopicName>
             <projectorTopicName>/projector/projector</projectorTopicName>
         </plugin>
    </gazebo>

3 Answers3

0

Maybe what you should try to do is add a new joint and link to your URDF file, like explained here http://gazebosim.org/tutorials?tut=ros_gzplugins. After that, you have to add your plugin to your gazebo file, so it can import the URDF and xacro files.

Plugin:

  <joint name="hokuyo_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="0 0 ${height3 - axel_offset/2}" rpy="0 0 0"/>
    <parent link="link3"/>
    <child link="hokuyo_link"/>
  </joint>

  <!-- Hokuyo Laser -->
  <link name="hokuyo_link">
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
    <box size="0.1 0.1 0.1"/>
      </geometry>
    </collision>

Gazebo file:

<gazebo reference="hokuyo_link">
    <sensor type="gpu_ray" name="head_hokuyo_sensor">
      <pose>0 0 0 0 0 0</pose>
      <visualize>false</visualize>
      <update_rate>40</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>720</samples>
            <resolution>1</resolution>
            <min_angle>-1.570796</min_angle>
            <max_angle>1.570796</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.10</min>
          <max>30.0</max>
          <resolution>0.01</resolution>
        </range>
        <noise>
          <type>gaussian</type>
          <!-- Noise parameters based on published spec for Hokuyo laser
               achieving "+-30mm" accuracy at range < 10m.  A mean of 0.0m and
               stddev of 0.01m will put 99.7% of samples within 0.03m of the true
               reading. -->
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_gpu_laser.so">
        <topicName>/rrbot/laser/scan</topicName>
        <frameName>hokuyo_link</frameName>
      </plugin>
    </sensor>
  </gazebo>

You can change the according to your needs. As for the tag, when true a "a semi-translucent laser ray is visualized within the scanning zone", as mentioned by Gazebo tutorials.

Don't know if you wish measure the distance, but if you do, and if the obstacle is in front of the laser FOV, you should print the mid value of the ranges[] array in LaserScan, like this:

from sensor_msgs.msg import LaserScan

def callback(data):

   distance = data.ranges[360]
   print(distance)

def listener():

   rospy.init_node(node_nome)
   rospy.Subscriber('/scan',callback)
   rospy.spin()

if __name__ == '__main__':
   listener()
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Thanks for your time, but this ray sensor does not appear on camera image, it is visible just on Gazebo GUI, but not visible to others sensors. – Daniel Regner Aug 19 '20 at 17:10
0

I find a way to work it.

I am using a gazebo sensor called projection as code present below but when you call the texture you must add it to gazebo root files. As I am using Gazebo 7 I create a texture and move it to folder /usr/share/gazebo-7/media/materials/textures and it works as it should.

I am able to project a texture over objects surfaces and being able to see this texture projected at camera sensor.

    <gazebo reference="projector_sensor_link">
        <!--sensor type="projector" name="projector_tester"-->
        <projector name="projector_test">
            <pose>0 0 0 0 0 0</pose>
            <texture>your_texture.png</texture>
            <fov>${fov}</fov>
            <near_clip>0.1</near_clip>
            <far_clip>10</far_clip>
        </projector>
    </gazebo>
0

There is a projector.world gazebo world file in /usr/share/gazebo-11/worlds, it shows everything.

Interestingly, the projection works for "both" sides of the objects, not only on the side of the projector.

For creating a "linear laser" (I mean, which creates a plain, not a line), I made a black png image sized 1024x1024 with a 1 pixel height horizontal red line on it. I named it to "red_line.png" and placed into /usr/share/gazebo-11/media/materials/textures.

enter image description here

Actually, the red line is vertical in gazebo world, but the projector can be rolled.

You can see on the screenshot that the red line is visible on the screen of the camera.

PeterB
  • 960
  • 6
  • 8