#!/usr/bin/env python3 # Software License Agreement (bsd license)


Download 183.03 Kb.
Sana28.12.2022
Hajmi183.03 Kb.
#1021416
Bog'liq
blockly python


#!/usr/bin/env python3


# Software License Agreement (BSD License)
#
# Copyright (c) 2022, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman

"""
# Notice


# 1. Changes to this file on Studio will not be preserved
# 2. The next conversion will overwrite the file with the same name
"""
import sys
import math
import time
import datetime
import random
import traceback
import threading

"""
# xArm-Python-SDK: https://github.com/xArm-Developer/xArm-Python-SDK


# git clone git@github.com:xArm-Developer/xArm-Python-SDK.git
# cd xArm-Python-SDK
# python setup.py install
"""
try:
from xarm.tools import utils
except:
pass
from xarm import version
from xarm.wrapper import XArmAPI

def pprint(*args, **kwargs):


try:
stack_tuple = traceback.extract_stack(limit=2)[0]
print('[{}][{}] {}'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), stack_tuple[1], ' '.join(map(str, args))))
except:
print(*args, **kwargs)

pprint('xArm-Python-SDK Version:{}'.format(version.__version__))

arm = XArmAPI('192.168.1.216')
arm.clean_warn()
arm.clean_error()
arm.motion_enable(True)
arm.set_mode(0)
arm.set_state(0)
time.sleep(1)

variables = {}


params = {'speed': 100, 'acc': 2000, 'angle_speed': 20, 'angle_acc': 500, 'events': {}, 'variables': variables, 'callback_in_thread': True, 'quit': False}

# Register error/warn changed callback


def error_warn_change_callback(data):
if data and data['error_code'] != 0:
params['quit'] = True
pprint('err={}, quit'.format(data['error_code']))
arm.release_error_warn_changed_callback(error_warn_change_callback)
arm.register_error_warn_changed_callback(error_warn_change_callback)

# Register state changed callback


def state_changed_callback(data):
if data and data['state'] == 4:
if arm.version_number[0] >= 1 and arm.version_number[1] >= 1 and arm.version_number[2] > 0:
params['quit'] = True
pprint('state=4, quit')
arm.release_state_changed_callback(state_changed_callback)
arm.register_state_changed_callback(state_changed_callback)

# Register counter value changed callback


if hasattr(arm, 'register_count_changed_callback'):
def count_changed_callback(data):
if not params['quit']:
pprint('counter val: {}'.format(data['count']))
arm.register_count_changed_callback(count_changed_callback)

# Register connect changed callback


def connect_changed_callback(data):
if data and not data['connected']:
params['quit'] = True
pprint('disconnect, connected={}, reported={}, quit'.format(data['connected'], data['reported']))
arm.release_connect_changed_callback(error_warn_change_callback)
arm.register_connect_changed_callback(connect_changed_callback)

if arm.error_code == 0 and not params['quit']:


code = arm.set_position(*[-397.9, -437.1, 373.7, 180.0, 0.0, 30.9], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[-169.8, -589.1, 373.7, 180.0, 0.0, 30.9], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[-169.8, -617.6, 144.8, 180.0, 0.0, 30.9], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[-169.8, -619.2, 144.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[-169.8, -619.2, 133.3, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_suction_cup(True, wait=False, delay_sec=0)
if code != 0:
params['quit'] = True
pprint('set_suction_cup, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[-169.8, -619.2, 425.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[396.4, -3.0, 425.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[116.5, 457.0, 425.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[116.5, 457.0, 144.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[116.5, 457.0, 131.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_suction_cup(False, wait=False, delay_sec=0)
if code != 0:
params['quit'] = True
pprint('set_suction_cup, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[116.5, 457.0, 425.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[396.4, -3.0, 425.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))
if arm.error_code == 0 and not params['quit']:
code = arm.set_position(*[-169.8, -619.2, 425.8, 180.0, 0.0, -67.3], speed=params['speed'], mvacc=params['acc'], radius=-1.0, wait=True)
if code != 0:
params['quit'] = True
pprint('set_position, code={}'.format(code))

# release all event


if hasattr(arm, 'release_count_changed_callback'):
arm.release_count_changed_callback(count_changed_callback)
arm.release_error_warn_changed_callback(state_changed_callback)
arm.release_state_changed_callback(state_changed_callback)
arm.release_connect_changed_callback(error_warn_change_callback)
Download 183.03 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling