目录

  • 一、电路连接
  • 二、实际操作
    • 1.1、舵机串联的ID修改方式
    • 1.2、例程代码修改
  • 三、结果展示

一、电路连接

参考我第一篇文章里面的电路连接

仿生蛇形机器人01、Dynamixel MX-64AR舵机控制例程的使用【Python 1.0协议】

在原有基础上串联一个舵机

(注意:我这里是串联两个舵机,利用4pin接口线随意连接一个母线端子即可,如果串联多个舵机,要注意连接的方式,得统一方便控制。)

二、实际操作

1.1、舵机串联的ID修改方式

按理来说,如下图,在Tools中应该会有一个ID Inspection的选项,可能是我的版本太低了,每次跳出来有个升级选项,我没管,这里我更新一下。

跳出的更新窗口

点击----重新启动----安装完成

这时候我们看见了ID Inspection的选项----点击ID Inspection----选择正确的com口和波特率----点击scan**(注意:这里我发现一个问题,原来这个功能并不是所有版本都支持的,看下图)**

翻译得

那么,很遗憾,像我们不符合条件的舵机,就真的只能一个一个改了,然后再串联一起。单个修改可以参考我的第一篇文章,里面有关于ID的单个修改。

仿生蛇形机器人01、Dynamixel MX-64AR舵机控制例程的使用【Python 1.0协议】

1.2、例程代码修改

说明:由于我们一般操作的例程就是read_write.py(我是用的是这个python 1.0版本),我们只要在原有的基础上进行ID定义就行了,看下面的两个代码。

修改前代码:read_write.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-################################################################################
# Copyright 2017 ROBOTIS CO., LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################# Author: Ryu Woon Jung (Leon)#
# *********     Read and Write Example      *********
#
#
# Available DXL model on this example : All models using Protocol 1.0
# This example is tested with a DXL MX-28, and an USB2DYNAMIXEL
# Be sure that DXL MX properties are already set as %% ID : 1 / Baudnum : 34 (Baudrate : 57600)
#import osif os.name == 'nt':import msvcrtdef getch():return msvcrt.getch().decode()
else:import sys, tty, termiosfd = sys.stdin.fileno()old_settings = termios.tcgetattr(fd)def getch():try:tty.setraw(sys.stdin.fileno())ch = sys.stdin.read(1)finally:termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)return chfrom dynamixel_sdk import *                    # Uses Dynamixel SDK library# Control table address
ADDR_MX_TORQUE_ENABLE      = 24               # Control table address is different in Dynamixel model
ADDR_MX_GOAL_POSITION      = 30
ADDR_MX_PRESENT_POSITION   = 36# Protocol version
PROTOCOL_VERSION            = 1.0               # See which protocol version is used in the Dynamixel# Default setting
DXL_ID                      = 1                 # Dynamixel ID : 1
BAUDRATE                    = 57600             # Dynamixel default baudrate : 57600
DEVICENAME                  = 'COM13'    # Check which port is being used on your controller# ex) Windows: "COM1"   Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"TORQUE_ENABLE               = 1                 # Value for enabling the torque
TORQUE_DISABLE              = 0                 # Value for disabling the torque
DXL_MINIMUM_POSITION_VALUE  = 10           # Dynamixel will rotate between this value
DXL_MAXIMUM_POSITION_VALUE  = 4000            # and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.)
DXL_MOVING_STATUS_THRESHOLD = 20                # Dynamixel moving status thresholdindex = 0
dxl_goal_position = [DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE]         # Goal position# Initialize PortHandler instance
# Set the port path
# Get methods and members of PortHandlerLinux or PortHandlerWindows
portHandler = PortHandler(DEVICENAME)# Initialize PacketHandler instance
# Set the protocol version
# Get methods and members of Protocol1PacketHandler or Protocol2PacketHandler
packetHandler = PacketHandler(PROTOCOL_VERSION)# Open port
if portHandler.openPort():print("Succeeded to open the port")
else:print("Failed to open the port")print("Press any key to terminate...")getch()quit()# Set port baudrate
if portHandler.setBaudRate(BAUDRATE):print("Succeeded to change the baudrate")
else:print("Failed to change the baudrate")print("Press any key to terminate...")getch()quit()# Enable Dynamixel Torque
dxl_comm_result, dxl_error = packetHandler.write1ByteTxRx(portHandler, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE)
if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))
elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))
else:print("Dynamixel has been successfully connected")while 1:print("Press any key to continue! (or press ESC to quit!)")if getch() == chr(0x1b):break# Write goal positiondxl_comm_result, dxl_error = packetHandler.write4ByteTxRx(portHandler, DXL_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index])if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))while 1:# Read present positiondxl_present_position, dxl_comm_result, dxl_error = packetHandler.read4ByteTxRx(portHandler, DXL_ID, ADDR_MX_PRESENT_POSITION)if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))print("[ID:%03d] GoalPos:%03d  PresPos:%03d" % (DXL_ID, dxl_goal_position[index], dxl_present_position))if not abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD:break# Change goal positionif index == 0:index = 1else:index = 0# Disable Dynamixel Torque
dxl_comm_result, dxl_error = packetHandler.write1ByteTxRx(portHandler, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE)
if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))
elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))# Close port
portHandler.closePort()

