2021-協同產品設計實習-stage1-ag2

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • Assemble
  • CoppeliaSim
  • Experience
    • Week2
    • Week3
  • Final Report
    • Youtube
    • PDF
Assemble << Previous Next >> Experience

CoppeliaSim

預計要讓繪製的飛機做一個起降的動作。

設計過程

1.將組合好的組合圖匯入。

2.拆解組合起來的飛機。

3.加入4根joint,將長度設為0.09m,直徑為0.02m。

4.把旋轉軸與四個輪子結合,並把輪子重新命名為left_motor,right_motor,back_left,back_right。

5.將機體本身跟輪子設為動態物件並實體化。

6.把馬達轉速設為100deg/s。

7.代入程式碼

function sysCall_init() 
    left_front_handle= sim.getObjectHandle('left_motor')
    left_back_handle= sim.getObjectHandle('left_motor')
    right_back_handle= sim.getObjectHandle('right_motor')
    right_front_handle= sim.getObjectHandle('right_motor')
    MaxVel=2
    leftvelocity=0
    rightvelocity=0
    dVel=0.5;
    --sim.setJointTargetVelocity(left_front_handle,leftvelocity)
    sim.setJointTargetVelocity(left_back_handle,leftvelocity)
    sim.setJointTargetVelocity(right_back_handle,rightvelocity)
    --sim.setJointTargetVelocity(right_front_handle,rightvelocity)
end

function sysCall_actuation() 
    message,auxiliaryData=sim.getSimulatorMessage()
    while message~=-1 do
        if (message==sim.message_keypress) then
            if (auxiliaryData[1]==32) then
                -- right key
                leftvelocity=0
                rightvelocity=0
                sim.setJointForce(left_front_handle, 0)
                sim.setJointForce(left_back_handle, 0)
                sim.setJointForce(right_back_handle, 0)
                sim.setJointForce(right_front_handle, 0)
                break
            else
                --sim.setJointForce(left_front_handle, 10000)
                sim.setJointForce(left_back_handle, 10000)
                sim.setJointForce(right_back_handle, 10000)
                --sim.setJointForce(right_front_handle, 10000)
            end
            if (auxiliaryData[1]==2007) then
                -- up key
                leftvelocity=(leftvelocity+rightvelocity)/2
                rightvelocity=leftvelocity
                leftvelocity=leftvelocity+dVel
                rightvelocity=rightvelocity+dVel
            end
            if (auxiliaryData[1]==2008) then
                -- down key
                leftvelocity=(leftvelocity+rightvelocity)/2
                rightvelocity=leftvelocity
                leftvelocity=leftvelocity-dVel
                rightvelocity=rightvelocity-dVel
            end
            if (auxiliaryData[1]==2009) then
                -- left key
                leftvelocity=leftvelocity-dVel
                rightvelocity=rightvelocity+dVel
            end
            if (auxiliaryData[1]==2010) then
                -- right key
                leftvelocity=leftvelocity+dVel
                rightvelocity=rightvelocity-dVel
            end
        end
        message,auxiliaryData=sim.getSimulatorMessage()
    end
    
    if leftvelocity>MaxVel then
        leftvelocity=MaxVel
    end
    if leftvelocity<-MaxVel then
        leftvelocity=-MaxVel
    end
    
    if rightvelocity>MaxVel then
                rightvelocity=MaxVel
    end
    if rightvelocity<-MaxVel then
                rightvelocity=-MaxVel
    end
    
    --sim.setJointTargetVelocity(left_front_handle,leftvelocity)
    sim.setJointTargetVelocity(left_back_handle,leftvelocity)
    sim.setJointTargetVelocity(right_back_handle,rightvelocity)
    --sim.setJointTargetVelocity(right_front_handle,rightvelocity)
    
end 

作動結果


Assemble << Previous Next >> Experience

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