1 Star 0 Fork 0

超神Fork/xArm-Python-SDK

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
1007-counter.py 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
vinman 提交于 6年前 . update
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2019, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman <vinman.wen@ufactory.cc> <vinman.cub@gmail.com>
"""
Description: Move Arc line(linear arc motion)
"""
import os
import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
#######################################################
"""
Just for test example
"""
if len(sys.argv) >= 2:
ip = sys.argv[1]
else:
try:
from configparser import ConfigParser
parser = ConfigParser()
parser.read('../robot.conf')
ip = parser.get('xArm', 'ip')
except:
ip = input('Please input the xArm ip address:')
if not ip:
print('input error, exit')
sys.exit(1)
########################################################
arm = XArmAPI(ip, is_radian=True)
arm.motion_enable(enable=True)
arm.set_mode(0)
arm.set_state(state=0)
def callback_count_changed(item):
print('counter val: {}'.format(item['count']))
arm.register_count_changed_callback(callback_count_changed)
arm.reset(wait=True)
paths = [
[300, 0, 150, -180, 0, 0],
[300, 200, 250, -180, 0, 0],
[500, 200, 150, -180, 0, 0],
[500, -200, 250, -180, 0, 0],
[300, -200, 150, -180, 0, 0],
[300, 0, 250, -180, 0, 0],
[300, 200, 350, -180, 0, 0],
[500, 200, 250, -180, 0, 0],
[500, -200, 350, -180, 0, 0],
[300, -200, 250, -180, 0, 0],
[300, 0, 350, -180, 0, 0],
]
arm.set_position(*paths[0], wait=True)
_, angles = arm.get_servo_angle()
arm.set_pause_time(0.2)
def move():
ret = arm.set_servo_angle(angle=angles, is_radian=False, speed=50, wait=False)
if ret < 0:
print('set_servo_angle, ret={}'.format(ret))
return -1
for path in paths:
ret = arm.set_position(*path[:6], radius=0, is_radian=False, wait=False, speed=300)
if ret < 0:
print('set_position, ret={}'.format(ret))
return -1
return 0
arm.set_counter_reset()
for i in range(100):
if move() != 0:
break
arm.set_counter_increase()
arm.reset(wait=True)
arm.disconnect()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/supernatural-fork/xArm-Python-SDK.git
git@gitee.com:supernatural-fork/xArm-Python-SDK.git
supernatural-fork
xArm-Python-SDK
xArm-Python-SDK
master

搜索帮助