40823224 cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • stage1
    • W1
    • W2
    • W3
    • W4
    • W5
  • stage2
    • W6
    • W7
    • W8
    • W9
  • stage3
    • W10
    • task 演練
      • task1
      • task2
      • task3
    • W14
    • W15
    • W16
      • Onshape零件
      • CoppeliaSim場景
      • suction pad 吸盤
      • 逆向運動學函式
      • remote API
    • W17
  • 筆記
    • leo編輯
    • 使用cms批次檔
    • CoppeliaSim操作筆記
    • Gitlab
    • Fossil
W15 << Previous Next >> Onshape零件

W16

Onshape零件

Onshape圖檔

繪製圖檔過程:


CoppeliaSim場景

W16_exam_雲端硬碟

建立場景過程:


suction pad 吸盤

加入吸盤後,鍵盤控制作動:

參考鍵碼:

keyboard.lua內容:

function sysCall_init()
    joint1=sim.getObjectHandle('joint1')
    joint2=sim.getObjectHandle('joint2')    
    joint3=sim.getObjectHandle('joint3')
    jointz=sim.getObjectHandle('jointZ')
    sim.setJointTargetPosition(joint1,0)
    sim.setJointTargetPosition(joint2,0)
    sim.setJointTargetPosition(joint3,0)
    sim.setJointTargetPosition(jointz,0)
    deg1=0
    deg2=0
    deg3=0
end

function sysCall_actuation()
    message,auxiliaryData=sim.getSimulatorMessage()
    while message~=-1 do
        if (message==sim.message_keypress) then
            if (auxiliaryData[1]==100) then
            deg1=deg1+1
            deg3=deg2-deg1
            sim.setJointTargetPosition(joint1,deg1*math.pi/180)
            end
            if (auxiliaryData[1]==97) then
            deg1=deg1-1
            deg3=deg2-deg1
            sim.setJointTargetPosition(joint1,deg1*math.pi/180)
            end
            if (auxiliaryData[1]==119) then
            deg2=deg2+1
            deg3=deg1-deg2
            sim.setJointTargetPosition(joint2,deg2*math.pi/180)
            end
            if (auxiliaryData[1]==115) then
            deg2=deg2-1
            deg3=deg1-deg2
            sim.setJointTargetPosition(joint2,deg2*math.pi/180)
            end
            if (auxiliaryData[1]==2008) then
                sim.setJointTargetPosition(jointz,-0.018)
                sim.setIntegerSignal("pad_switch",1)
            end
            if(auxiliaryData[1]==2007) then
                sim.setJointTargetPosition(jointz,0)
            end
            if(auxiliaryData[1]==32) then
                sim.setIntegerSignal("pad_switch",0)
            end
            sim.setJointTargetPosition(joint3,deg3*math.pi/180)
        end
    message,auxiliaryData=sim.getSimulatorMessage()
    end
end


逆向運動學函式

Lua作動:

Lua control.lua內容:

function moving(x,y)
    a=0.467
    b=0.401
    c=math.pow(math.pow(x,2)+math.pow(y,2),0.5)
    s=(a+b+c)*0.5
    area=math.pow((s*(s-a)*(s-b)*(s-c)),0.5)
    h=area/(2*c)
    deg1_base=math.atan(x/y)
    if x<0 and y<0 then
        deg1_base=deg1_base+math.pi
    end
    deg1_tri=math.asin(h/a)
    deg1=deg1_base+deg1_tri
    deg2=math.pi-(0.5*math.pi-deg1_tri)-math.acos(h/b)
    deg3=deg2-deg1
    print(deg3)
    sim.setJointTargetPosition(joint1,deg1)
    sim.setJointTargetPosition(joint2,-deg2)
    sim.setJointTargetPosition(joint3,deg3)
    
end

function pick_and_place(x,y)
    sim.setIntegerSignal("pad_switch",0)
    sim.wait(t)
    moving(0,0.868)
    sim.wait(t)
    moving(x,y)
    sim.wait(t)
    sim.setIntegerSignal("pad_switch",1)
    sim.setJointTargetPosition(jointz,-0.018)
    sim.wait(t)
    sim.setJointTargetPosition(jointz,0)
    sim.wait(t)
