NFU-MDE-40823108-KAO,YU-CHE-cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • KMOLab basis
    • Cmsimde create
    • Python program
    • SSH key produce
    • SSH putty settings
    • Leo Edit Blog
    • Leo Edit Reveal
    • Synergy
  • Coppeliasim basic
    • Import objects
    • Divide object
    • Appearance setting
    • Joint settings
    • Orchestration objects
    • Proximity sensor
  • Midterm
    • W1
    • W2
    • W3
      • work
    • W4
    • W5
    • W6
    • W7
    • W8
    • W9
  • Final
    • W10-task1
    • W11-task2
    • W12-task3
    • W13
    • W14
    • W15
    • W16
    • W17
    • W18
  • Stage1-ag1
  • Stage2-ag1
  • Stage3-ag1
  • phone webcam
    • ios for Webcam
    • Android for Webcam
  • Github sever issue
W10-task1 << Previous Next >> W12-task3

W11-task2

執行Task2,stage1 與 stage2 所完成的 coppeliasim 場景, 採 Python remote API 進行操控, 並將過程拍成影片。

CoppeliaSim 使用 4.2.0 版.

將stage1 與 stage2 所完成的coppeliasim場景, 使用 Python remote API 進行操控:

 CoppeliaSim 場景進行操控:

首先將下方紅框處的3個檔案與要執行的.ttt檔案放在同一個資寮夾。

接下來將.Py檔放入(Untitled)-SciTE,並修改第一行為: sim as vrep,再將下方馬達換成對應名稱

接下來將逞景整體加入腳本

第一個腳本

simRemoteApi.start(19999)

第二個腳本

threadFunction=function()
	-- Put your thread code here (initialization and clean-up code should not be in here)

	
	-- Some EXTERNAL commands (e.g. socket commands provided by Lua libraries)
	-- might appear as blocking to the simulator. In that case, you can define
	-- a non-blocking section as following example shows:
	--
	-- sim.setThreadIsFree(true) -- Start of the non-blocking section
	--
	-- Following 2 lines are meant as an example of EXTERNAL blocking commands:
	-- http = require("socket.http")
	-- print(http.request("http://www.google.com"))
	--
	-- sim.setThreadIsFree(false) -- End of the non-blocking section
	--
	-- While in a non-blocking section, try to avoid calling sim-functions. Also
	-- never forget to close the blocking section, otherwise V-REP will hang.
	-- Make sure you read the information related to the sim.setThreadIsFree
	-- API function in V-REP's documentation.


	-- If you wish to synchronize a threaded loop with each simulation pass,
	-- set the thread switch timing in the initialization phase of this script
	-- to the maximum (200), and manually switch thread here with the
	-- sim.switchThread() command. 
	-- ( sim.switchThread() will suspend this script's execution until next
	-- simulation pass, i.e. until the simulation time has changed )
	--
	-- Following example illustrates this:
	-- 
	-- while true do
	--     local p=sim.getObjectPosition(objHandle,-1)
	--     p[1]=p[1]+0.001
	--     sim.setObjectPosition(objHandle,-1,p)
	--     sim.switchThread()
	-- end
end

-- Put some initialization code here:
sim.setThreadSwitchTiming(2) -- Default timing for automatic thread switching

-- Here we execute the regular thread code:
res,err=xpcall(threadFunction,function(err) return debug.traceback(err) end)
if not res then
	sim.addStatusbarMessage('Lua runtime error: '..err)
end

-- Put some clean-up code here:
simRemoteApi.start(19999)

成功執行畫面

import sim as vrep
import sys
# child threaded script: 
#simExtRemoteApiStart(19999)
 
vrep.simxFinish(-1)
 
clientID = vrep.simxStart('127.0.0.1', 19999, True, True, 5000, 5)
 
if clientID!= -1:
    print("Connected to remote server")
else:
    print('Connection not successful')
    sys.exit('Could not connect')
 
errorCode,left_motor_handle=vrep.simxGetObjectHandle(clientID,'left_m',vrep.simx_opmode_oneshot_wait)
 
errorCode,right_motor_handle=vrep.simxGetObjectHandle(clientID,'right_m',vrep.simx_opmode_oneshot_wait)
 
if errorCode == -1:
    print('Can not find left or right motor')
    sys.exit()
 
errorCode=vrep.simxSetJointTargetVelocity(clientID,left_motor_handle,0, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,right_motor_handle,2, vrep.simx_opmode_oneshot_wait)


W10-task1 << Previous Next >> W12-task3

Copyright © All rights reserved | This template is made with by Colorlib