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
    • 影片字幕整理
自動吹笛子機 << Previous Next >> W13 Pick and Place remoteApi

3D列印機

使用python remoteApi進行遠端控制

控制:

上下左右控制噴頭的上下左右

空白鍵往上

C鍵往下

圖檔

3D print remoteApi program

3D print remoteApi.ttt

程式參考

5/18 程式修改:將顯示的數值由公尺轉成毫米並且去掉多餘的小數點

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('127.0.0.1', 19997, True, True, 5000, 5)
 
if clientID != -1:
    print ('Conipconfigected to remote API server')
    
    res = vrep.simxAddStatusbarMessage(
        clientID, "40823214",
        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,joint1=vrep.simxGetObjectHandle(clientID,"X",opmode)
    ret,joint2=vrep.simxGetObjectHandle(clientID,"Y",opmode)
    ret,joint3=vrep.simxGetObjectHandle(clientID,"Z",opmode)
    dx=0
    dy=0
    dz=0
    dt=0.005
    cont=0
    rangeR=0.013
    max_h=0.35
    vrep.simxSetJointTargetPosition(clientID,joint1,dx,opmode)
    vrep.simxSetJointTargetPosition(clientID,joint2,dx,opmode)
    vrep.simxSetJointTargetPosition(clientID,joint3,dx,opmode)

    while True:
        #Clockwise
        if keyboard.is_pressed("8"):
            dx=dx+dt
            cont=float(math.pow(dx,2)+math.pow(dy,2))
            if cont<rangeR:
                vrep.simxSetJointTargetPosition(clientID,joint1,dx,opmode)
                print(round(dx*1000,1),round(dy*1000,1),round(dz*1000,1))
            else:
                print("Out of range")
                dx=dx-dt
        if keyboard.is_pressed("2"):
            dx=dx-dt
            cont=float(math.pow(dx,2)+math.pow(dy,2))
            if cont<rangeR:
                vrep.simxSetJointTargetPosition(clientID,joint1,dx,opmode)
                print(round(dx*1000,1),round(dy*1000,1),round(dz*1000,1))
            else:
                print("Out of range")
                dx=dx+dt
        if keyboard.is_pressed("4"):
            dy=dy+dt
            cont=float(math.pow(dx,2)+math.pow(dy,2))
            if cont<rangeR:
                vrep.simxSetJointTargetPosition(clientID,joint2,dy,opmode)
                print(round(dx*1000,1),round(dy*1000,1),round(dz*1000,1))
            else:
                print("Out of range")
                dy=dy-dt
        if keyboard.is_pressed("6"):
            dy=dy-dt
            cont=float(math.pow(dx,2)+math.pow(dy,2))
            if cont<rangeR:
                vrep.simxSetJointTargetPosition(clientID,joint2,dy,opmode)
                print(round(dx*1000,1),round(dy*1000,1),round(dz*1000,1))
            else:
                print("Out of range")
                dy=dy+dt
        if keyboard.is_pressed("space"):    
            dz=dz+dt   
            if dz<max_h:       
                vrep.simxSetJointTargetPosition(clientID,joint3,dz,opmode)
                print(round(dx*1000,1),round(dy*1000,1),round(dz*1000,1))
            else:
                print("too high")
                dz=dz-dt 
        if keyboard.is_pressed("c"):
            dz=dz-dt
            if dz<0:
                print("too low")
                dz=0
            else:
                vrep.simxSetJointTargetPosition(clientID,joint3,dz,opmode)
                print(round(dx*1000,1),round(dy*1000,1),round(dz*1000,1))
    else:
        print ('Failed connecting to remote API server')
        print ('End')


自動吹笛子機 << Previous Next >> W13 Pick and Place remoteApi

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