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

View File

@ -1,17 +1,20 @@
local TestingController = require("controller.testing_controller") local TurtleTestingController = require("controller.turtle_testing_controller")
local AudioTestingController = require("controller.audio_testing_controller")
local ExcavationController = require("controller.excavation_controller") local ExcavationController = require("controller.excavation_controller")
local AudioController = require("controller.audio_controller") local AudioController = require("controller.audio_controller")
local controllers = { local controllers = {
TestingController:Create(), TurtleTestingController:Create(),
AudioTestingController:Create(),
ExcavationController:Create(), ExcavationController:Create(),
AudioController:Create(), AudioController:Create(),
} }
print("Multiple controllers are available:") print("Multiple controllers are available:")
print("1: Testing Mode") print("1: Turtle Testing Mode")
print("2: Volume Excavation") print("2: Audio Testing Mode")
print("3: Play Bangarang") print("3: Volume Excavation")
print("4: Play Bangarang")
local choice = 0 local choice = 0
while choice < 1 or choice > #controllers do while choice < 1 or choice > #controllers do
@ -21,10 +24,12 @@ end
controllers[choice]:Run() controllers[choice]:Run()
-- TODO: StackOverflow once the inventory is full, unstocking doesn't work...
-- Is the InventoryFull check wrong?
-- TODO: Test if there's a chest when dropping/sucking/mining (don't mine chests!) -- TODO: Test if there's a chest when dropping/sucking/mining (don't mine chests!)
-- TODO: Add controller to build rooms with walls of a specified material -- TODO: Add controller to build rooms with walls of a specified material
-- TODO: Support specifying the mining height
-- TODO: Add configurable trash_list with items that won't be picked up -- TODO: Add configurable trash_list with items that won't be picked up
-- TODO: Add a speaker to the turtle (listen to music while mining) -- TODO: When refueling but chest is missing, wait there until the user puts a chest with fuel
-- TODO: Add emergency return routine if can't move (e.g. try to move in different directions first)
-- TODO: Add shortcuts for the volume excavation:
-- - Tunnel forward 3x2 or 3x3 with specified length
-- - Excavate downwards (quarry) in a square, specify side length
-- TODO: Add a stair building mode (specify side length, min 2x2)