修改后代码:read_write1.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-################################################################################
# Copyright 2017 ROBOTIS CO., LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################# Author: Ryu Woon Jung (Leon)#
# *********     Read and Write Example      *********
#
#
# Available DXL model on this example : All models using Protocol 1.0
# This example is tested with a DXL MX-28, and an USB2DYNAMIXEL
# Be sure that DXL MX properties are already set as %% ID : 1 / Baudnum : 34 (Baudrate : 57600)
#import osif os.name == 'nt':import msvcrtdef getch():return msvcrt.getch().decode()
else:import sys, tty, termiosfd = sys.stdin.fileno()old_settings = termios.tcgetattr(fd)def getch():try:tty.setraw(sys.stdin.fileno())ch = sys.stdin.read(1)finally:termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)return chfrom dynamixel_sdk import *                    # Uses Dynamixel SDK library# Control table address
ADDR_MX_TORQUE_ENABLE      = 24               # Control table address is different in Dynamixel model
ADDR_MX_GOAL_POSITION      = 30
ADDR_MX_PRESENT_POSITION   = 36# Protocol version
PROTOCOL_VERSION            = 1.0               # See which protocol version is used in the Dynamixel# Default setting
DXL_ID                      = 1                 # Dynamixel ID : 1
DXL2_ID                     = 2                 # Dynamixel ID : 2
BAUDRATE                    = 57600             # Dynamixel default baudrate : 57600
DEVICENAME                  = '/dev/ttyUSB0'    # Check which port is being used on your controller# ex) Windows: "COM1"   Linux: "/dev/ttyUSB0" Mac: "/dev/tty.usbserial-*"TORQUE_ENABLE               = 1                 # Value for enabling the torque
TORQUE_DISABLE              = 0                 # Value for disabling the torqueDXL_MINIMUM_POSITION_VALUE  = 10                # Dynamixel will rotate between this value
DXL_MAXIMUM_POSITION_VALUE  = 4000              # and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.)
DXL_MOVING_STATUS_THRESHOLD = 20                # Dynamixel moving status thresholdDXL2_MINIMUM_POSITION_VALUE  = 500               # Dynamixel will rotate between this value
DXL2_MAXIMUM_POSITION_VALUE  = 3000              # and this value (note that the Dynamixel would not move when the position value is out of movable range. Check e-manual about the range of the Dynamixel you use.)
DXL2_MOVING_STATUS_THRESHOLD = 10                # Dynamixel moving status thresholdindex = 0
index2 = 0
dxl_goal_position = [DXL_MINIMUM_POSITION_VALUE, DXL_MAXIMUM_POSITION_VALUE]         # Goal position
dxl2_goal_position = [DXL2_MINIMUM_POSITION_VALUE, DXL2_MAXIMUM_POSITION_VALUE]         # Goal position# Initialize PortHandler instance
# Set the port path
# Get methods and members of PortHandlerLinux or PortHandlerWindows
portHandler = PortHandler(DEVICENAME)# Initialize PacketHandler instance
# Set the protocol version
# Get methods and members of Protocol1PacketHandler or Protocol2PacketHandler
packetHandler = PacketHandler(PROTOCOL_VERSION)# Open port
if portHandler.openPort():print("Succeeded to open the port")
else:print("Failed to open the port")print("Press any key to terminate...")getch()quit()# Set port baudrate
if portHandler.setBaudRate(BAUDRATE):print("Succeeded to change the baudrate")
else:print("Failed to change the baudrate")print("Press any key to terminate...")getch()quit()# Enable Dynamixel Torque
dxl_comm_result, dxl_error = packetHandler.write1ByteTxRx(portHandler, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE)
dxl_comm_result, dxl_error = packetHandler.write1ByteTxRx(portHandler, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_ENABLE)
if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))
elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))
else:print("Dynamixel has been successfully connected")while 1:print("Press any key to continue! (or press ESC to quit!)")if getch() == chr(0x1b):break# Write goal positiondxl_comm_result, dxl_error = packetHandler.write4ByteTxRx(portHandler, DXL_ID, ADDR_MX_GOAL_POSITION, dxl_goal_position[index])dxl_comm_result, dxl_error = packetHandler.write4ByteTxRx(portHandler, DXL2_ID, ADDR_MX_GOAL_POSITION, dxl2_goal_position[index2])if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))while 1:# Read present positiondxl_present_position, dxl_comm_result, dxl_error = packetHandler.read4ByteTxRx(portHandler, DXL_ID, ADDR_MX_PRESENT_POSITION)dxl2_present_position, dxl_comm_result, dxl_error = packetHandler.read4ByteTxRx(portHandler, DXL2_ID, ADDR_MX_PRESENT_POSITION)if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))print("[ID:%03d] GoalPos:%03d  PresPos:%03d" % (DXL_ID, dxl_goal_position[index], dxl_present_position))print("[ID:%03d] GoalPos:%03d  PresPos:%03d" % (DXL2_ID, dxl2_goal_position[index2], dxl2_present_position))if not ((abs(dxl_goal_position[index] - dxl_present_position) > DXL_MOVING_STATUS_THRESHOLD) and ((dxl2_goal_position[index2] - dxl2_present_position) > DXL2_MOVING_STATUS_THRESHOLD)):break# Change goal positionif index == 0:index = 1else:index = 0if index2 == 0:index2 = 1else:index2 = 0# Disable Dynamixel Torque
dxl_comm_result, dxl_error = packetHandler.write1ByteTxRx(portHandler, DXL_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE)
dxl_comm_result, dxl_error = packetHandler.write1ByteTxRx(portHandler, DXL2_ID, ADDR_MX_TORQUE_ENABLE, TORQUE_DISABLE)
if dxl_comm_result != COMM_SUCCESS:print("%s" % packetHandler.getTxRxResult(dxl_comm_result))
elif dxl_error != 0:print("%s" % packetHandler.getRxPacketError(dxl_error))# Close port
portHandler.closePort()

