用python控制dynamixel ax-12+伺服的库

pyax12的Python项目详细描述


Documentation Status

PyAX-12

版权所有(C)20102015 Jeremie Decock(http://www.jdhp.org

http://www.vorobotics.com

说明

PyAX-12是要控制的开源轻量级python库 Dynamixel AX-12+执行器。

Watch a demo on youtube

注意:

This project is still in beta stage, so the API is not finalized yet.

依赖性

pyax-12在gnu/linux(debian 8)和macosx下被测试为与python 3.4一起工作。 (Mavericks 10.9)和Windows(7)。 最新gnu/linux、maxosx和windows系统下的任何python 3.x版本 也应该适合。

pyax-12也可以通过gpio连接器在Raspberry Pi上运行。

Python-serial是安装pyax-12所需的唯一依赖项。

注意:

If you use ^{tt1}$ to install PyAX-12, Python-serial will be automatically downloaded and installed (see the following install section).

安装

gnu/linux

您可以使用以下命令安装、升级和卸载pyax-12(在 终端):

pip install --pre pyax12
pip install --upgrade pyax12
pip uninstall pyax12

或者,如果您下载了pyax-12源代码:

python3 setup.py install

窗口

您可以使用以下命令安装、升级和卸载pyax-12(在 command prompt):

py -m pip install --pre pyax12
py -m pip install --upgrade pyax12
py -m pip uninstall pyax12

或者,如果您下载了pyax-12源代码:

py setup.py install

macosx

您可以使用以下命令安装、升级和卸载pyax-12(在 终端):

pip install --pre pyax12
pip install --upgrade pyax12
pip uninstall pyax12

或者,如果您下载了pyax-12源代码:

python3 setup.py install

硬件设置

Official AX-12 documentation(存档)。

通过usb端口将ax-12执行器连接到计算机(包括覆盆子pi计算机)

可以使用USB2Dynamixel将ax-12执行器连接到计算机。 实际上,任何ftdi串行/usb转换器设备都应该做这项工作。

有关usb2dynamixel设置的更多信息,请检查 official documentation

通过gpio端口将ax-12执行器连接到覆盆子pi

需要一个小的电子电路来转换覆盆子脉冲信号(开 RX和TX管脚)连接到dynamixels所需的半双工管脚(请参见 this archive)。

将全双工转换为半双工的芯片是74HC126/74HC04 或74LS241。

使用774hc126/74hc04控制dynamixel ax-12

对于74HC126/74HC04,请检查以下页面:

UART配置

将带宽增加到1Mbps可能需要特殊设置(未测试 但是):

否则,将带宽保持在57600bps应该是现成的 (确保使用正确的dynamixel id和dynamixel带宽 正确设置为56700bps)。

示例用法

在下面的示例中,dynamixel_idportbaudrate 应根据您的配置调整值:

  • 对于linux用户:
    • port值应该类似于
      • “/天ev/ttys0“,”/dev/ttys1“,…如果您使用实际的串行端口
      • “/dev/ttyusb0”、“/dev/ttyusb1”……如果使用USB to serial适配器 (就像USB2Dynamixel适配器一样)
    • baudrate值应与中配置的值相同 dynamixel单位
  • 对于windows用户:
    • port值应该类似于“com2”、“com3”…(请参见 com端口在windows中的配置device manager
    • baudrate值应与中配置的值相同 dynamixel单元窗口device manager(即检查 com端口在windows中的配置device manager
  • 对于macosx用户:
    • port值应该类似于“/dev/tty.usbserial xxx” 使用USB to serial适配器,如USB2Dynamixel适配器
    • baudrate值应与中配置的值相同 dynamixel单位
  • 对于raspberry pi用户:
    • 如果你想通过gpio连接器控制ax-12执行器,别忘了 在Connection构造函数中将rpi_gpio设置为True(检查 以下第一个示例)
    • port值应该是“/dev/ttyama0”

如果使用USB2Dynamixel设备,请确保其开关设置为“ttl”。

其他一些例子可以在examples目录中找到。

ping动态像素

如果指定的dynamixel单元已连接并且 在给定的baudrate中可用;否则它将打印False

from pyax12.connection import Connection

# Connect to the serial port
serial_connection = Connection(port="/dev/ttyUSB0", baudrate=57600)

dynamixel_id = 3

# Ping the third dynamixel unit
is_available = serial_connection.ping(dynamixel_id)

print(is_available)

# Close the serial connection
serial_connection.close()

将ax-12执行器连接到gpio连接器的覆盆子pi用户应该 请改用以下代码:

from pyax12.connection import Connection

# Connect to the serial port
serial_connection = Connection(port="/dev/ttyAMA0", rpi_gpio=True)

dynamixel_id = 3

# Ping the third dynamixel unit
is_available = serial_connection.ping(dynamixel_id)

print(is_available)

# Close the serial connection
serial_connection.close()

扫描(搜索可用的dynamixel单位)

此代码段打印连接的可用dynamixel单元的id列表(位于 给定的baudrate)。

from pyax12.connection import Connection

# Connect to the serial port
serial_connection = Connection(port="/dev/ttyUSB0", baudrate=57600)

# Ping the dynamixel unit(s)
ids_available = serial_connection.scan()

for dynamixel_id in ids_available:
    print(dynamixel_id)

# Close the serial connection
serial_connection.close()

将第一个dynamixel单元移动到不同的位置角度

这个片段将第一个dynamixel单元移动到0°,然后是-45°,-90°,-135°, - 150°(最大CW角),+150°(最大CW角),+135°,+90°,+45° 最后回到0°。

from pyax12.connection import Connection
import time

# Connect to the serial port
serial_connection = Connection(port="/dev/ttyUSB0", baudrate=57600)

dynamixel_id = 1

# Go to 0°
serial_connection.goto(dynamixel_id, 0, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to -45° (45° CW)
serial_connection.goto(dynamixel_id, -45, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to -90° (90° CW)
serial_connection.goto(dynamixel_id, -90, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to -135° (135° CW)
serial_connection.goto(dynamixel_id, -135, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to -150° (150° CW)
serial_connection.goto(dynamixel_id, -150, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to +150° (150° CCW)
serial_connection.goto(dynamixel_id, 150, speed=512, degrees=True)
time.sleep(2)    # Wait 2 seconds

# Go to +135° (135° CCW)
serial_connection.goto(dynamixel_id, 135, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to +90° (90° CCW)
serial_connection.goto(dynamixel_id, 90, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go to +45° (45° CCW)
serial_connection.goto(dynamixel_id, 45, speed=512, degrees=True)
time.sleep(1)    # Wait 1 second

# Go back to 0°
serial_connection.goto(dynamixel_id, 0, speed=512, degrees=True)

# Close the serial connection
serial_connection.close()

错误报告

要搜索或报告错误,请使用pyax-12错误跟踪器:

https://github.com/jeremiedecock/pyax12/issues

相关库

控制Dynamixel AX-12+执行器的其他库在 以下(非全面)列表:

许可证

PyAX-12库是根据 MIT License

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在扩展类中将Java重写为抽象的非抽象方法   java可滚动视图   java Android:隐藏操作栏,保持标签   java如何在Hibernate中使用@Qualifier   java如何在spring MVC中进行Http会话管理以获取数据库中的数据   java如何为TictaToe游戏创建HashMap   java在消息资源文件中查找未使用的值   从源代码构建Kafka时发生java错误   c中的java调用optaplanner DLL#   无法通过Java API访问orientdb函数   任务的java执行失败“:app:ProcessDebuggGoogleService”   java在整个模拟过程中保持代理之间的距离不变   如何在Java中使用BouncyCastle PGP实用程序实现增量加密?   java在安卓中计算画布点的距离   Java回文修订   java在Firebase数据库中存储变量的必要性   java如何使用gquery手势插件在页面上启用文本突出显示?   java如何在Apache camel中使用POST调用REST?