{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Poppy Torso interacting with objects in V-REP using Pypot\n", "\n", "We suppose here that you've read the tutorial about [Controlling a Poppy Humanoid](http://nbviewer.ipython.org/github/poppy-project/pypot/blob/master/samples/notebooks/Controlling%20a%20Poppy%20humanoid%20in%20V-REP%20using%20pypot.ipynb), 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. \n", "\n", "In this tutorial, we will illustrate the use of the Poppy Torso creature in the V-REP simulator, interacting with objects." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Installation\n", "As with the Poppy Humanoid creature, you can install the Torso one with the following pip command:\n", "\n", "pip install poppy_torso\n", "\n", "and check your installation with" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pypot.creatures import PoppyTorso" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we suppose you have started a V-REP simulator, and we instantiate a simulated Torso robot:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "poppy = PoppyTorso(simulator='vrep')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"V-REP" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Interaction with objects\n", "\n", "Now we can use the robot's io interface to pop some objects." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "io = poppy._controllers[0].io" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's create a cube in front of the robot:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "name = 'cube'\n", "position = [0.2, 0, 0.8] # X, Y, Z\n", "sizes = [0.1, 0.1, 0.1] # in meters\n", "mass = 0.5 # in kg\n", "io.add_cube(name, position, sizes, mass)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"V-REP" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The objects can be moved to a given position, provided you know the object's name in V-REP. \n", "\n", "Let's try with this cube called 'cube':" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "io.set_object_position('cube', [0.15,0.05,0.8])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"V-REP" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now the cube is close to the left hand of Poppy Torso, he wants to touch it:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'l_elbow_y': 0.5999999999999943,\n", " 'head_y': -0.6000000000000014,\n", " 'r_arm_z': -0.0,\n", " 'head_z': -0.0,\n", " 'r_shoulder_x': 0.0,\n", " 'r_shoulder_y': 0.29999999999999716,\n", " 'r_elbow_y': 0.0,\n", " 'l_arm_z': -0.0,\n", " 'abs_z': 0.0,\n", " 'bust_y': 0.1,\n", " 'bust_x': 0.0,\n", " 'l_shoulder_x': 2.299999999999997,\n", " 'l_shoulder_y': 2.4000000000000057}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{m.name: m.present_position for m in poppy.motors}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "poppy.l_arm_z.goal_position = -30" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"V-REP" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The objects can be asked for their position and orientation at any time:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0.15482132136821747, 0.0854160264134407, 0.7475599050521851]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.get_object_position('cube')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n", "\n", "The position of the cube is defined as the position of its center.\n", "\n", "Now for the orientation:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-3.5130476305766933e-08, -1.890403922288897e-08, -0.5231685638427734]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "io.get_object_orientation('cube')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-29.99055461519083" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Z_orientation = io.get_object_orientation('cube')[2] * 180./3.14\n", "Z_orientation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thus the cube has then been rotated around the $Z$ axis by $0.06$ rad or $3.7$ deg." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Different objects\n", "Different types of objects are readily available: cuboids, spheroids, cylinders and cones, using a similar API.\n", "\n", "Let's add a ball, a cylinder and a cone:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "io.add_sphere('ball1', [0.1, 0, 0.8], [0.1, 0.1, 0.2], 2)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "io.add_cylinder('cylinder1', [0.1, 0, 0.8], [0.1, 0.1, 0.2], 2, [1000,1000])" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "collapsed": true }, "outputs": [], "source": [ "io.add_cone('cone1', [0.1, 0, 0.8], [0.1, 0.1, 0.2], 2, [1000,1000])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For those 3 types of objects, an optional parameter can be set: $precision$ (default = [10, 10]).\n", "\n", "The precision represents the number of edges of the object along the 2 dimensions of its surface." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notes: \n", " * you should avoid to pop 2 objects with the same name,\n", " * spheroids, cylinders and cones seems not to be very stable in V-REP." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"V-REP" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bonus\n", "You can play with the for loop..." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import VimeoVideo\n", "VimeoVideo(127023576)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.6.9 64-bit ('minfo': conda)", "language": "python", "name": "python36964bitminfoconda94c8397879e8413897a3ae60a8e0def8" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 1 }