本项目是我为课程《大模型视觉抓取6轴机械臂》 设计的6轴机械臂。
主要目标是尽量用市面上的标准件制作一个性能优秀,价格优惠的教学用途机械臂(2000元以内)。
If you have any questions, please submit issues or email me: [email]enpeicv@outlook.com[/email], have fun with it!
扫码加入微信WeChat交流群:
<img src="https://enpei-md.oss-cn-hangzhou.aliyuncs.com/202404161532376.png?x-oss-process=style/wp" style="width:200px;" />

一、Episode 1机械臂参数:
名称:Episode 1(意为第一代,可能根据学员需求,后续升级迭代)
本体:主要传动机构为铝合金和45号钢CNC加工零件,外壳为PLA 3D打印件。6自由度,6个42步进电机,4个高精度行星减速器,FOC闭环驱动板,CAN总线通信,负载500g,活动半径510mm,高重复精度。
夹爪:负压真空夹爪,25KG 舵机2指柔性夹爪。
软件:ROBODK上位机,正逆解算,拖拽示教,TCP 协议API编程,3D、6D抓取网络,多模态VLM、LLM等。
SDK API:TCP协议的API,支持各种编程语言,API有角度移动模式(MoveJ)、坐标位置模式、欧拉角模式、直线运动模式(MoveL)。
应用:已实现手眼标定(眼在手上、眼在手外)、3D、6D抓取等。
<img src="https://enpei-md.oss-cn-hangzhou.aliyuncs.com/202502111259136.png?x-oss-process=style/wp" style="zoom: 25%;" />
视频演示:B站点击播放
二、原理图:
整体:

电机驱动:
<img src="https://enpei-md.oss-cn-hangzhou.aliyuncs.com/202502141158971.png?x-oss-process=style/wp" style="zoom:50%;" />
夹爪:
三、物料表
四、API简介
链接机械臂:0.server.py
示例代码:
# 导入控制API
from episode_controller.episodeServer import MotorControlServer
......
# 配置服务器
parser = argparse.ArgumentParser(description="Motor Control Server")
# resume:是否在上次姿态恢复
parser.add_argument("--resume", type=bool, default=False, help="Resume previous session")
# usb_id:USB地址,最高支持6个机械臂同时驱动
parser.add_argument("--usb_id", type=int, default=1, help="USB handler ID, use pcaninfo to check")
# TCP协议IP地址
parser.add_argument("--ip", type=str, default="localhost", help="Server IP address")
# 端口
parser.add_argument("--port", type=int, default=12345, help="Server port")
# 启动TCP协议API服务器
server = MotorControlServer(resume=args.resume, usb_id=args.usb_id)
server.start_server(host=args.ip, port=args.port)
这样启动后,便可以使用支持TCP协议的编程语言去连接操作机械臂。
API列表:episodeServer.py
- home: 执行电机回零校准,将机械臂移动到初始位置
- gripper: 控制夹爪动作,根据参数决定抓取(闭合)或释放(打开)
- servo_gripper: 发送舵机抓取命令,设置夹爪角度
- robodk_simulation: 启动或关闭Robodk模拟功能
- set_free_mode: 设置电机自由模式,允许手动或自由控制电机
- get_motor_angles: 获取当前各电机的角度信息
- angle_mode: 通过角度模式直接控制各电机运动
- move_xyz_rotation: 使用逆运动学移动到指定XYZ位置
- move_linear_xyz_rotation: 沿直线路径移动到目标位置
def home(self):
"""
执行电机回零校准,将机械臂移动到初始位置。
返回:
- 归位操作所需的时间(秒)。
"""
command = {'action': 'home', 'params': None}
result = self.send_command(command)
if result is not None:
print("正在归位,预计耗时 {} 秒".format(result))
time.sleep(result)
return result
def gripper(self, on=0):
"""
控制夹爪的抓取和释放。
参数:
- on: 大于0表示抓取(闭合),否则表示释放(打开)。
返回:
- 机械臂响应的结果。
"""
action_str = "gripper_on" if on > 0 else "gripper_off"
command = {'action': action_str, 'params': None}
result = self.send_command(command)
time.sleep(0.05)
return result
def servo_gripper(self, degree):
"""
控制舵机夹爪动作,设置指定角度。
参数:
- degree: 舵机的目标角度(单位:度)。
返回:
- 机械臂响应的结果。
"""
command = {'action': 'servo_gripper', 'params': degree}
result = self.send_command(command)
time.sleep(1) # 等待动作完成
return result
def robodk_simulation(self, enable):
"""
启动或关闭Robodk模拟功能。
参数:
- enable: 布尔值,True表示启用模拟,False表示禁用。
返回:
- 机械臂响应的结果。
"""
params = 1 if enable else 0
command = {'action': 'robodk_simu', 'params': params}
result = self.send_command(command)
time.sleep(0.05)
return result
def set_free_mode(self, mode):
"""
设置电机自由模式,允许手动或自由控制电机,用来示教模式。
参数:
- mode: 自由模式参数,根据具体需求设定。
返回:
- 机械臂响应的结果。
"""
command = {'action': 'set_free_mode', 'params': mode}
result = self.send_command(command)
return result
def get_motor_angles(self):
"""
获取当前各电机编码器的角度值。
返回:
- 电机角度列表,如果获取失败则返回None。
"""
command = {'action': 'get_motor_angles', 'params': None}
result = self.send_command(command)
return result
def angle_mode(self, angles, speed_ratio=1.0):
"""
角度模式运动:根据指定角度直接控制各电机的运动。
参数:
- angles: 电机角度列表,顺序与实际电机对应。
- speed_ratio: 运动速度比例,默认1.0。
返回:
- 机械臂响应的结果。
"""
command = {'action': 'angle_mode', 'params': (angles, speed_ratio)}
result = self.send_command(command)
return result
def move_xyz_rotation(self, x, y, z, rotation_angles=[90, 0, 180], order='zyx'):
"""
使用逆运动学控制机械臂运动到指定的XYZ位置,并设置目标姿态。
参数:
- x, y, z: 目标位置坐标(单位:毫米或其他,根据实际设定)。
- rotation_angles: 目标姿态角度列表(默认为 [90, 0, 180])。
- order: 旋转顺序(如'zyx'),确保与控制端一致。
返回:
- 如果有解,返回运动执行时间(秒),否则返回 -1 表示无解。
"""
params = [x, y, z] + rotation_angles + [order]
command = {'action': 'move_xyz_rotation', 'params': params}
result = self.send_command(command)
if result != -1 and result is not None:
print("运动中,预计耗时 {} 秒".format(result))
time.sleep(result)
else:
print("目标位置或姿态无解")
return result
def move_linear_xyz_rotation(self, x, y, z, rotation_angles=[90, 0, 180], order='zyx'):
"""
直线模式运动:沿直线路径运动到指定位置,并同时调整末端姿态。
参数:
- x, y, z: 目标位置坐标。
- rotation_angles: 目标姿态角度列表。
- order: 旋转顺序(默认为 'zyx')。
返回:
- 如果运动规划成功,返回运动总时间(秒);否则返回 -1 表示无解。
"""
params = [x, y, z] + rotation_angles + [order]
command = {'action': 'move_linear_xyz_rotation', 'params': params}
result = self.send_command(command)
if result != -1 and result is not None:
print("直线运动规划成功,总共需要 {} 秒".format(result))
time.sleep(result)
else:
print("直线运动规划失败:目标无解")
return result
五、应用代码
5.1 示教模式
操作其中一台机械臂,另外一台跟着运动。
代码:3.teach_mode.py
5.2 3D抓取
眼在手外深度相机辅助3D平面抓取(末端欧拉角固定)
代码:2.air_sucker.py
5.3 6D抓取
眼在手上深度相机辅助3D平面抓取(末端欧拉角不固定)
代码:1.demo_episode_with_gripper.py
5.3 结合VLM、LLM
结合大语言模型、多模态模型
代码:
2.demo_VLM_grasp.py
3.demo_VLM_handler.py
点击下载代码