Skip to content

Instantly share code, notes, and snippets.

@clebio
Last active November 15, 2020 19:21
Show Gist options
  • Save clebio/d4d7fb1c2afdfec68d0ccafd143f5027 to your computer and use it in GitHub Desktop.
Save clebio/d4d7fb1c2afdfec68d0ccafd143f5027 to your computer and use it in GitHub Desktop.
Pybullet permute ground plane
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: Caleb Hyde
@date: November, 2020
"""
import numpy as np
import pybullet as pb
import pybullet_data
import time
import logging
pb.connect(pb.GUI)
pb.setAdditionalSearchPath(pybullet_data.getDataPath())
pb.setGravity(0, 0, -9.81)
ALPHA = 0.1
POSITION = [0, 0, -0.1]
groundId = pb.createCollisionShape(pb.GEOM_BOX, halfExtents=[1, 1, 0.1])
shapeID = pb.createVisualShape(pb.GEOM_BOX, halfExtents=[1, 1, 0.1])
ground = pb.createMultiBody(
baseMass=0,
baseCollisionShapeIndex=groundId,
basePosition=POSITION,
baseVisualShapeIndex=shapeID,
)
def permute_ground(gnd):
force = [ALPHA * np.sin(now), ALPHA * np.cos(now), 0]
orientation = pb.getQuaternionFromEuler(force)
# logging.debug(orientation)
pb.resetBasePositionAndOrientation(
bodyUniqueId=gnd,
ornObj=orientation,
posObj=POSITION,
)
while True:
now = time.time()
permute_ground(ground)
pb.stepSimulation()
time.sleep(0.05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment