逆向運動學函式-鍵盤控制與程式迴圈方式 <<
Previous Next >> stage3 專案
Python remote API 逆向運動學函式
api 檔案與程式
import sim as vrep
import sys
import time
import math
vrep.simxFinish(-1)
clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5)
if clientID!= -1:
print("Connected to remote server")
else:
print('Connection not successful')
vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot)
def move(j1,j2,j4):
ret,joint1=vrep.simxGetObjectHandle(clientID,"joint1",vrep.simx_opmode_blocking)
ret,joint2=vrep.simxGetObjectHandle(clientID,"joint2",vrep.simx_opmode_blocking)
ret,joint4=vrep.simxGetObjectHandle(clientID,"joint4",vrep.simx_opmode_blocking)
jointHandle=[joint1,joint2,joint4]
j=[j1*math.pi/180,j2*math.pi/180,j4*math.pi/180]
for i in range(3):
vrep.simxSetJointPosition(clientID,jointHandle[i],j[i],vrep.simx_opmode_oneshot)
time.sleep(0.5)
def suck():
vrep.simxSetIntegerSignal(clientID,"active",1,vrep.simx_opmode_oneshot_wait)
def quit():
vrep.simxSetIntegerSignal(clientID,"active",0,vrep.simx_opmode_oneshot_wait)
while True:
move(0,0,0)
quit()
move(0,0,-2)
suck()
move(40.9472,-68.978,0)
quit()
move(40.9472,-68.978,0)
move(40.9472,-68.978,-2)
suck()
move(40.9472,-68.978,0)
move(-158.2529,-89.6799,0)
quit()
move(-158.2529,-89.6799,0)
move(-158.2529,-89.6799,-2)
suck()
move(-158.2529,-89.6799,0)
心得:
這次作業對我來說非常的有挑戰性,由於我對程式還沒有很熟練,導致在製作時一直發生問題,詢問 40823131跟 40823112,在他們指導下瞭解FOR迴圈的製作與API,讓我了解到哪裡需要加強
逆向運動學函式-鍵盤控制與程式迴圈方式 <<
Previous Next >> stage3 專案