{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Controling a simulated roboticia in Vrep " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, be sure you have a robot installed on your computer. If not, you can install it with pip by running in a shell :\n", "```\n", "> pip install roboticia-quattro\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Second create your robot :" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from roboticia_quattro import RoboticiaQuattro" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "robot = RoboticiaQuattro(simulator = 'vrep', host = '127.0.0.1')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Your robot have sensors and motors attach to it : " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "robot.motors" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "robot.sensors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Motors and sensors are updated by a controller. You are not supposed to access the controller to manage your robot but you can see the controllers : " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[,\n", " ]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "robot._controllers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that each controller have an io. The io is the classe used to communicate with the real robot. The io is used to synchronize the software robot class with the real robot :" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "robot._controllers[1].io" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The synchronization made by the controllers can be stopped and start : " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "robot.stop_sync()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "robot.start_sync()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And you can manage all motors and sensors very easily : " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example if you want to retrieve the value of the force sensor f1 :" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "9.143142402172089" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "robot.f1.force" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to know the position of the motor m12 :" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "-20.0" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "robot.m12.present_position" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The simulation in vrep can be stop, start or reset :" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [], "source": [ "robot.stop_simulation()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "robot.start_simulation()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [], "source": [ "robot.reset_simulation()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Don't forget to close your robot if you want to release the io and the real bus or socket used for that :" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [], "source": [ "robot.close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 1 }