Some tests to check if your setup is running correctly - Using dynamixel XL320 motor

Import the module to test the motors :

In [1]:
import pypot.dynamixel
import time

Find the available usb port. The port where USB2AX or USBDynamixel is plug.


In [2]:
print(pypot.dynamixel.get_available_ports())


['COM3']

Open a low level connexion to the motors, don't forget to replace 'COM3' if your port is different.


In [3]:
dxl_io = pypot.dynamixel.Dxl320IO('COM3', use_sync_read=True)

Find the different motors which must have differents id. Id have been set up before with the herborist tool.


In [5]:
print(dxl_io.scan(range(30)))


[1, 2, 3, 4]

A test to check the speed of the communication with your motor. On windows it is possible that you have to change the latency time of the driver of the usbdynamixel (see forum : https://forum.poppy-project.org/t/birth-of-poppy-ergo-jr-and-support-for-low-cost-xl-320-motors/1052/22)


In [4]:
%timeit dxl_io.get_present_position((1, 2, 3, 4))


100 loops, best of 3: 5.9 ms per loop

Setting the robot to 0 position :


In [5]:
dxl_io.set_goal_position({1: 0})
dxl_io.set_goal_position({2: 0})
dxl_io.set_goal_position({3: 0})
dxl_io.set_goal_position({4: 0})

If you want to close the connexion :


In [27]:
dxl_io.close()

Now, if you want to have a robot acces and not only motors access, you have to configure your robot.


In [1]:
from pypot.dynamixel import autodetect_robot

my_robot = autodetect_robot()

for m in my_robot.motors:
    m.goal_position = 0.0

In [20]:
my_robot.motors


Out[20]:
[<DxlMotor name=motor_1 id=1 pos=0.15>,
 <DxlMotor name=motor_2 id=2 pos=-1.03>,
 <DxlMotor name=motor_3 id=3 pos=-5.13>,
 <DxlMotor name=motor_4 id=4 pos=7.77>]

In [5]:
my_robot.motor_1.goal_position = 0

You can save the configuration in a file :


In [9]:
import json

config = my_robot.to_config()

with open('mini_dof.json', 'wb') as f:
    json.dump(config, f)

And close the robot :


In [14]:
my_robot.close()

You can use your previous json file to instanciate your robot :


In [9]:
from pypot.robot import from_json

mini_4dof = from_json('test.json')

In [10]:
mini_4dof.motors


Out[10]:
[<DxlMotor name=m1 id=1 pos=-20.67>,
 <DxlMotor name=m2 id=2 pos=-40.91>,
 <DxlMotor name=m3 id=3 pos=-30.35>,
 <DxlMotor name=m4 id=4 pos=89.88>]

And make move your robot :


In [12]:
mini_4dof.m4.goto_position(90,0.5)

In [13]:
mini_4dof.m4.goto_position(-90,0.5)

In [228]:
mini_4dof.m3.goto_position(-10,0.5)

In [229]:
mini_4dof.m3.goto_position(90,0.5)

In [211]:
mini_4dof.m4.goto_position(90,0.5)
mini_4dof.m4.goto_position(-90,0.5)

In [216]:
mini_4dof.m3.goal_position = 20

In [8]:
mini_4dof.close()

If you have correctly set your robot as a poppy creature you just have to import the class and instanciate your robot :


In [2]:
from poppy.creatures import Poppy4dofArmMini

To know what poppy creature are installed on your computer :


In [3]:
installed_poppy_creatures_packages()


Out[3]:
['poppy-humanoid', 'poppy-ergo-jr', 'poppy-4dof-arm-mini']

In [29]:
poppy = Poppy4dofArmMini()

In [30]:
poppy.motors


Out[30]:
[<DxlMotor name=m1 id=1 pos=0.15>,
 <DxlMotor name=m2 id=2 pos=1.61>,
 <DxlMotor name=m3 id=3 pos=-2.79>,
 <DxlMotor name=m4 id=4 pos=-0.73>]

In [35]:
poppy.close()

To check what is installed on your computer. You have to find the name of your creature.


In [1]:
import pip
pip.get_installed_distributions()


Out[1]:
[pyserial 2.7 (c:\python27\lib\site-packages\pyserial-2.7-py2.7-win32.egg),
 ipython 3.0.0-b1 (c:\python27\lib\site-packages\ipython-3.0.0_b1-py2.7.egg),
 zerorpc 0.4.4 (c:\python27\lib\site-packages\zerorpc-0.4.4-py2.7.egg),
 pyzmq 14.5.0 (c:\python27\lib\site-packages\pyzmq-14.5.0-py2.7-win32.egg),
 tornado 4.1 (c:\python27\lib\site-packages\tornado-4.1-py2.7-win32.egg),
 bottle 0.12.8 (c:\python27\lib\site-packages\bottle-0.12.8-py2.7.egg),
 mistune 0.5 (c:\python27\lib\site-packages\mistune-0.5-py2.7.egg),
 mock 1.0.1 (c:\python27\lib\site-packages\mock-1.0.1-py2.7.egg),
 nose 1.3.4 (c:\python27\lib\site-packages\nose-1.3.4-py2.7.egg),
 requests 2.5.1 (c:\python27\lib\site-packages\requests-2.5.1-py2.7.egg),
 jinja2 2.7.3 (c:\python27\lib\site-packages\jinja2-2.7.3-py2.7.egg),
 jsonschema 2.4.0 (c:\python27\lib\site-packages\jsonschema-2.4.0-py2.7.egg),
 numpydoc 0.5 (c:\python27\lib\site-packages\numpydoc-0.5-py2.7.egg),
 pygments 2.0.2 (c:\python27\lib\site-packages\pygments-2.0.2-py2.7.egg),
 sphinx 1.3b2 (c:\python27\lib\site-packages\sphinx-1.3b2-py2.7.egg),
 enum34 1.0.4 (c:\python27\lib\site-packages\enum34-1.0.4-py2.7.egg),
 poppy-humanoid 1.1.0 (c:\users\julien\documents\travail\poppy\poppy-humanoid\software),
 pypot 2.7.1 (c:\python27\lib\site-packages\pypot-2.7.1-py2.7.egg),
 poppy-ergo-jr 1.1.0 (c:\python27\lib\site-packages\poppy_ergo_jr-1.1.0-py2.7.egg),
 poppy-creature 1.6.0 (c:\python27\lib\site-packages\poppy_creature-1.6.0-py2.7.egg),
 poppy-dof4-arm-mini 0.0.1 (c:\python27\lib\site-packages\poppy_dof4_arm_mini-0.0.1-py2.7.egg),
 Babel 1.3 (c:\python27\lib\site-packages),
 backports.ssl-match-hostname 3.4.0.2 (c:\python27\lib\site-packages),
 bleach 1.4.1 (c:\python27\lib\site-packages),
 certifi 14.05.14 (c:\python27\lib\site-packages),
 colorama 0.3.3 (c:\python27\lib\site-packages),
 docutils 0.12 (c:\python27\lib\site-packages),
 html5lib 0.99999 (c:\python27\lib\site-packages),
 MarkupSafe 0.23 (c:\python27\lib\site-packages),
 matplotlib 1.4.2 (c:\python27\lib\site-packages),
 numpy 1.9.1 (c:\python27\lib\site-packages),
 pyparsing 2.0.3 (c:\python27\lib\site-packages),
 pyreadline 2.0 (c:\python27\lib\site-packages),
 python-dateutil 2.4.0 (c:\python27\lib\site-packages),
 pytz 2014.10 (c:\python27\lib\site-packages),
 pywin32 219 (c:\python27\lib\site-packages),
 readme 0.5.1 (c:\python27\lib\site-packages),
 restview 2.3.0 (c:\python27\lib\site-packages),
 scipy 0.14.0 (c:\python27\lib\site-packages),
 six 1.9.0 (c:\python27\lib\site-packages),
 snowballstemmer 1.2.0 (c:\python27\lib\site-packages)]

In [ ]: