main1
#
"""
测试Scale(移动滑块)
用于在指定的数值区间,通过滑块的移动来选择值。
"""
'''Scale为输出限定范围的数字区间,可以为之指定最大值,最小值及步距值等。
from_ 指定最小值
to指定最大值
(主要就是前两项)
resolution指定步长,默认是1
tickinterval设置刻度
orient设置横向(HORIZONTAL)和竖向(VERTICAL)
'''
from tkinter import *
a=[0,0,0,0,0,0]
root = Tk()
root.geometry('500x500')
def test01(value):
a[0]=value
print('关节a1:', a[0])
def test02(value):
a[1]=value
print('关节a2:', a[1])
def test03(value):
a[2]=value
print('关节a3:', a[2])
def test04(value):
a[3]=value
print('关节a4:', a[3])
def test05(value):
a[4]=value
print('关节a5:', a[4])
def test06(value):
a[5]=value
print('关节a6:', a[5])
s1 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test01)
s2 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test02)
s3 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test03)
s4 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test04)
s5 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test05)
s6 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test06)
s1.pack()
s2.pack()
s3.pack()
s4.pack()
s5.pack()
s6.pack()
root.mainloop()
main2
'''
完整的GUI UR5 机械臂控制
在Vrep中添加一个UR5机械臂
在Vrep服务端的脚本添加启动服务器就可以
simRemoteApi.start(19999)
'''
import sys
import numpy as np
import math
import matplotlib.pyplot as mpl
import time
try:
import sim
except:
print ('--------------------------------------------------------------')
print ('"sim.py" could not be imported. This means very probably that')
print ('either "sim.py" or the remoteApi library could not be found.')
print ('Make sure both are in the same folder as this file,')
print ('or appropriately adjust the file "sim.py"')
print ('--------------------------------------------------------------')
print ('')
import time
print ('Program started')
sim.simxFinish(-1) # just in case, close all opened connections
clientID=sim.simxStart('127.0.0.1',19999,True,True,5000,5) # 连接地址、连接端口、等待直到连接、一旦断开就不再连接、超时ms、通讯周期
if clientID!=-1:
print ('Connected to remote API server')
sim.simxAddStatusbarMessage(clientID,'Hello CoppeliaSim!',sim.simx_opmode_oneshot)
sim.simxStartSimulation(clientID, sim.simx_opmode_blocking)
print("Simulation start")
time.sleep(2)
jointHandle=[-1,-1,-1,-1,-1,-1]
jointHandle = np.zeros((6,), dtype=np.int)
for i in range(6):
#jointHandles[i]='UR5_joint'+str(i+1)
errorCode, returnHandle = sim.simxGetObjectHandle(clientID, 'UR5_joint' + str(i + 1), sim.simx_opmode_blocking)
jointHandle[i] = returnHandle
else:
print('errro')
from tkinter import *
a=[0,0,0,0,0,0]
root = Tk()
root.geometry('500x500')
def test01(value):
a[0]=int(value)
print('关节:', a)
sim.simxPauseCommunication(clientID, True)
for i in range(6):
sim.simxSetJointTargetPosition(clientID, jointHandle[i], a[i]*math.pi/180, sim.simx_opmode_oneshot)
sim.simxPauseCommunication(clientID, False)
time.sleep(0.01)
def test02(value):
a[1]=int(value)
print('关节:', a)
sim.simxPauseCommunication(clientID, True)
for i in range(6):
sim.simxSetJointTargetPosition(clientID, jointHandle[i], a[i]*math.pi/180, sim.simx_opmode_oneshot)
sim.simxPauseCommunication(clientID, False)
time.sleep(0.01)
def test03(value):
a[2]=int(value)
print('关节:', a)
sim.simxPauseCommunication(clientID, True)
for i in range(6):
sim.simxSetJointTargetPosition(clientID, jointHandle[i], a[i]*math.pi/180, sim.simx_opmode_oneshot)
sim.simxPauseCommunication(clientID, False)
time.sleep(0.01)
def test04(value):
a[3]=int(value)
print('关节:', a)
sim.simxPauseCommunication(clientID, True)
for i in range(6):
sim.simxSetJointTargetPosition(clientID, jointHandle[i], a[i]*math.pi/180, sim.simx_opmode_oneshot)
sim.simxPauseCommunication(clientID, False)
time.sleep(0.01)
def test05(value):
a[4]=int(value)
print('关节:', a)
sim.simxPauseCommunication(clientID, True)
for i in range(6):
sim.simxSetJointTargetPosition(clientID, jointHandle[i], a[i]*math.pi/180, sim.simx_opmode_oneshot)
sim.simxPauseCommunication(clientID, False)
time.sleep(0.01)
def test06(value):
a[5]=int(value)
print('关节:', a)
sim.simxPauseCommunication(clientID, True)
for i in range(6):
sim.simxSetJointTargetPosition(clientID, jointHandle[i], a[i]*math.pi/180, sim.simx_opmode_oneshot)
sim.simxPauseCommunication(clientID, False)
time.sleep(0.01)
s1 = Scale(root, from_=-180, to=180, length=360, tickinterval=30, orient=HORIZONTAL, command=test01)
s1.pack()
root.mainloop()
# Before closing the connection to CoppeliaSim, make sure that the last command sent out had time to arrive. You can guarantee this with (for example):
sim.simxGetPingTime(clientID)
# Now close the connection to CoppeliaSim:
sim.simxStopSimulation(clientID, sim.simx_opmode_blocking) #停止仿真
sim.simxFinish(clientID)