Model keeps swinging back and forth and is not fixed to the ground

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
simont
Posts: 8
Joined: Mon Dec 09, 2019 7:01 am

Model keeps swinging back and forth and is not fixed to the ground

Post by simont »

Hi,
I have the inverted pendulum modell below and it should be trained with reinforcement learning in pybullet.
The problem now ist, that it doesn't stand still but it swings back and forth. Does anybody of you have an idea
what could be the reason or how I could fix the model to the ground?

Code: Select all

<?xml version="1.0"    ?>

<robot name="Cartpole"  >


  <joint name="Rotation" type="continuous">  
    <parent link="Cart"/>
    <child link="Shaft"/>
    <origin rpy="0  0  0" xyz="0.0215  0.247   0.0435"/>
    <axis xyz="1  0  0"/>
    <limit effort="0.0" lower="0.0" upper="0.0" velocity="0.0"/>
  </joint>

  <joint name="Cart_joint" type="prismatic">
    <parent link="Base"/>
    <child link="Cart"/>
    <origin rpy="0  0  0" xyz="-0.04147 -0.31058  0.22851"/>
    <axis xyz="0 -1  0"/>
    <limit effort="0.0" lower="-0.23555" upper="0.23555" velocity="0.0"/>
  </joint>

  <joint name="Pole_Shaft" type="fixed">
    <parent link="Shaft"/>
    <child link="Pole"/>
    <origin rpy="0  0  0" xyz="0.0193  0      0.007"/>
    <axis xyz="0  0  0"/>
    <limit effort="0" lower="0" upper="0" velocity="0"/> 
  </joint>

  <link name="Cart">
    <inertial>
      <mass value="0.4494280957660571"/>
      <origin rpy="0  0  0" xyz="0  0  0"/>
    <inertia 
ixx="0.034344216689805106" 
ixy="-0.0013555840592494157" 
ixz="0.005746023053830929" 
iyy="0.033575305370647346" 
iyz="0.007655119926892856"     
izz="0.0029338994617400297"/>  
    </inertial> 

      
      <collision name="Cart_collision">
      <origin rpy="0  0  0" xyz="-0.00606  0.24716  0.03996"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Cart.stl" scale="0.001 0.001 0.001"/>
      </geometry>
      </collision>

    <visual name="Cart_visual">
      <origin rpy="0  0  0" xyz="-0.00606  0.24716  0.03996"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Cart.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </visual>

  </link> 



  <link name="Shaft">
    <inertial>
      <mass value="0.024209988665072436"/>
      <origin rpy="0  0  0" xyz="0  0  0"/>
      <inertia ixx="0.00188987952436807" ixy="-1.1706804306416182e-05" ixz="5.008066577766269e-05" iyy="0.0017943029340322224" iyz="0.0004187314228447953" izz="0.00010090272031144335"/>
    </inertial>
    <collision name="Shaft_collision">
      <origin rpy="0  0  0" xyz="0.01237  0       0"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Shaft.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </collision>
    <visual name="Shaft_visual">
      <origin rpy="0  0  0" xyz="0.01237  0       0"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Shaft.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </visual>

  </link>



  <link name="Pole">

    <inertial>
      <mass value="0.01797430178868597"/>
      <origin rpy="0  0  0" xyz="0  0  0"/>
      <inertia ixx="0.0008366739796019355" ixy="-7.689518680322801e-07" ixz="2.477907732299824e-06" iyy="0.0007640110742674137" iyz="0.0002341786839091567" izz="7.299569596665657e-05"/>
    </inertial>

    <collision name="Pole_collision">
      <origin rpy="0  0  0" xyz="0       0      -0.07411"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Pole.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </collision>

    <visual name="Pole_visual">
      <origin rpy="0  0  0" xyz="0       0      -0.07411"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Pole.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </visual>
  </link>


  <link name="Base">
    <inertial>
      <mass value="222222.5459113603106216"/>
      <origin rpy="0  0  0" xyz="0  0  0"/>
      <inertia ixx="0.5882136684497374" ixy="-0.02906460593367471" ixz="0.0501787117673072" iyy="0.14479915583911276" iyz="0.07620661469781886" izz="0.5291431708702397"/>
    </inertial>
    <collision name="Base_collision">
      <origin rpy="0  0  0" xyz="-0.10471 -0.14784  0.19902"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Base.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </collision>
    <visual name="Base_visual">
      <origin rpy="0  0  0" xyz="-0.10471 -0.14784  0.19902"/>
      <geometry>
        <mesh filename="package:///home/simon_tiessen/sim-to-real-ai/example_robots/urdf_cartpole/meshes/CAD/Base.stl" scale="0.001 0.001 0.001"/>
      </geometry>
    </visual>
  </link>

