task2 <<
Previous Next >> s2
s1
stage1升降裝置
1.程式控制方式:python remote api
內容:在stage1報告中,因還未熟悉coppelia的操作還未將coppelia模擬出來及寫入程式,但經過後來自己慢慢摸索和嘗試,已經把整體大概都模擬出來了,以下是我用remote api對場景做控制的畫面
coppelia檔案下載處:S1-2.zip
api.py檔案下載處:S1-2api.zip
程式碼
import sim as vrep
import math
import random
import time
import keyboard
print ('Start')
# Close eventual old connections
vrep.simxFinish(-1)
# Connect to V-REP remote server
clientID = vrep.simxStart('192.168.50.217', 19997, True, True, 5000, 5)
if clientID !=-1:
print ('Connected to remote API server')
res = vrep.simxAddStatusbarMessage(
clientID, "40823204",
vrep.simx_opmode_oneshot)
if res not in (vrep.simx_return_ok, vrep.simx_return_novalue_flag):
print("Could not add a message to the status bar.")
opmode = vrep.simx_opmode_oneshot_wait
STREAMING = vrep.simx_opmode_streaming
vrep.simxStartSimulation(clientID, opmode)
ret,joint0=vrep.simxGetObjectHandle(clientID,"joint0",opmode)
ret,joint1=vrep.simxGetObjectHandle(clientID,"joint1",opmode)
dy=0
dr=0
vrep.simxSetJointTargetPosition(clientID,joint0,dy,opmode)
vrep.simxSetJointTargetPosition(clientID,joint1,dr,opmode)
while True:
#Clockwise
if keyboard.is_pressed("2"):
dy=dy-0.1
dr=dr+0.1
vrep.simxSetJointTargetPosition(clientID,joint0,dy,opmode)
vrep.simxSetJointTargetPosition(clientID,joint1,dr,opmode)
print("go")
2.程式控制方式:Lua script
程式碼
function sysCall_init()
-- do some initialization here
joint=sim.getObjectHandle('joint0')
joint1=sim.getObjectHandle('joint1')
dy=0
dr=0
dt=5
end
function sysCall_actuation()
message,auxiliaryData=sim.getSimulatorMessage()
while message~=-1 do
if (message==sim.message_keypress) then
if (auxiliaryData[1]==32) then
dy=dy-dt
dr=dr+dt
sim.setJointTargetPosition(joint,dy*math.pi/180)
sim.setJointTargetPosition(joint1,dr*math.pi/180)
end
end
message,auxiliaryData=sim.getSimulatorMessage()
end
end
task2 <<
Previous Next >> s2