2021-協同產品設計實習-stage3-bg6

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • 機械手臂
    • 繪圖成果
    • 計算角度
  • 程式模擬
    • W10
    • W11
  • CoppliaSim程式模擬
    • CoppeliaSim 教學
      • 軸的旋轉教學
      • 直線運動教學
      • 1-單軸直線運動
      • 2-可變速之旋轉運動
      • 3-遙控攝影小汽車
      • CODE 指令解說
      • remoteApi python 指令對照
      • 機械手臂設定範例
      • 按鍵控制代碼
    • 架設場景
      • 對軸進行旋轉控制
      • 對方快進行XYZ軸控制
      • 物件螺旋運動
      • 3D列印機_控制噴嘴
      • 3D列印機_自動繪製
      • 3D列印機_控制高度
      • 衝擊試驗機
      • 架設機械手臂場景
      • 機械手臂場景微調
      • 機械手臂場景路徑控制
    • W13 Pick and Place
      • remoteApi
      • 0526更新
      • 舊版本
    • 尋找控制代碼
    • 控制解說
    • 0513 機械手臂新增夾爪控制
    • 0511 Programming in C++
    • 參考資料
    • 舊資料
      • 0511 Programming in Lua on multiple program
      • 0511 Programming in Lua in One program
  • task2-remoteAPI
    • 機械手臂多人對戰
    • 自動吹笛子機
    • 3D列印機
    • W13 Pick and Place remoteApi
      • 0601
      • 0524
    • remoteAPI in C++
      • 0511
      • 0512
      • 0512-2
    • remoteAPI in python
      • 0513-1
      • 0517
    • remoteApi in Lua
      • 0513-2
  • stage3
    • task
      • task1
    • 每週進度影片
      • 第九週
      • 第十週
      • 第十一週
      • 第十二週
      • 第十三週
    • 討論
      • discord
      • 第一次討論
      • 第二次討論
      • 第三次討論
      • 第四次討論
      • 第五次討論
    • 遇到的問題
      • 更新出錯
      • 倉儲帳號被鎖
    • 小組直播影片
      • 第11週
      • 第12週
      • 第13週
  • W15
    • 影片字幕整理
0511 Programming in Lua in One program << Previous Next >> 機械手臂多人對戰

task2-remoteAPI

請各組員分別將個人在 stage1 與 stage2 所完成的 coppeliasim 場景, 採 Python remote API 進行操控, 並將過程拍成影片後, 放在個人與分組網站上.

stage3 專案中的 CoppeliaSim 請一律使用 4.2.0 版.

範例: http://mde.tw/cad2020/content/CoppeliaSim.html

W10 範例:

各班上課時所分配到的內部 IP, 192.168.192.1+組別+排序別

意即, 第五組排序別第一即為該組組長, 其 IP 為 192.168.192.151

以 http://mde.tw/cad2020/downloads/coppeliasim/vrep_remoteapi_ex.7z 為例, 每一個 Python3 remote api 程式執行需要 sim.py, simConst.py 與 remoteApi.dll 等三個檔案, 若針對 2w1a.ttt 場景, 以下列 Python 程式對位於 192.168.192.1 伺服器上的 CoppeliaSim 場景進行操控:

import sim as vrep
import math
import random
import time

print ('Start')

# Close eventual old connections
vrep.simxFinish(-1)
# Connect to V-REP remote server
clientID = vrep.simxStart('192.168.192.1', 19997, True, True, 5000, 5)