</robot> 
Attachments
pendelum.png
pendelum.png (69.72 KiB) Viewed 11116 times
LocknutBushing
Posts: 11
Joined: Sat Jan 18, 2020 4:37 am

Re: Model keeps swinging back and forth and is not fixed to the ground

Post by LocknutBushing »

I'm not entirely sure what you mean by swinging back and forth, that's especially confusing terminology when you're already talking about a pendulum. But if you mean the base of the pendulum is shaking, you can make it fixed in place easily:

Code: Select all

robot = p.loadURDF("[insert urdf path here]", useFixedBase=1)
This fixes the base component of the URDF model.
simont
Posts: 8
Joined: Mon Dec 09, 2019 7:01 am

Re: Model keeps swinging back and forth and is not fixed to the ground

Post by simont »

Hi, yeah sorry you are right, it is confusing terminology. And yes, I mean the base of the pendulum is shaking.
So here is the original code:

Code: Select all

 self.model = p.loadURDF(filename, flags=p.URDF_USE_SELF_COLLISION) 
So I tried this one, but it would not change anything so far. Any idea?

Code: Select all

 self.model = p.loadURDF(filename, flags=p.URDF_USE_SELF_COLLISION, useFixedBase=1) 

LocknutBushing wrote: Sun Jan 26, 2020 4:47 am I'm not entirely sure what you mean by swinging back and forth, that's especially confusing terminology when you're already talking about a pendulum. But if you mean the base of the pendulum is shaking, you can make it fixed in place easily:

Code: Select all

robot = p.loadURDF("[insert urdf path here]", useFixedBase=1)
This fixes the base component of the URDF model.
simont
Posts: 8
Joined: Mon Dec 09, 2019 7:01 am

Re: Model keeps swinging back and forth and is not fixed to the ground

Post by simont »

Hi I have fixed it :wink: I added another ground plane on my own directly into the urdf file by adding another link (the ground) and a joint
between this link and the base of my model like below. Pay attention that I used the Base link from my model as the parent and the ground
as child, instead of doing it the other way around as one would normally do.

Code: Select all

 
  <link name="ground"> 
    <inertial>
      <mass value="0.0"/>
      <inertia ixx="0.0" ixy="0.0" ixz="0.0" iyy="0.0" iyz="0.0" izz="0.0"/>
    </inertial>

    <visual>
      <geometry>
        <box size="10 10 -0.0001" />
      </geometry>
      <material name="red" />
    </visual>

    <collision>
      <geometry>
        <box size="10 10 -0.0001" />
      </geometry>
    </collision>
  </link>

  <joint name="ground_joint" type="fixed"> 
    <parent link="Base" /> 
    <child link="ground" />
  </joint> 
 
LocknutBushing
Posts: 11
Joined: Sat Jan 18, 2020 4:37 am

Re: Model keeps swinging back and forth and is not fixed to the ground

Post by LocknutBushing »

I'm glad you solved it, although I'm puzzled as to why that worked.
bullet_team
Posts: 21
Joined: Mon Oct 28, 2013 12:18 am

Re: Model keeps swinging back and forth and is not fixed to the ground

Post by bullet_team »

You should fix the base, using the 'useFixedBase=True' option in pybullet.loadURDF
Alternatively, set the mass of the first (base) link to zero.

See also the PyBullet quickstart guide for more info in general.
https://docs.google.com/document/d/10sX ... e70wns7io3
Post Reply