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
    • 影片字幕整理
remoteAPI in python << Previous Next >> 0517

0513-1

嘗試用remoteAPI鍵盤控制機械手臂,不過手臂上段模擬時出現甩動問題,因此只展示下半部分。

程式碼

# 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.1,opmode)
        #anti-Clockwise 
        if keyboard.is_pressed("f"):
         vrep.simxSetJointTargetVelocity(clientID,base_handle,-0.1,opmode)
        #bottom_handle up
        if keyboard.is_pressed ("w"):
         vrep.simxSetJointTargetVelocity(clientID,bottom_handle,0.1,opmode)
        #bottom_handle down
        if keyboard.is_pressed ("s"):
         vrep.simxSetJointTargetVelocity(clientID,bottom_handle,-0.1,opmode)
         #top_handle up
        if keyboard.is_pressed ("e"):
         vrep.simxSetJointTargetVelocity(clientID,top_handle,0.1,opmode)
         #top_handle down
        if keyboard.is_pressed ("d"):
         vrep.simxSetJointTargetVelocity(clientID,top_handle,-0.1,opmode)
         #rotate
        if keyboard.is_pressed ("r"):
         vrep.simxSetJointTargetVelocity(clientID,rotate_handle,0.1,opmode)
         #wrist_handle left
        if keyboard.is_pressed ("j"):
         vrep.simxSetJointTargetVelocity(clientID,wrist_handle,0.1,opmode)
         #wrist_handle right
        if keyboard.is_pressed ("k"):
         vrep.simxSetJointTargetVelocity(clientID,wrist_handle,-0.1,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')


remoteAPI in python << Previous Next >> 0517

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