Stage1-ag1 <<
Previous Next >> Stage3-ag1
Stage2-ag1
分組專題成員:
第一位成員:a408231112 (組長)
第二位成員:40823108 (組員)
第三位成員:40823109 (組員)
第四位成員:408231045 (組員)
Website: a40823112 Stage2-ag1 Website
Website: 40823108 Stage2-ag1 Website
Website: 40823109 Stage2-ag1 Website
Website: 40823145 Stage2-ag1 Website
Reveal: a40823112 Stage2-ag1 Reveal
Reveal: 40823108 Stage2-ag1 Reveal
Reveal: 40823145 Stage2-ag1 Reveal
分組為期5週,W5~W9以下呈現內容為最後一週之成果:
第五週分組專案開始,分組以第一次分組兩兩合併為主。
組別為:stage2-ag1
本專案使用Autodesk Inventor 2021 Professional,ipt、iam檔案需使用同版本才有辦法開啟
檔案下載:
零件檔:
Lego EV3 model files
場景檔:
.ttt files
W5
分組討論完,決定Stage2的產品設計內容,為Stage1-ag1的產品進行改良,並新增其它功能:
1.利用鍵盤方向鍵操控
2.增加接近傳感器使產品自動行走時,不會撞到障礙物

本次專案沿用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
W8
增加接近傳感器使產品自動行走時,不會撞到障礙物

(🔽程式碼)
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 activate="false" closeable="false" resizeable="false" title="'..sim.getObjectName(bubbleRobBase)..' speed">'..[[
<hslider id="1" maximum="100" minimum="0" onchange="speedChange_callback"></hslider>
<label style="* {margin-left: 300px;" text=""></label>
</ui>
]]
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
W9
程式模擬影片與PDF報告
方向鍵控制模擬
Stage1-ag1 <<
Previous Next >> Stage3-ag1