1

Add AudioTestingController

This commit is contained in:
2025-10-07 16:51:15 +02:00
parent a5b159fca4
commit 6728841195
3 changed files with 110 additions and 23 deletions

View File

@ -0,0 +1,82 @@
local TurtleController = require("controller.turtle_controller")
local AudioController = require("controller.audio_controller")
---@class AudioTestingController
---@field controller TurtleController
---@field audio AudioController
local AudioTestingController = {}
AudioTestingController.__index = AudioTestingController
---@return AudioTestingController
function AudioTestingController:Create()
local t = {}
setmetatable(t, AudioTestingController)
-----------------------------------------------------------------------------------------------
-- Fields
-----------------------------------------------------------------------------------------------
t.controller = TurtleController:Create()
t.audio = AudioController:Create()
return t
end
-----------------------------------------------------------------------------------------------
-- Behavior Methods
-----------------------------------------------------------------------------------------------
function AudioTestingController:TestAudioWithoutMovement()
local function dancing()
for _ = 1, 256 do
self.controller:TurnRelative(1)
end
self.audio:StopPlaying()
end
parallel.waitForAll(dancing, self.audio:PlayAudioFactory("bangarang"))
end
function AudioTestingController:TestAudioWithMovement()
local function movement()
for _ = 1, 10 do
self.controller:MoveForward(10)
self.controller:MoveVertical(3)
self.controller:TurnRelative(2)
self.controller:MoveForward(10)
self.controller:MoveVertical(-3)
self.controller:TurnRelative(2)
end
self.audio:StopPlaying()
end
parallel.waitForAll(movement, self.audio:PlayAudioFactory("bangarang"))
end
-----------------------------------------------------------------------------------------------
-- Main Method
-----------------------------------------------------------------------------------------------
function AudioTestingController:Run()
self.controller:Configure()
self.controller:DisableMiningForward()
self.controller:DisableMiningAbove()
self.controller:DisableMiningBelow()
print("There are multiple tests available:")
print("1: Audio without movement")
print("2: Audio with movement")
local choice = 0
while choice < 1 or choice > 2 do
print("Choose a test by entering its number:")
choice = tonumber(io.read()) or 0
end
if choice == 1 then
self:TestAudioWithoutMovement()
elseif choice == 2 then
self:TestAudioWithMovement()
end
end
return AudioTestingController

View File

@ -1,15 +1,15 @@
local Direction = require("lib.direction")
local TurtleController = require("controller.turtle_controller")
---@class TestingController
---@class TurtleTestingController
---@field controller TurtleController
local TestingController = {}
TestingController.__index = TestingController
local TurtleTestingController = {}
TurtleTestingController.__index = TurtleTestingController
---@return TestingController
function TestingController:Create()
---@return TurtleTestingController
function TurtleTestingController:Create()
local t = {}
setmetatable(t, TestingController)
setmetatable(t, TurtleTestingController)
t.controller = TurtleController:Create()
@ -20,7 +20,7 @@ end
-- Behavior Methods
-----------------------------------------------------------------------------------------------
function TestingController:TestRelativeMovementWithRelativeRotation()
function TurtleTestingController:TestRelativeMovementWithRelativeRotation()
print("Testing relative movement with relative rotation...")
-- N: BackCenter (Center)
@ -50,7 +50,7 @@ function TestingController:TestRelativeMovementWithRelativeRotation()
_ = io.read()
end
function TestingController:TestRelativeMovementWithAbsoluteRotation()
function TurtleTestingController:TestRelativeMovementWithAbsoluteRotation()
print("Testing relative movement with absolute rotation...")
-- N: BackCenter (Center)
@ -80,7 +80,7 @@ function TestingController:TestRelativeMovementWithAbsoluteRotation()
_ = io.read()
end
function TestingController:TestAbsoluteMovementWithoutStack()
function TurtleTestingController:TestAbsoluteMovementWithoutStack()
print("Testing absolute movement without stack...")
-- N: BackCenter (Center)
@ -104,7 +104,7 @@ function TestingController:TestAbsoluteMovementWithoutStack()
_ = io.read()
end
function TestingController:TestAbsoluteMovementWithStack()
function TurtleTestingController:TestAbsoluteMovementWithStack()
print("Testing absolute movement with stack...")
-- N: BotCenter (Center)
@ -126,7 +126,7 @@ function TestingController:TestAbsoluteMovementWithStack()
_ = io.read()
end
function TestingController:TestUnstocking()
function TurtleTestingController:TestUnstocking()
print("Testing inventory unloading...")
self.controller:MoveToPosition(3, 0, 3, Direction.WEST)
@ -143,7 +143,7 @@ function TestingController:TestUnstocking()
_ = io.read()
end
function TestingController:TestRefueling()
function TurtleTestingController:TestRefueling()
print("Testing refueling...")
self.controller:MoveToPosition(3, 0, 3, Direction.WEST)
@ -164,7 +164,7 @@ end
-- Main Method
-----------------------------------------------------------------------------------------------
function TestingController:Run()
function TurtleTestingController:Run()
self.controller:Configure()
self.controller:DisableMiningForward()
self.controller:DisableMiningAbove()
@ -217,4 +217,4 @@ function TestingController:Run()
end
end
return TestingController
return TurtleTestingController