add pingpong world

This commit is contained in:
Brian Delhaisse
2019-07-07 04:02:42 +02:00
parent 2eb5028148
commit 4f9940c154
15 changed files with 31913 additions and 4 deletions
@@ -0,0 +1,13 @@
#
# Wavefront material file
# Created with Kaydara FBX
#
newmtl Mat
map_Kd net.png
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.200000 0.200000 0.200000
illum 2
Ns 50.000000
Tr 1.000000
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
#
# Wavefront material file
# Converted by Meshlab Group
#
newmtl material_0
Ka 0.200000 0.200000 0.200000
Kd 0.800000 0.800000 0.800000
Ks 1.000000 1.000000 1.000000
Tr 1.000000
illum 2
Ns 0.000000
map_Kd net.png
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

@@ -0,0 +1,13 @@
#
# Wavefront material file
# Created with Kaydara FBX
#
newmtl 01___Default
map_Kd paddle.jpg
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.200000 0.200000 0.200000
illum 2
Ns 50.000000
Tr 1.000000
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
#
# Wavefront material file
# Converted by Meshlab Group
#
newmtl material_0
Ka 0.200000 0.200000 0.200000
Kd 0.800000 0.800000 0.800000
Ks 1.000000 1.000000 1.000000
Tr 1.000000
illum 2
Ns 0.000000
map_Kd paddle.jpg
@@ -0,0 +1,13 @@
#
# Wavefront material file
# Created with Kaydara FBX
#
newmtl Mat_1
map_Kd table.png
Ka 0.000000 0.000000 0.000000
Kd 0.800000 0.800000 0.800000
Ks 0.200000 0.200000 0.200000
illum 2
Ns 50.000000
Tr 1.000000
@@ -0,0 +1,72 @@
####
#
# OBJ File Generated by Meshlab
#
####
# Object table.obj
#
# Vertices: 8
# Faces: 12
#
####
mtllib ./table.obj.mtl
vn -1.570796 -1.570796 -1.570796
v -1.369846 -0.757018 -0.044536 0.752941 0.752941 0.752941
vn -1.570796 -1.570795 1.570796
v -1.369846 -0.757018 0.044536 0.752941 0.752941 0.752941
vn 1.570796 -1.570795 -1.570796
v 1.369846 -0.757018 -0.044536 0.752941 0.752941 0.752941
vn 1.570796 -1.570796 1.570796
v 1.369846 -0.757018 0.044536 0.752941 0.752941 0.752941
vn 1.570796 1.570796 -1.570796
v 1.369846 0.757018 -0.044536 0.752941 0.752941 0.752941
vn 1.570796 1.570795 1.570796
v 1.369846 0.757018 0.044536 0.752941 0.752941 0.752941
vn -1.570796 1.570795 -1.570796
v -1.369846 0.757018 -0.044536 0.752941 0.752941 0.752941
vn -1.570796 1.570796 1.570796
v -1.369846 0.757018 0.044536 0.752941 0.752941 0.752941
# 8 vertices, 0 vertices normals
usemtl material_0
vt 0.009557 0.116139
vt 0.879735 0.091371
vt 0.879735 0.116139
f 2/1/2 3/2/3 4/3/4
vt 0.009557 0.091371
f 3/2/3 2/1/2 1/4/1
vt 0.009557 0.008367
vt 0.490443 0.008367
vt 0.009557 0.033135
f 3/5/3 5/6/5 4/7/4
vt 0.490443 0.033135
f 4/7/4 5/6/5 6/8/6
vt 0.879735 0.074637
vt 0.009557 0.074637
vt 0.879735 0.049869
f 8/9/8 6/10/6 7/11/7
vt 0.009557 0.049869
f 5/12/5 7/11/7 6/10/6
vt 0.509557 0.033135
vt 0.990443 0.008367
vt 0.990443 0.033135
f 8/13/8 1/14/1 2/15/2
vt 0.509557 0.008367
f 1/14/1 8/13/8 7/16/7
vt 0.879735 0.991633
vt 0.009557 0.991633
vt 0.879735 0.570620
f 6/17/6 8/18/8 4/19/4
vt 0.009557 0.570620
f 2/20/2 4/19/4 8/18/8
vt 0.009557 0.553886
vt 0.879735 0.132874
vt 0.879735 0.553886
f 1/21/1 5/22/5 3/23/3
vt 0.009557 0.132874
f 5/22/5 1/21/1 7/24/7
# 12 faces, 24 coords texture
# End of File
@@ -0,0 +1,14 @@
#
# Wavefront material file
# Converted by Meshlab Group
#
newmtl material_0
Ka 0.200000 0.200000 0.200000
Kd 0.800000 0.800000 0.800000
Ks 1.000000 1.000000 1.000000
Tr 1.000000
illum 2
Ns 0.000000
map_Kd table.png
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@@ -0,0 +1,57 @@
#!/usr/bin/env python
r"""Provide the ping pong (table tennis) self.
"""
import os
import numpy as np
from pyrobolearn.worlds import BasicWorld
__author__ = "Brian Delhaisse"
__copyright__ = "Copyright 2019, PyRoboLearn"
__credits__ = ["Brian Delhaisse"]
__license__ = "GNU GPLv3"
__version__ = "1.0.0"
__maintainer__ = "Brian Delhaisse"
__email__ = "briandelhaisse@gmail.com"
__status__ = "Development"
class PingPongWorld(BasicWorld):
r"""Ping Pong world
"""
def __init__(self, simulator, table_position=(0., 0., 0.76), dimensions=(1., 1., 1.)):
super(PingPongWorld, self).__init__(simulator)
mesh_path = os.path.dirname(os.path.abspath(__file__)) + '/../../meshes/sports/pingpong/'
# ping pong
table = self.load_mesh(mesh_path + 'table.obj', position=table_position, scale=dimensions, mass=0,
flags=1)
self.change_dynamics(table, restitution=0.3)
net_position = np.asarray(table_position) + np.array([0., 0., 0.01])
net = self.load_mesh(mesh_path + 'net.obj', position=net_position, scale=dimensions, mass=0, flags=1)
paddle1 = self.load_mesh(mesh_path + 'paddle.obj', position=(1.1, 0.4, 0.9), scale=dimensions, mass=0.08,
flags=0)
paddle2 = self.load_mesh(mesh_path + 'paddle.obj', position=(-1.1, -0.4, 0.9), orientation=(0., -1., 0., 0.),
scale=dimensions, mass=0.08, flags=0, return_body=False)
ball = self.load_sphere(position=(1., 0.35, 1.2), mass=0.0027, radius=0.020, color=None, return_body=True)
ball.restitution = 2.5
# Test
if __name__ == '__main__':
from itertools import count
import pyrobolearn as prl
sim = prl.simulators.Bullet()
world = PingPongWorld(sim)
for t in count():
world.step(sim.dt)
+46 -4
View File
@@ -942,6 +942,44 @@ class World(object):
return self.sim.get_closest_points(body1=body.id, body2=body2, distance=radius,
link1_id=link_id, link2_id=link2_id)
def get_contact_bodies(self):
pass
def attach(self, body1, body2, link1=-1, link2=-1, contact_point=None):
"""
Attach two bodies (links) together at the specified contact points.
To detach them, call ``world.detach(body1, body2, link1, link2)``.
Args:
body1 (int, Body): body unique id, or a Body instance.
body2 (int, Body): body unique id, or a Body instance.
link1 (int, None): link id. By default, it will be the base (=-1).
link2 (int, None): link id. By default, it will be the base (=-1).
contact_point (np.array[3], None): the contact point. If None, it will compute it. If there are multiple
contact points, it will attach the links to each one of them.
Returns:
bool: True if it was successful.
"""
pass
def detach(self, body1, body2, link1=-1, link2=-1, contact_point=None):
"""
Detach two bodies that were previously attached.
Args:
body1:
body2:
link1:
link2:
contact_point:
Returns:
bool: True if it was successful.
"""
pass
def load_floor(self, scaling=1.):
"""
Load a basic floor in the world.
@@ -1878,12 +1916,14 @@ class World(object):
print("Contact damping coefficient (-1 if not available): {}".format(info[8]))
print("Contact stiffness coefficient (-1 if not available): {}".format(info[9]))
def change_dynamics(self, lateral_friction=1., spinning_friction=0., rolling_friction=0., restitution=0.,
linear_damping=0.04, angular_damping=0.04, contact_stiffness=-1, contact_damping=-1, **kwargs):
def change_dynamics(self, body_id=None, lateral_friction=1., spinning_friction=0., rolling_friction=0.,
restitution=0., linear_damping=0.04, angular_damping=0.04, contact_stiffness=-1,
contact_damping=-1, **kwargs):
"""
Change the world floor dynamics.
Change the dynamics of a body. If no body is specified, it will be change the world floor dynamics.
Args:
body_id (int, None): unique body id. If None, it will be the world floor.
lateral_friction (float): lateral (linear) contact friction
spinning_friction (float): torsional friction around the contact normal
rolling_friction (float): torsional friction orthogonal to contact normal
@@ -1895,7 +1935,9 @@ class World(object):
`contact_stiffness`. This overrides the value if it was specified in the URDF file in the contact
section.
"""
self.sim.change_dynamics(body_id=self.floor_id, link_id=-1, lateral_friction=lateral_friction,
if body_id is None:
body_id = self.floor_id
self.sim.change_dynamics(body_id=body_id, link_id=-1, lateral_friction=lateral_friction,
spinning_friction=spinning_friction, rolling_friction=rolling_friction,
restitution=restitution, linear_damping=linear_damping,
angular_damping=angular_damping, contact_stiffness=contact_stiffness,