if clientID != -1:
    print ('Connected to remote API server')

    res = vrep.simxAddStatusbarMessage(
        clientID, "teacher",
        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.")
    # Communication operating mode with the remote API : wait for its answer before continuing (blocking mode)
    # http://www.coppeliarobotics.com/helpFiles/en/remoteApiConstants.htm
    opmode = vrep.simx_opmode_oneshot_wait

    # Try to retrieve motors and robot handlers
    # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxGetObjectHandle
    ret1, wristHandle = vrep.simxGetObjectHandle(clientID, "WristMotor", opmode)
    ret2, elbowHandle = vrep.simxGetObjectHandle(clientID, "ElbowMotor", opmode)
    ret3, shoulderHandle = vrep.simxGetObjectHandle(clientID, "ShoulderMotor", opmode)
    ret4, robotHandle = vrep.simxGetObjectHandle(clientID, "2W1A", opmode)

    # If handlers are OK, execute three random simulations
    if ret1 == 0 and ret2 == 0 and ret3 == 0:
        random.seed()
        for i in range(0, 3):
            # Start the simulation
            # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxStartSimulation
            vrep.simxStartSimulation(clientID, opmode)
            print("----- Simulation started -----")

            # Start getting the robot position
            # Unlike other commands, we will use a streaming operating mode
            # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxGetObjectPosition
            pret, robotPos = vrep.simxGetObjectPosition(clientID, robotHandle, -1, vrep.simx_opmode_streaming)
            print("2w1a position: (x = " + str(robotPos[0]) +\
                  ", y = " + str(robotPos[1]) + ")")

            # Start getting the robot orientation
            # Unlike other commands, we will use a streaming operating mode
            # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxGetObjectOrientation
            oret, robotOrient = vrep.simxGetObjectOrientation(clientID, robotHandle, -1, vrep.simx_opmode_streaming)
            print("2w1a orientation: (x = " + str(robotOrient[0]) + \
                  ", y = " + str(robotOrient[1]) +\
                  ", z = " + str(robotOrient[2]) + ")")

            # Make the robot move randomly five times
            for j in range(0, 5):
                # Generating random positions for the motors
                awrist = random.randint(0, 300)
                aelbow = random.randint(0, 300)
                ashoulder = random.randint(0, 300)

                # The control functions use Radians to determine the target position.
                # Here, we use maths.radians to convert degrees into radians.
                # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxSetJointTargetPosition
                print("Motors target positions: " + str(ashoulder) + " " + str(aelbow) + " " + str(awrist))
                vrep.simxSetJointTargetPosition(clientID, wristHandle, math.radians(awrist), opmode)
                vrep.simxSetJointTargetPosition(clientID, elbowHandle, math.radians(aelbow), opmode)
                vrep.simxSetJointTargetPosition(clientID, shoulderHandle, math.radians(ashoulder), opmode)

                # Wait in order to let the motors finish their movements
                # Tip: there must be a more efficient way to do it...
                time.sleep(5)

                # Get the motors effective positions after the movement sequence
                # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxGetJointPosition
                pwrist = vrep.simxGetJointPosition(clientID, wristHandle, opmode)
                pelbow = vrep.simxGetJointPosition(clientID, elbowHandle, opmode)
                pshoulder = vrep.simxGetJointPosition(clientID, shoulderHandle, opmode)
                print("Motors reached positions: " + str(ashoulder) + " " + str(aelbow) + " " + str(awrist))

                # Get the robot position after the movement sequence
                pret, robotPos = vrep.simxGetObjectPosition(clientID, robotHandle, -1, vrep.simx_opmode_buffer)
                print("2w1a position: (x = " + str(robotPos[0]) +\
                      ", y = " + str(robotPos[1]) + ")")

                # Get the robot orientation after the movement sequence
                oret, robotOrient = vrep.simxGetObjectOrientation(clientID, robotHandle, -1, vrep.simx_opmode_buffer)
                print("2w1a orientation: (x = " + str(robotOrient[0]) +\
                      ", y = " + str(robotOrient[1]) +\
                      ", z = " + str(robotOrient[2]) + ")")

            # End the simulation, wait to be sure V-REP had the time to stop it entirely
            # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxStopSimulation
            vrep.simxStopSimulation(clientID, opmode)
            time.sleep(1)
            print("----- Simulation ended -----")

    # Close the connection to V-REP remote server
    # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxFinish
    vrep.simxFinish(clientID)
else:
    print ('Failed connecting to remote API server')
print ('End')

CoppeliaSim 場景 remote API 協同監控流程:

  1. 各組員下載 https://portableapps.com/apps/music_video/obs-studio-portable
  2. 擔任 CoppliaSim 場景直播者時, 必須以 @gm 帳號登入 Youtube 後, 啟動 Live stream 取得直播串流金鑰, 將金鑰輸入 OBS 後, 擷取電腦顯示器啟動串流, 然後利用 copy video url 取得直播網址.
  3. 將直播網誌公布在 https://gitter.im/mdecourse/cd2021, 並附上伺服器 IPv4 內部網路 IP 位址與場景開放埠號.
  4. 直播者同時必須在個人網站上公布 Python remote API 操控直播場景相關參變數以及監控條件.
  5. 待遠端各協同操控學員準備就緒後, 完成操控流程後將所錄製的影片嵌入個人與分組網站中.

直播範例錄影:

參考資料:

RoboComp is a cutting-edge open-source robotics framework providing tools to easily create, modify and manage robot software components.

https://github.com/mdecourse/robocomp

Code to connect RocoComp to V-REP

https://github.com/mdecourse/V-REP-component


0511 Programming in Lua in One program << Previous Next >> 機械手臂多人對戰

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