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>"
}