40823145-cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Copperation
  • Midterm
    • Week 1
      • Create New repository and Wecsite
    • Week 2
    • Week 3
      • upgrade cmsimde
  • Stage1-ag1
  • stage2-ag1
  • stage3-ag1
    • Task1
    • Task2
    • W13
    • W14
      • MTB_Robot
      • gitlab
    • W15
    • W16
  • Final
  • Note
    • Upgrade pip
    • ssh
    • Leo Editor
      • Blog
      • Reveal
    • Code
  • FreeCAD protable
Stage1-ag1 << Previous Next >> stage3-ag1

stage2-ag1

分組專題成員:

第一位成員:408231112 (組長)

Website: 40823112 Stage2-ag1 Website

Reveal: 40823112 Stage2-ag1 Reveal

第二位成員:40823108 (組員)

Website: 40823108 Stage2-ag1 Website

Reveal: 40823108 Stage2-ag1 Reveal

第三位成員:40823109 (組員)

Website: 40823109 Stage2-ag1 Website

第四位成員:408231045 (組員)

Website: 40823145 Stage2-ag1 Website

Reveal: 40823145 Stage2-ag1 Reveal

專題項目:經討論決定Stage2的項目,為Stage1-ag1的改良,並增加其它功能:

1.利用鍵盤方向鍵操控

2.增加接近傳感器使產品自動行走時,不會撞到障礙物

本次圖檔沿用Stage1,改使用Coppeliasim,透過lua程式編寫

W5

本次專案沿用stage1-ag1之專案,為了讓模型能夠按照我們的意思做動,我們嘗試編寫Lua程式並以方向鍵進行控制。

下方為第一次測試程式與模擬圖

Lua程式:

threadFunction=function()
    -- put your actuation code here
 while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
    -- Read the keyboard messages (make sure the focus is on the main window, scene view):
        message,auxiliaryData=sim.getSimulatorMessage()
        while message~=-1 do
            if (message==sim.message_keypress) then
if (auxiliaryData[1]==2007) then
                -- up key
                velocity=1000
                torque=10000
                Shape4 = 1000
                Shape7 = 1000
            end
            if (auxiliaryData[1]==2008) then
                -- down key
                velocity=1000
                torque=10000
                Shape4 = 1000
                Shape7 = 1000
            end
            if (auxiliaryData[1]==2009) then
                -- left key
                velocity=1000
                torque=10000
                Shape4 = 1000
                Shape7 = 1000
            end
            if (auxiliaryData[1]==2010) then
                -- right key
                velocity=1000
                torque=10000
                Shape4 = 1000
                Shape7 = 1000
            end
        end
        message,auxiliaryData=sim.getSimulatorMessage()
    end
    if Shape4 == 1
        then sim.setJointPosition(joint_1, 1000, orientation)
    if Shape7 == 1
        then sim.setJointPosition(joint_2, 1000, orientation)
    end
        sim.setJointTargetVelocity(joint,velocity)
    end
        joint_1=sim.getObjectHandle('joint_1')
        joint_2=sim.getObjectHandle('joint_2')
        Shape4=sim.getObjectHandle('Shape4')
        Shape7=sim.getObjectHandle('Shape7')
        velocity=0
        torque=0
        Shape4 = 0
        Shape7 = 0
end

因部分語法有誤,日後待除錯。

W6

經過一週的時間,我們將程式進行了修改,但還是有錯誤,無法讓機構以上下左右鍵的方式進行控制。

下方為模擬圖:

第二次Lua程式測試:

function sysCall_init()
    -- do some initialization here
    left_front_handle= sim.getObjectHandle('left_front')
    left_back_handle= sim.getObjectHandle('left_back')
    right_back_handle= sim.getObjectHandle('right_back')
    right_front_handle= sim.getObjectHandle('right_front')
     
    joint_1_handle= sim.getObjectHandle('joint_1')
     
    joint_2_handle= sim.getObjectHandle('joint_2')
    MaxVel=10
    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()
    -- put your actuation code here
    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)
                 
                 
                sim.setJointForce(joint_1_handle, 1000)
                 
                sim.setJointForce(joint_2_handle, 1000)
                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)
             
            sim.setJointForce(joint_1_handle, 0)
             
            sim.setJointForce(joint_2_handle, 0)
            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
 
