Robotics StackExchange | Archived questions

How do I rotate a camera plugin in my model?

I have a urdf file for a four wheeled robot that includes a camera and a hokuyo laser scanner that uses the gazebo sensor plugins. However, at the moment the camera points to the rear of the robot. I have tried changing the origin tag of the link for the camera and also tried adding a pose tag to various parts of the urdf file, with no change being present.

This is my urdf file:

<?xml version="1.0"?>
<robot name="Bilkins">


  <link name="chassis">
    <visual>
      <geometry>
        <mesh filename="package://bilkins/meshes/chassis.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin rpy="0.0 0 0" xyz="0 0 0"/>
    </visual>
    <collision>
      <geometry>
        <mesh filename="package://bilkins/meshes/chassis.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin rpy="0.0 0 0" xyz="0 0 0"/>
    </collision>
    <inertial>
      <mass value="0.2" />
      <inertia ixx="0.4" ixy="0.0" ixz="0.0" iyy="0.4" iyz="0.0" izz="0.2"/>
    </inertial>
  </link>

  <link name="rear_axle">
    <visual>
      <geometry>
        <mesh filename="package://bilkins/meshes/rear_axle.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="-1.3 0 -0.5" />
    </visual>
    <collision>
      <geometry>
        <mesh filename="package://bilkins/meshes/rear_axle.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="-1.3 0 -0.5" />
    </collision>
    <inertial>
      <mass value="0.14" />
      <inertia ixx="0.4" ixy="0.0" ixz="0.0" iyy="0.4" iyz="0.0" izz="0.2"/>
    </inertial>
  </link>

  <link name="front_axle">
    <visual>
      <geometry>
        <mesh filename="package://bilkins/meshes/front_axle.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="1.3 0 -0.5" />
    </visual>
    <collision>
      <geometry>
        <mesh filename="package://bilkins/meshes/front_axle.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="1.3 0 -0.5" />
    </collision>
    <inertial>
      <mass value="0.1" />
      <inertia ixx="0.4" ixy="0.0" ixz="0.0" iyy="0.4" iyz="0.0" izz="0.2"/>
    </inertial>
  </link>

  <link name="front_left_wheel">
    <visual>
      <geometry>
        <mesh filename="package://bilkins/meshes/front_left_wheel.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="1.3 0.9 -0.5" />
    </visual>
    <collision>
      <geometry>
        <mesh filename="package://bilkins/meshes/front_left_wheel.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="1.3 0.9 -0.5" />
    </collision>
    <inertial>
      <mass value="0.02" />
      <inertia ixx="0.4" ixy="0.0" ixz="0.0" iyy="0.4" iyz="0.0" izz="0.2"/>
    </inertial>
  </link>

  <link name="front_right_wheel">
    <visual>
      <geometry>
        <mesh filename="package://bilkins/meshes/front_right_wheel.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="1.3 -0.9 -0.5" />
    </visual>
    <collision>
      <geometry>
        <mesh filename="package://bilkins/meshes/front_right_wheel.dae" scale="0.1 0.1 0.1" />
      </geometry>
      <origin xyz="1.3 -0.9 -0.5" />
    </collision>
    <inertial>
      <mass value="0.02" />
      <inertia ixx="0.4" ixy="0.0" ixz="0.0" iyy="0.4" iyz="0.0" izz="0.2"/>
    </inertial>
  </link>

  <joint name="rear_axle_to_chassis" type="continuous">
    <parent link="chassis"/>
    <child link="rear_axle" />
    <axis xyz="0 1 0" />
    <origin xyz="1.3 0 0.5" />
  </joint>

  <joint name="front_axle_to_chassis" type="revolute">
    <axis xyz="0 0 1" />
    <limit effort="1000.0" lower="-0.1" upper="0.1" velocity="0.5"/>
    <parent link="chassis"/>
    <child link="front_axle" />
    <origin xyz="-1.3 0 0.5" />
  </joint>

  <joint name="front_left_wheel_to_axle" type="continuous">
    <parent link="front_axle"/>
    <child link="front_left_wheel" />
    <axis xyz="0 1 0" />
    <origin xyz="0 -0.9 0" />
  </joint>

  <joint name="front_right_wheel_to_axle" type="continuous">
    <parent link="front_axle"/>
    <child link="front_right_wheel" />
    <axis xyz="0 1 0" />
    <origin xyz="0 0.9 0" />
  </joint>

  <joint name="hokuyo_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <parent link="chassis"/>
    <child link="hokuyo_link"/>
  </joint>

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

    <visual>
      <origin xyz="-1 0 1.2" rpy="0 0 0"/>
      <geometry>
        <mesh filename="package://bilkins/meshes/hokuyo.dae"/>
      </geometry>
    </visual>

    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

  <!-- hokuyo -->
  <gazebo reference="hokuyo_link">
    <sensor type="gpu_ray" name="head_hokuyo_sensor">
      <pose>0 0 0 0 0 0</pose>
      <visualize>true</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>/bilkins/laser/scan</topicName>
        <frameName>hokuyo_link</frameName>
      </plugin>
    </sensor>
  </gazebo>

  <joint name="camera_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <parent link="chassis"/>
    <child link="camera_link"/>
  </joint>

  <!-- Camera -->
  <link name="camera_link">

    <collision>
      <origin xyz="-1.1 0 0.7" rpy="0 0 1"/>
      <geometry>
    <box size="0.1 0.1 0.1"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="-1.1 0 0.7" rpy="0 0 1"/>
      <geometry>
    <box size="0.1 0.1 0.1"/>
      </geometry>
      <material name="red"/>
    </visual>

    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

  <!-- camera -->
  <gazebo reference="camera_link">
    <sensor type="camera" name="camera1">
      <update_rate>30.0</update_rate>
      <camera name="head">
        <horizontal_fov>1.3962634</horizontal_fov>
        <image>
          <width>800</width>
          <height>800</height>
          <format>R8G8B8</format>
        </image>
        <clip>
          <near>0.02</near>
          <far>300</far>
        </clip>
        <noise>
          <type>gaussian</type>
          <!-- Noise is sampled independently per pixel on each frame.
               That pixel's noise value is added to each of its color
               channels, which at that point lie in the range [0,1]. -->
          <mean>0.0</mean>
          <stddev>0.007</stddev>
        </noise>
      </camera>
      <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
        <alwaysOn>true</alwaysOn>
        <updateRate>0.0</updateRate>
        <cameraName>bilkins/camera1</cameraName>
        <imageTopicName>image_raw</imageTopicName>
        <cameraInfoTopicName>camera_info</cameraInfoTopicName>
        <frameName>camera_link</frameName>
        <hackBaseline>0.07</hackBaseline>
        <distortionK1>0.0</distortionK1>
        <distortionK2>0.0</distortionK2>
        <distortionK3>0.0</distortionK3>
        <distortionT1>0.0</distortionT1>
        <distortionT2>0.0</distortionT2>
      </plugin>
    </sensor>
  </gazebo>

