stage2-ag1

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • Work Distribution
  • Cooperation
  • Weekly progress
    • W5
    • W6
    • W7 Keyboard Control
      • 模擬問題與排解
    • W8 Sensor Control
      • Sensor模擬問題與排解
    • W9
  • Product Install
Weekly progress << Previous Next >> W6

W5

第五週分組專案開始,分組以第一次分組兩兩合併為主。

組別為:stage2-ag1

組員:

       40823108

       40823109

       40823112

       40823145

分組討論完,決定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

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


Weekly progress << Previous Next >> W6

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