pybullet's applyExternalForce with LINK_FRAME option ??

Post Reply
rufus
Posts: 1
Joined: Wed Mar 22, 2017 2:26 pm

pybullet's applyExternalForce with LINK_FRAME option ??

Post by rufus »

Hi,
Many thanks for making bullet available! I'm working on a quadcopter simulation in pybullet by stepping through the simulation. I model the four propellers by four forces, that are applied using the function applyExternalForce. I use the p.LINK_FRAME option to specify the position and direction of the forces in the quadcopters base coordinate frame. It seems that the position of the forces is correct, however the direction of the forces seems to be in the WORLD_FRAME.
The following minimal example (I could not add the file to this post) confirms this behavior. It starts with a pitch of 45^o and at two forces each of 10 N in vertical direction are exerted, in local coordinates at (x,y,z)=(0.1, 0,0) and (x,y,z)=(-0.1,0,0). The simulation shows a vertical movement, whereas a movement along z=-x is expected.

Code:

Code: Select all

import numpy as np
import pybullet as p

physicsClient = p.connect(p.DIRECT)
p.setGravity(0,0,0)
p.setTimeStep(1e-3)
p.setRealTimeSimulation(0)
quadcopterId = p.loadURDF("quadrotor.urdf",[0,0,0],p.getQuaternionFromEuler([0,np.pi/4,0]))

# becaue of the pitch of 45^o the quadcopter is expected to accelerate along
# the line z = -x (in the world coordinate frame), but it goes straight along the z-axis
for _ in range(10):
    p.applyExternalForce(quadcopterId,-1,[0,0,10],[0.1,0,0],p.LINK_FRAME)
    p.applyExternalForce(quadcopterId,-1,[0,0,10],[-0.1,0,0],p.LINK_FRAME)
    p.stepSimulation()
    pos,orientation = p.getBasePositionAndOrientation(quadcopterId)
    rpy = p.getEulerFromQuaternion(orientation)
    print("X = {:+f}, Y = {:+f}, Z = {:+f}, Roll = {:+f}, Pitch = {:+f}, Yaw = {:+f}".format(*pos,*rpy))
Output:
X = +0.000000, Y = +0.000000, Z = +0.000040, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = +0.000000, Y = +0.000000, Z = +0.000120, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.000240, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.000400, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.000600, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.000840, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.001120, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.001440, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.001800, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000
X = -0.000000, Y = +0.000000, Z = +0.002200, Roll = -0.000000, Pitch = +0.785398, Yaw = -0.000000

I'm using python3.5 and bullet3 obtained from github retrieved at 16 Feb 2017.
Post Reply