</robot>

I am running Melodic on Ubuntu 18.04.

Asked by ARMWilkinson on 2020-10-05 08:14:44 UTC

Comments

Answers

I haven't been able to find a way to rotate the camera plugin on Ubuntu 20, ROS 2 Foxy, but it is worth noting that the plugin faces towards the positive X direction. So you can either design the link acting as your camera accordingly, or you can make a special link with no physics attributes, and create a joint connecting the camera sensor link to your actual link you have to represent the camera.

Example a camera sensor rotated 90 degrees (from yaw/z axis) than that of the link:

<?xml version="1.0" encoding="UTF-8"?>

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

 <!-- Just the sensor, nothing else -->
<link name="camera_sensor_link">

      <sensor type="camera" name="sensor_name">
          <always_on>0</always_on>
          <update_rate>1</update_rate>

          <camera name="camera_name">
            <distortion>
              <k1>0.1</k1>
              <k2>0.2</k2>
              <k3>0.3</k3>
              <p1>0.4</p1>
              <p2>0.5</p2>
              <center>0.5 0.5</center>
            </distortion>
          </camera>

          <plugin name="plugin_name" filename="libgazebo_ros_camera.so">

            <ros>
              <namespace>custom_ns</namespace>
              <argument>image_raw:=custom_img</argument>
              <argument>camera_info:=custom_info</argument>
            </ros>

            <camera_name>custom_camera</camera_name>
            <frame_name>custom_frame</frame_name>
            <hack_baseline>0.07</hack_baseline>
          </plugin>
        </sensor>

</link>

 <!-- This would be your actual link you wanted to attach the camera sensor too -->
<link name="camera_link">

    <!-- Camera Link Inertia -->
    <inertial>
      <mass value="1"/>
      <inertia
        ixx="0.166667" ixy="0" ixz="0"
        iyx="0" iyy="0.166667" iyz="0"
        izx="0" izy="0" izz="0.166667"
        />
    </inertial>

    <!-- Camera Link Visual -->
    <visual name='visual'>
      <geometry>
        <box size="0.1 0.2 0.1" />
      </geometry>
    </visual>

    <!-- Camera Link Collision -->
    <collision name='collision'>
      <geometry>
        <box size="0.1 0.2 0.1" />
      </geometry>
    </collision>
  </link>

<joint name='robot_footprint_joint' type='fixed'>
    <parent link="camera_link" />
    <child link="camera_sensor_link" />
    <origin xyz="0.1 0 0" rpy="0 0 1.570795" />
  </joint>

</robot>

Asked by 808brick on 2021-03-30 22:11:45 UTC

Comments