建议,将第二个代码放入Atom中打开,对比着第一个代码看,有助于理解与运用。

三、结果展示

在这里舵机是运动的

仿生蛇形机器人03、Dynamixel MX-64AR舵机串联两个修改Demo(例程)进行调节相关推荐

  1. 仿生蛇形机器人04、Dynamixel MX-64AR舵机串联实现仿生蛇基本步态

    目录 一.3D结构 二.实现原理 三.代码实现 四.成果演示 总结 一.3D结构 外观通过solidworks建模,用大昆3d打印机打印. 关节展示 二.实现原理 首先要看过我的第一篇文章,知道dem ...

  2. 仿生蛇形机器人01、Dynamixel MX-64AR舵机控制例程的使用【Python 1.0协议】

    目录 前言 一.资料获取 二.下载Atom.DYNAMIXEL Wizard 2.0 2.1.Atom的安装 2.2.DYNAMIXEL Wizard 2.0的安装 三.实操过程 3.1.电路连接 3 ...

  3. 如何在Python中串联两个列表?

    如何在Python中串联两个列表? 例: listone = [1, 2, 3] listtwo = [4, 5, 6] 预期结果: >>> joinedlist [1, 2, 3, ...

  4. 两个led并联和一个电阻串联两个灯不能同时亮问题

    两个led并联在和一个电阻串联,出现两个led不同时亮时只能红色的led可以量,两个led可以单独亮. 连接方法如下. 原因分析: 由于两个led一个是红色一个是蓝色,怀疑是参数不一致导致的.查看两个 ...

  5. 两台虚拟服务器如何串联,两台tp-link路由器串联设置教程

    摘 要 [导读]两台tp-link路由器串联设置教程图文教程,详细信息请阅读下文!网友提问:两个TP-Link路由器串联怎么设置?有两台TP-Link无线路由器,用网线把这两个TP-Link路由器串联 ...

  6. 串联两个路由器互相访问路由表设置记录

    串联两个路由器互相访问路由表设置记录 好久没有登陆CSDN,发现账号由于密码过于简单,可能被盗了,博文里被发布了好多恶意的广告,都是什么找小姐内容全套什么的来着,乍一看账号里还有200积分,就干脆重新 ...

  7. 仿生蛇形机器人02、Dynamixel MX-64AR舵机出现软件故障、无法调节角度

    目录 一.问题描述 二.解决方法 三.结果展示 [参考文章] 一.问题描述 当打开上位机Dynamixel Wizard 2.0时候,出现下图(或者其他软件调试问题)问题时. 二.解决方法 注:舵机固 ...

  8. i.MX RT开发笔记-03 | i.MX RT1062地址空间映射及启动方式

    系列文章目录 i.MX RT开发笔记-01 | 初识 i.MX RT1062 跨界MCU i.MX RT开发笔记-02 | i.MX RT1062开发环境搭建(MDK芯片包.NXP SDK详解) 文章 ...

  9. python舵机控制程序_树莓派PWM控制舵机的两种方式

    PWM控制舵机简介 通常情况下,伺服电机(舵机)是由一个标准的直流系统和一个内部反馈控制装置(一个减速齿轮和电位计)来组成的.伺服电机(舵机)的主要作用是将齿轮轴旋转到一个预定义的方向上.伺服电机(舵 ...

最新文章

  1. 右脑编程法--左脑是基础(4)之语言篇
  2. em算法 实例 正态分布_【机器学习】EM算法详细推导和讲解
  3. python下载文件暂停恢复_selenium+Python如何取消Chrome下载文件的‘保留’‘放弃’提示?...
  4. LeetCode 257 二叉树的所有路径
  5. Dubbo 集成 ZooKeeper 注册中心实现服务调用
  6. Glut 回调函数小结
  7. thymeleaf if 条件判断
  8. ORA-12505: TNS: 监听程序当前无法识别连接描述符中所给出的 SID
  9. 什么是数字证书?数字证书在哪办理?
  10. 使用Canvas绘制简单工程符号
  11. hmdb51数据集,视频+标签
  12. XCode7报 App Transport Security has blocked a cleartext HTTP (http://) resource load since it is inse
  13. MATLAB 绘制平行六面体
  14. 微信小程序getUserProfile,获取头像和昵称实现登录
  15. bert中文使用总结
  16. sk_buff 介绍
  17. 杜比服务器网站,杜比服务器远程账号和密码
  18. 滑动差分倒谱系数 matlab,【网安学术】基于音频特征参数的多语种分类算法
  19. 关于 go run 命令执行过程中的“坑坑点点”
  20. 如何制作一个纸张的撕裂效果

热门文章

  1. bump map(凹凸贴图)的一个简单生成方法
  2. 国内移动互联网广告平台7宗罪
  3. 史上最全的IDEA快捷键总结
  4. 强势测试思维和弱势测试思维
  5. dell台式机进入安全模式_戴尔电脑如何进入安全模式
  6. 教你用Python感知女朋友的情绪变化?
  7. php定义指定长度数组,PHP中定义数组时,不需要指定数组的大小。
  8. HBase Shell启动缓慢及操作耗时长的原因分析与解决
  9. 今天下午去京东物流应聘快递员
  10. 详细解读ARM寄存器之CPSR