cd2021 40823218

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • W1
  • W2
  • 修改圖檔
    • W3繪製零件圖
    • 0312修改圖檔
    • 0313修改圖檔
  • 模擬
    • stage1-bg5-1
    • stage2-bg7-1
      • 0412模擬(無球)
      • 0413模擬(有球)
      • 0415模擬
      • 0416模擬
      • 0422模擬
    • stage3-bg6
      • 0513
      • 0517
  • 報告
    • stage1-bg5-2
    • stage2-bg7-2
  • W5
  • W7
    • stage2發球機構圖
    • CoppeliaSim模擬
  • task
    • task1
    • task2
  • W15
    • 影片字幕整理
  • W16
stage3-bg6 << Previous Next >> 0517

0513

嘗試用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')

stage3-bg6 << Previous Next >> 0517

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