function sysCall_sensing()
    -- put your sensing code here
end
 
function sysCall_cleanup()
    -- do some clean-up here
end
 
-- See the user manual or the available code snippets for additional callback functions and details

第二次程式失敗,日後將持續進除錯。

W7

利用鍵盤操控物體行走

(🔽程式碼)

function sysCall_init() 
    left_handle= sim.getObjectHandle('left_m')
    right_handle= sim.getObjectHandle('right_m')
    MaxVel=2
    leftvelocity=0
    rightvelocity=0
    dVel=0.5;
    sim.setJointTargetVelocity(left_handle,leftvelocity)
    sim.setJointTargetVelocity(right_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(right_front_handle, 0)
                break
            else
                sim.setJointForce(left_handle, 10000)
                sim.setJointForce(right_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_handle,leftvelocity)
    sim.setJointTargetVelocity(right_handle,rightvelocity)
    
end 

模擬問題與排解

問題: 當本體開啟運動模擬時會產生錯誤,導致產品解體

問題原因: 討論後發現,產品的模擬干涉太多使其無法正常運作,原因是產品的輪子跟球體上並不是完整的圓,而是由許多正方形的小格子所構成,所以在模擬時產生過多的干涉影響電腦正常模擬,因而模擬錯誤。

問題排解: 在coppeliasim內 add->primitive shape->Cylinder 增添簡化圖形來代替原本的車輪,而原本的輪子就做為Disc的造型。

W8 Sensor Control

增加接近傳感器使產品自動行走時,不會撞到障礙物

(🔽程式碼)

function sysCall_init()
    
    
end

function sysCall_actuation()
    
end

function sysCall_sensing()
    
end

function sysCall_cleanup()
    
end



function sysCall_afterDelete(inData)
    for key,value in pairs(inData.objectHandles) do
        print("Object with handle "..key.." was deleted")
    end
    
end

function sysCall_afterCreate(inData)
    for key,value in pairs(inData.objectHandles) do
        print("Object with handle "..value.." was created")
    end
end
--]]
function speedChange_callback(ui,id,newVal)
    speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*newVal/100
end

function sysCall_init()
    
    bubbleRobBase=sim.getObjectAssociatedWithScript(sim.handle_self) 
    leftMotor=sim.getObjectHandle("bubbleRob_leftMotor") 
    rightMotor=sim.getObjectHandle("bubbleRob_rightMotor") 
    noseSensor=sim.getObjectHandle("bubbleRob_sensingNose") 
    minMaxSpeed={120*math.pi/180,300*math.pi/180} 
    backUntilTime=-1 
   
        xml = ''..[[
        
        
        
        ]]
    ui=simUI.create(xml)
    speed=(minMaxSpeed[1]+minMaxSpeed[2])*1
    simUI.setSliderValue(ui,1,100*(speed-minMaxSpeed[1])/(minMaxSpeed[2]-minMaxSpeed[1]))
end

function sysCall_actuation()
    result=sim.readProximitySensor(noseSensor) 
    
    if (result>0) then backUntilTime=sim.getSimulationTime()+4 end 

    if (backUntilTime<sim.getSimulationTime()) then
        
        sim.setJointTargetVelocity(leftMotor,speed)
        sim.setJointTargetVelocity(rightMotor,speed)
    else
        
        sim.setJointTargetVelocity(leftMotor,-speed/5)
        sim.setJointTargetVelocity(rightMotor,-speed/200)
    end
end

function sysCall_cleanup()
	simUI.destroy(ui)
end

Sensor模擬問題與排解

問題:程式與感測器都確認無誤後,卻還是無法做動。

問題原因:與組員討論後發現,感測器都沒有發生問題,不會做動的原因是程式打錯才無法驅動馬達。

問題排解:更改產品物件的程式碼即可。

W9

程式模擬影片與PDF報告

方向鍵控制模擬

感測器模擬

PDF報告


Stage1-ag1 << Previous Next >> stage3-ag1

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