end

function sysCall_threadmain()
    t=5
    joint1=sim.getObjectHandle('joint1')
    joint2=sim.getObjectHandle('joint2')
    jointz=sim.getObjectHandle('jointZ')
    joint3=sim.getObjectHandle('joint3')
    sim.setJointTargetPosition(joint1,0)
    sim.setJointTargetPosition(joint2,0)
    sim.setJointTargetPosition(joint3,0)
    sim.setIntegerSignal("pad_switch",1)
    sim.setJointTargetPosition(jointz,-0.018)
    sim.wait(t)
    sim.setJointTargetPosition(jointz,0)
    sim.wait(t)
    while sim.getSimulationState()~=sim.simulation_advancing_abouttostopre do
        x=0.2
        y=0.7
        moving(x,y)
        sim.wait(t)
        pick_and_place(x,y)
        x=-0.3
        y=-0.55
        moving(x,y)
        sim.wait(t)
        pick_and_place(x,y)
    end
end


remote API

remote API作動:

Python remote API.py內容:

import sim as vrep
import math
import random
import time
import math

def moving(x,y):
    a=0.467
    b=0.401
    c=math.pow(math.pow(x,2)+math.pow(y,2),0.5)
    s=(a+b+c)*0.5
    area=math.pow((s*(s-a)*(s-b)*(s-c)),0.5)
    h=area/(2*c)
    deg1_base=math.atan(x/y)
    if x<0 and y<0 :
        deg1_base=deg1_base+math.pi
    deg1_tri=math.asin(h/a)
    deg1=deg1_base+deg1_tri
    deg2=math.pi-(0.5*math.pi-deg1_tri)-math.acos(h/b)
    deg3=deg2-deg1
    vrep.simxSetJointTargetPosition(clientID,joint01,deg1,opmode)
    vrep.simxSetJointTargetPosition(clientID,joint02,(-deg2),opmode)
    vrep.simxSetJointTargetPosition(clientID,joint03,deg3,opmode)

def pick_and_place(x,y):
    vrep.simxSetIntegerSignal(clientID,"pad_switch",0,opmode)
    time.sleep(tt)
    moving(0,0.868)
    time.sleep(tt)
    moving(x,y)
    time.sleep(tt)
    vrep.simxSetIntegerSignal(clientID,"pad_switch",1,opmode)
    vrep.simxSetJointTargetPosition(clientID,jointz,-0.018,opmode)
    time.sleep(tt)
    vrep.simxSetJointTargetPosition(clientID,jointz,0,opmode)
    time.sleep(tt)



print ('Start')
 
vrep.simxFinish(-1)
 
clientID = vrep.simxStart('172.20.10.4', 19997, True, True, 5000, 5)
  
if clientID != -1:
    print ('Connected to remote API server')
      
    res = vrep.simxAddStatusbarMessage(
        clientID, "40823224",
        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,joint01=vrep.simxGetObjectHandle(clientID,"joint1",opmode)
    ret,joint02=vrep.simxGetObjectHandle(clientID,"joint2",opmode)
    ret,joint03=vrep.simxGetObjectHandle(clientID,"joint3",opmode)
    ret,jointz=vrep.simxGetObjectHandle(clientID,"jointZ",opmode)
    tt=1.5
 

    while True :
        vrep.simxSetJointTargetPosition(clientID,joint01,0,opmode)
        vrep.simxSetJointTargetPosition(clientID,joint02,0,opmode)
        vrep.simxSetJointTargetPosition(clientID,joint03,0,opmode)
        vrep.simxSetJointTargetPosition(clientID,jointz,-0.018,opmode)
        vrep.simxSetIntegerSignal(clientID,"pad_switch",1,opmode)
        time.sleep(tt)
        vrep.simxSetJointTargetPosition(clientID,jointz,0,opmode)
        time.sleep(tt)
        while True:
            x=0.2
            y=0.7
            moving(x,y)
            time.sleep(tt)
            pick_and_place(x,y)
            x=-0.3
            y=-0.55
            moving(x,y)
            time.sleep(tt)
            pick_and_place(x,y)


W15 << Previous Next >> Onshape零件

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