We suppose here that you've read the tutorial about Controlling a Poppy Humanoid, and will reuse the pypot library to control a Poppy robot, so you can refer to that tutorial if you need more details about it.
In this tutorial, we will illustrate the use of the Poppy Torso creature in the V-REP simulator, interacting with objects.
As with the Poppy Humanoid creature, you can install the Torso one with the following pip command:
pip install poppy_torso
and check your installation with
from pypot.creatures import PoppyTorso
Here we suppose you have started a V-REP simulator, and we instantiate a simulated Torso robot:
poppy = PoppyTorso(simulator='vrep')
Now we can use the robot's io interface to pop some objects.
io = poppy._controllers[0].io
Let's create a cube in front of the robot:
name = 'cube'
position = [0.2, 0, 0.8] # X, Y, Z
sizes = [0.1, 0.1, 0.1] # in meters
mass = 0.5 # in kg
io.add_cube(name, position, sizes, mass)
The objects can be moved to a given position, provided you know the object's name in V-REP.
Let's try with this cube called 'cube':
io.set_object_position('cube', [0.15,0.05,0.8])
Now the cube is close to the left hand of Poppy Torso, he wants to touch it:
{m.name: m.present_position for m in poppy.motors}
{'l_elbow_y': 0.5999999999999943, 'head_y': -0.6000000000000014, 'r_arm_z': -0.0, 'head_z': -0.0, 'r_shoulder_x': 0.0, 'r_shoulder_y': 0.29999999999999716, 'r_elbow_y': 0.0, 'l_arm_z': -0.0, 'abs_z': 0.0, 'bust_y': 0.1, 'bust_x': 0.0, 'l_shoulder_x': 2.299999999999997, 'l_shoulder_y': 2.4000000000000057}
poppy.l_arm_z.goal_position = -30
The objects can be asked for their position and orientation at any time:
io.get_object_position('cube')
[0.15482132136821747, 0.0854160264134407, 0.7475599050521851]
Here we see that Poppy has moved the cube from $X=15$ cm to $X= 25$ cm, and from $Y= 0$ cm to $Y= -5$ cm.
The position of the cube is defined as the position of its center.
Now for the orientation:
io.get_object_orientation('cube')
[-3.5130476305766933e-08, -1.890403922288897e-08, -0.5231685638427734]
Z_orientation = io.get_object_orientation('cube')[2] * 180./3.14
Z_orientation
-29.99055461519083
Thus the cube has then been rotated around the $Z$ axis by $0.06$ rad or $3.7$ deg.
Different types of objects are readily available: cuboids, spheroids, cylinders and cones, using a similar API.
Let's add a ball, a cylinder and a cone:
io.add_sphere('ball1', [0.1, 0, 0.8], [0.1, 0.1, 0.2], 2)
io.add_cylinder('cylinder1', [0.1, 0, 0.8], [0.1, 0.1, 0.2], 2, [1000,1000])
io.add_cone('cone1', [0.1, 0, 0.8], [0.1, 0.1, 0.2], 2, [1000,1000])
For those 3 types of objects, an optional parameter can be set: $precision$ (default = [10, 10]).
The precision represents the number of edges of the object along the 2 dimensions of its surface.
Notes: * you should avoid to pop 2 objects with the same name, * spheroids, cylinders and cones seems not to be very stable in V-REP.
You can play with the for loop...
from IPython.display import VimeoVideo
VimeoVideo(127023576)