gazebosim / docs

High-level Gazebo documentation that gets published to https://gazebosim.org/docs/
https://gazebosim.org/docs
44 stars 83 forks source link

force/torque sensor example & how to add the link information to sensor plugin? #331

Closed xibeisiber closed 1 year ago

xibeisiber commented 1 year ago

Hi,

  1. Is there an example on how to simulate the 6-axis force/torque sensor?

  2. I put the robot model in one xacro file and intend to put ignition-related content in another xacro file. In classic gazebo, there is a "bodyName" tag for the imu plugin and "jointName" tag for the force-torque plugin. But in ignition, there is no thus tag in the tutorial. So the question is how to relate the sensor(say IMU) to certain link. I see in the example sensor_tutorial.sdf that the imu sensor tag should be under the link tag. But this way I have to the robot content and ignition content in the same file(sdf or xacro).

Environment: ros2 humble, Ignition Gazebo 6.11.0

Thanks for any help! Jia

xibeisiber commented 1 year ago

Environment: ros2 humble, Ignition Gazebo 6.11.0

  1. I found the example file "force_torque.sdf" in gz_sim/test/worlds.
  2. for the IMU, the sensor is bound to a link, so I can use <gazebo reference="base_link"> in the ignition-related xacro file. For the force-torque sensor, I add the following in the ignition-related xacro file and load the xacro files to ignition using ros2 launch, there is no /force_torque topic using ign topic -l. But if I save the world as sdf file and load it into ignition, the /force_torque topic does exist... It seems that the force-torque topic name is not correctly read when launching xacro?
    <gazebo reference="joint2">
    <preserveFixedJoint>true</preserveFixedJoint>
    <sensor name="force_torque_sensor" type="force_torque">
      <pose>0 0 0 0 -0 0</pose>
      <update_rate>100</update_rate>
      <always_on>true</always_on>
      <visualize>true</visualize>
      <topic>force_torque</topic>
      <force_torque>
        <frame>sensor</frame>
        <measure_direction>parent_to_child</measure_direction>
      </force_torque>
    </sensor>
    </gazebo>

    The full package is here (modified from ros_gz_sim_demos): test_demos.zip ros2 launch test_demos load_xacro.launch.py ros2 launch test_demos load_sdf.launch.py ign topic -l

Screenshot from 2023-01-31 18-09-35

xibeisiber commented 1 year ago

Partly solved. For some unknown reason, the <plugin filename="ignition-gazebo-forcetorque-system" name="ignition::gazebo::systems::ForceTorque" /> can not be successfully loaded when written in xacro file. A makeshift solution is to add this plugin in /usr/share/ignition/ignition-gazebo6/worlds/empty.sdf.

azeey commented 1 year ago

The reason is the force torque sensor system, like the IMU sensor system, is meant to be loaded as part of the world as it handles all the force torque sensors in the world, not just a single model. I think the IMU sensor works when loaded as a model plugin, but it's just a side-effect of how it's implemented. Users are not meant to load it as a model plugin.

For your ROS2 usage, I recommend you copy the empty.sdf into your own package, modify it to include the ForceTorque sensor under <world> and use that in your launch file with the gz_args argument of gz_sim.launch.py.

Nibanovic commented 6 months ago

tldr: My two cents: to work around this issue, you don't need to define the whole sensor in empty.sdf, only the plugin.

I just struggled with the same issue. For me, I only had to add ForceTorque plugin under the <world name="empty"> tag, as so:

  <world name="empty">
    <physics name="1ms" type="ignored">
      <max_step_size>0.001</max_step_size>
      <real_time_factor>1.0</real_time_factor>
    </physics>
### ... some other plugins
    <plugin 
      filename="ignition-gazebo-forcetorque-system"
      name="ignition::gazebo::systems::ForceTorque">
    <plugin>

Then, the sensor defined in my URDF was being properly read:

      <gazebo reference="${prefix}joint5">
        <sensor name="force_torque_sensor" type="force_torque">
          <always_on>true</always_on>
          <update_rate>100</update_rate>
          <visualize>true</visualize>
          <topic>force_torque</topic>
          <enable_metrics>true</enable_metrics>
          <pose>0 0 0 0 0 0</pose>
          <force_torque>
            <frame>sensor</frame>
            <measure_direction>child_to_parent</measure_direction>
          </force_torque> 
        </sensor>
      </gazebo>
jaronski commented 1 month ago

i am trying to get ros2_control force_torque_sensor_broadcaster to publish the data from the force torque sensor from inside of ign fortress. when i try to start the ros2 control load_controller fts_sensor_broadcaster --set-state active it shows green and "as if" its working but when i list_controllers it tells me the fts_sensor_broadcaster is inactive.

[ign-1] [ERROR] [1716986934.994304661] [controller_manager]: Can't activate controller 'ftsensor_broadcaster': State interface with key 'sensor_FT/force.x' does not exist [spawner-8] [INFO] [1716986935.005369509] [spawner_ftsensor_broadcaster]: Configured and activated ftsensor_broadcaster

i tried renaming the sensor, state_interfaces in the config.yaml and xacro of my custom robot model. I added the plugin as described here into the empty_world.sdf that i launch

<!-- FT Plugin -->
    <plugin filename="ignition-gazebo-forcetorque-system" name="ignition::gazebo::systems::ForceTorque"/>

is this working at all? i tried also looking into the universal robots repos but i guess the force torque part is not working as i couldn't find a ur_controller/force_torque_sensor_broadcaster as stated in the config.yaml

Does anyone here have a solution for this or successfully integrated the Force Torque Sensor in Ignition Fortress and ros2 humble ros2_control ?

Thanks for any hints or tips