1
$\begingroup$

I've installed webots 2023b and after I saw that a world with and inverted pendulum has been already shipped in the default installation directory, I decided to use that world for my project.

Basically I followed this tutorial and this tutorial to be able to publish sensor data directly from the urdf file itself. That means, that I create this file:

<?xml version="1.0" ?>
<robot name="Inverted Pendulum">
    <webots>  
        <device reference="hip" type="PositionSensor">
            <ros>
                <topicName>/hip</topicName>
                <alwaysOn>true</alwaysOn>
            </ros>
        </device>
        <device reference="horizontal position sensor" type="PositionSensor">
            <ros>
                <topicName>/horizontal_position</topicName>
                <alwaysOn>true</alwaysOn>
            </ros>
        </device>
        <plugin type="inverted_pendulum.device_driver.InvertedPendulum"/>
    </webots>
</robot>

but, even if, everything starts correctly (no errors or warnings in webots), doing a:

    $ros2 topic list

does not show any topic with the name /hip or /horizontal_position. It hangs forever waiting for data to be published.

The simulator is not paused, since I created a driver, which moves the cart forth and back.

Any idea?

The code for the world is the same. I changed only the name. But I add it here anyway, just in case.

#VRML_SIM R2023b utf8
    
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2023b/projects/objects/backgrounds/protos/TexturedBackground.proto"
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2023b/projects/objects/floors/protos/Floor.proto"

WorldInfo {
  info [
    "An example of hot to solve the Inverted Pendulum problem using a PID controller"
  ]
  title "Inverted Pendulum"
  basicTimeStep 16
  contactProperties [
    ContactProperties {
      material1 "robot_basis"
      material2 "floor"
      coulombFriction [
        0.2
      ]
    }
  ]
}
Viewpoint {
  orientation -0.0996069518072968 -0.03685053329082472 0.9943442529364971 3.666446119327704
  position 13.193129047100818 10.690115274872808 4.2889817843979205
  follow "robot:solid"
}
TexturedBackground {
}
Floor {
  size 1000 2
  appearance PBRAppearance {
    baseColorMap ImageTexture {
      url [
        "https://raw.githubusercontent.com/cyberbotics/webots/R2023b/projects/default/worlds/textures/checkered_marble.jpg"
      ]
    }
    roughness 1
    metalness 0
  }
}
Robot {
  rotation 0 0 1 3.14159
  children [
    SliderJoint {
      jointParameters JointParameters {
        axis 1 0 0
        dampingConstant 1.5
      }
      device [
        LinearMotor {
          name "horizontal_motor"
          maxForce 40
        }
        PositionSensor {
          name "horizontal position sensor"
        }
      ]
      endPoint Solid {
        translation 0 0 0.06
        children [
          DEF ROBOT_SHAPE Shape {
            appearance PBRAppearance {
              baseColor 0.2443427176317998 0.704051270313573 0.1756923781185626
              roughness 1
              metalness 0
            }
            geometry Box {
              size 0.3 0.1 0.1
            }
          }
          DEF HIP HingeJoint {
            jointParameters HingeJointParameters {
              position 0.000161402
              axis 0 1 0
              anchor 0 0 0.03
            }
            device [
              PositionSensor {
                name "hip"
              }
            ]
            endPoint DEF THIGH_BB Solid {
              translation 0 -0.061 0.33000000000000007
              rotation 0 1 0 0
              children [
                Shape {
                  appearance PBRAppearance {
                    baseColor 0.8496833752956435 0.07072556649118791 0.09393453879606317
                    roughness 1
                    metalness 0
                  }
                  geometry DEF THIGH_BOX Box {
                    size 0.05 0.02 0.6
                  }
                }
              ]
              boundingObject USE THIGH_BOX
              physics Physics {
                density -1
                mass 0.05
                centerOfMass [
                  0 0.061 -0.27
                ]
              }
            }
          }
          PointLight {
            attenuation 0 0 1
            intensity 5
            location 0 0 2
          }
        ]
        contactMaterial "robot_basis"
        boundingObject USE ROBOT_SHAPE
        physics Physics {
          density -1
          mass 1
        }
      }
    }
  ]
  name "Inverted_Pendulum"
  boundingObject Box {
    size 200 0.1 0.01
  }
  physics Physics {
    density -1
    mass 30
  }
  controller "<extern>"
}
$\endgroup$

1 Answer 1

1
$\begingroup$

There is no position sensor ROS plugin in webots_ros2.

There are two ways to get joint position data published:

  • Use ros2_control. There is a ros2_control interface for webots_ros2 called webots_ros2_control (see usage example here). In your case, you will need to spawn joint_state_broadcaster which publishes joints state messages. This is generally a recommended way to interact with joints in ROS as you can achieve hard control loops, much better performance, and simpler sim2real transfer.
  • Create a custom webots_ros2 plugin (see the tutorial). You can use it to create a joint state publisher and publish joints state messages.
$\endgroup$
2
  • $\begingroup$ Tks a lot for your answer. The only problem now is that I get all the time the following error: [controller_manager]: 'update_rate' parameter not set, using default value. but my file is identical (only same variables name are different) to the one you posted. Do you know, what can be done? I would try to not open another thread if possible $\endgroup$
    – Wilhelm
    Oct 17, 2023 at 13:32
  • $\begingroup$ It looks the provided .yaml file is either missing the update_rate parameter or there the path to the file is wrong. $\endgroup$ Oct 18, 2023 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.