40823247

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Stage1
    • W1
    • W2
    • W3
    • W4
    • 自動旋轉烤肉機
  • Stage2
    • W5
    • W6
    • W7
    • W8
    • W9
    • 多功能腳踏車衝擊測試機
  • stage3
    • W10
    • W11
    • W12
    • W13
  • W16
  • Task
    • Mission
    • task1
    • task2
    • task3
    • Robot Pick and Place
  • Others
    • Fix cmsimde
    • Update cmsimde
    • leo
    • github提交沒有顯示頭像
    • 組員合併倉儲產生衝突
    • 轉移Github倉儲資料至GOGS
  • Videos
W11 << Previous Next >> W13

W12

5/17組員完成了程式模擬

此為檔案載點:

https://drive.google.com/file/d/1FErGMzyfP5MTvf8cLc1Ox2xHJhuDN1XH/view?usp=sharing

-5/18開始測試程式,可以順利執行-

解壓縮檔案後,將此api.py丟到白窗測試程式

若要操控自己電腦的coppeliasim裡的機構,將ip位址改為127.0.0.1,點選go即可執行。

------------(我是分隔線)--------------

按鍵A為主軸順時針旋轉

按鍵B為主軸逆時針旋轉

按鍵W為大臂向上

按鍵S為大臂向下

按鍵E為小臂向上

按鍵D為小臂向下

按鍵R為小臂旋轉

按鍵J為手肘向上

按鍵K為手肘向下

------------(我是分隔線)---------------

此為程式碼:

# File created by Thibaut Royer, Epitech school
# thibaut1.royer@epitech.eu
# It intends to be an example program for the "Two wheels, one arm" educative project.
  
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.0.4', 19997, True, True, 5000, 5)
  
if clientID != -1:
    print ('Connected to remote API server')
      
    res = vrep.simxAddStatusbarMessage(
        clientID, "40823218",
        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
    STREAMING = vrep.simx_opmode_streaming
  
    # Try to retrieve motors and robot handlers
    # http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctionsPython.htm#simxGetObjectHandle
    vrep.simxStartSimulation(clientID, opmode)
    ret,base_handle=vrep.simxGetObjectHandle(clientID,"joint1",opmode)
    ret,bottom_handle=vrep.simxGetObjectHandle(clientID,"joint2",opmode)
    ret,top_handle=vrep.simxGetObjectHandle(clientID,"joint3",opmode)
    ret,rotate_handle=vrep.simxGetObjectHandle(clientID,"joint4",opmode)
    ret,wrist_handle=vrep.simxGetObjectHandle(clientID,"joint5",opmode)
    while True:
        #Clockwise
        if keyboard.is_pressed("a"):
         vrep.simxSetJointTargetVelocity(clientID,base_handle,0.2,opmode)
        #anti-Clockwise
        if keyboard.is_pressed("f"):
         vrep.simxSetJointTargetVelocity(clientID,base_handle,-0.2,opmode)
        #bottom_handle up
        if keyboard.is_pressed ("w"):
         vrep.simxSetJointTargetVelocity(clientID,bottom_handle,0.2,opmode)
        #bottom_handle down
        if keyboard.is_pressed ("s"):
         vrep.simxSetJointTargetVelocity(clientID,bottom_handle,-0.2,opmode)
         #top_handle up
        if keyboard.is_pressed ("e"):
         vrep.simxSetJointTargetVelocity(clientID,top_handle,0.2,opmode)
         #top_handle down
        if keyboard.is_pressed ("d"):
         vrep.simxSetJointTargetVelocity(clientID,top_handle,-0.2,opmode)
         #rotate
        if keyboard.is_pressed ("r"):
         vrep.simxSetJointTargetVelocity(clientID,rotate_handle,0.2,opmode)
         #wrist_handle left
        if keyboard.is_pressed ("j"):
         vrep.simxSetJointTargetVelocity(clientID,wrist_handle,0.2,opmode)
         #wrist_handle right
        if keyboard.is_pressed ("k"):
         vrep.simxSetJointTargetVelocity(clientID,wrist_handle,-0.2,opmode)
         #stop
        if keyboard.is_pressed ("space"):
         vrep.simxSetJointTargetVelocity(clientID,base_handle,0,opmode)
         vrep.simxSetJointTargetVelocity(clientID,bottom_handle,0,opmode)
         vrep.simxSetJointTargetVelocity(clientID,top_handle,0,opmode)
         vrep.simxSetJointTargetVelocity(clientID,rotate_handle,0,opmode)
         vrep.simxSetJointTargetVelocity(clientID,wrist_handle,0,opmode)
  
  
else:
    print ('Failed connecting to remote API server')
    print ('End')

此處的意思為呼叫這些程式,因為要執行接下來的程式碼時會用到

修改此處的id位址會影響你要操控的電腦位址

此處為定義程式指令和零件的關係和模式,後方的joint就是指coppeliasim的零件

這串的意思是,當你按下鍵盤的按鍵,對應的已被你定義關係的零件就會根據你下的指令作動

下載老師提供的壓縮檔:http://mde.tw/cd2021/content/task2.html


W11 << Previous Next >> W13

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