From 672884119552eadbf57be8bfc1473fcea88107d3 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Tue, 7 Oct 2025 16:51:15 +0200 Subject: [PATCH] Add AudioTestingController --- controller/audio_testing_controller.lua | 82 +++++++++++++++++++ ...ller.lua => turtle_testing_controller.lua} | 28 +++---- main.lua | 23 ++++-- 3 files changed, 110 insertions(+), 23 deletions(-) create mode 100644 controller/audio_testing_controller.lua rename controller/{testing_controller.lua => turtle_testing_controller.lua} (87%) diff --git a/controller/audio_testing_controller.lua b/controller/audio_testing_controller.lua new file mode 100644 index 0000000..d95efb0 --- /dev/null +++ b/controller/audio_testing_controller.lua @@ -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 diff --git a/controller/testing_controller.lua b/controller/turtle_testing_controller.lua similarity index 87% rename from controller/testing_controller.lua rename to controller/turtle_testing_controller.lua index a5da36b..b5a24bb 100644 --- a/controller/testing_controller.lua +++ b/controller/turtle_testing_controller.lua @@ -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 diff --git a/main.lua b/main.lua index b254898..18a6d24 100644 --- a/main.lua +++ b/main.lua @@ -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 AudioController = require("controller.audio_controller") local controllers = { - TestingController:Create(), + TurtleTestingController:Create(), + AudioTestingController:Create(), ExcavationController:Create(), AudioController:Create(), } print("Multiple controllers are available:") -print("1: Testing Mode") -print("2: Volume Excavation") -print("3: Play Bangarang") +print("1: Turtle Testing Mode") +print("2: Audio Testing Mode") +print("3: Volume Excavation") +print("4: Play Bangarang") local choice = 0 while choice < 1 or choice > #controllers do @@ -21,10 +24,12 @@ end 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: 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 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)