From 173b1d4c48d757f10a145adc5a0b1b7351e2e3a3 Mon Sep 17 00:00:00 2001 From: templeofshadow Date: Thu, 25 Jun 2026 04:06:21 -0500 Subject: [PATCH] following commit --- README.md | 38 +++++++++ config.lua | 3 - config.txt | 14 ++++ docs.md | 15 ---- main.lua | 105 +++++++++++++++---------- thrusters.lua => thrusters.txt.example | 0 6 files changed, 117 insertions(+), 58 deletions(-) create mode 100644 README.md delete mode 100644 config.lua create mode 100644 config.txt rename thrusters.lua => thrusters.txt.example (100%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c12711 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# CC:Tweaked, Create: Aeronautics & Create: Avionics | Multi-Thruster Attitude Control Script + +This script is mainly designed for large-scale vessels that need attitude stabilisation and (OPTIONAL) automatic control. + +You will need: + +- As many thrusters as needed to have sufficient thrust for your environment + - Support for: + - Create: Aeronautics + - Gyroscopic Propeller Bearing + - Propeller Bearing + - All single-block Propellers + - Create Propulsion: Simulated + - Fuel, Chemical, and Ion Thrusters + - Vector & Liquid Vector Thrusters (the script will not take advantage of the thrust vectoring, so it is not reccommended to use them) +- One (1) Altitude Sensor +- One (1) Navigation Table +- One (1) Gimbal Sensor +- Three (3) Velocity Sensors (Each facing a different cardinal direction) +- One (1) Advanced Computer +- At least two (2) Advanced Monitor arrays, one at least 2x2 and one at least 1x3 + - Note: the 2x2 is for autopilot controls and the 1x3 is for flight readouts + - It is reccommended for the 2x2 to be a convienient place, while the 1x3 should be within your field of view when taking manual control +- Three (3) analog levers (reccomended: Throttle Levers) + - Note that these levers will be for forward, reverse, and downards thrust respectively +- Three (3) Redstone Relays, place these where they will be powered by your analog levers +- As many wired modems and cable you need to connect all peripherals + - This includes all explicitly named peripherals, all thrusters/propellers, and for each propeller, every speed-changer block that controls the speed for the propeller's network + +When building your vessel, while connecting each thruster to the network, make sure to note down the thruster's peripheral name when you activate the modem, along with what cardinal directions it will affect when powered (fore, aft, port, starboard, up, and down). + +When you are finished, create a lua file at `/caero-attitude-control/config/thrusters.txt` according to the thrusters.txt.example file. Also, if you have any perisistent config changes, please set them in the `/caero-attitude-control/config/config.txt` file. Make sure this file exists and contains the thruster.txt file path. + +You can change the path of the thruster file (and config file by changing the main lua file) if you need to. + +Make sure you trust the code in config.txt and thruster.txt. It will run arbitrarily within the main lua file. + +Once you are done, simply run the program and follow the directions that show up on the monitor. diff --git a/config.lua b/config.lua deleted file mode 100644 index ab8eb77..0000000 --- a/config.lua +++ /dev/null @@ -1,3 +0,0 @@ -return { - thrusterConfigPath = "/config/thrusters.lua" -} \ No newline at end of file diff --git a/config.txt b/config.txt new file mode 100644 index 0000000..30a1a31 --- /dev/null +++ b/config.txt @@ -0,0 +1,14 @@ +return { + ConfigPath = "/caero-attitude-control/config/config.txt", + thrusterConfigPath = "/caero-attitude-control/config/thrusters.txt", + Monitors = { + InstrumentPanelMonitor = nil, + AutopilotControlMonitor = nil + }, + Autopilot = { + AutopilotEngaged = false, + AutoForeAft = false, + AutopilotDesiredSpeed = nil, + AutopilotDesiredHeading = nil + } +} \ No newline at end of file diff --git a/docs.md b/docs.md index 75f3482..39d20da 100644 --- a/docs.md +++ b/docs.md @@ -1,20 +1,5 @@ # Implementation Docs -## Redstone Mode - -Total redstone inputs: 22 -8x tilt signals -6x accelerometer signals -4x direction signals -1x altitude signal -1x downwards thrust signal -1x fore thrust signal -1x aft thrust signal - -Total required redstone outputs: at least 8 -4x for four large thrusters -8x for at least eight small attitude thrusters (4x lateral, 4x pitch/roll) - ## Required functionality - Achieve target angles for tilt values (target is 0) diff --git a/main.lua b/main.lua index f8b0aaf..5b57601 100644 --- a/main.lua +++ b/main.lua @@ -33,14 +33,37 @@ Thrusters = { } } -- Table of thruster tables -ConfigPath = "/config/config.lua" +ThrusterTypes = { + "thruster", + "solid_fuel_thruster", + "ion_thruster", + "vector_thruster", + "liquid_vector_thruster" +} + +PropellerTypes = { + "gyroscopic_propeller_bearing", + "propeller", + "propeller_bearing" +} + +TransmissionTypes = { + "analog_transmission", + "Create_RotationSpeedController" +} + Config = {} +Config.ConfigPath = "/caero-attitude-control/config/config.txt" + +-- Monitor Configuration +Config.Monitors.InstrumentPanelMonitor = nil +Config.Monitors.AutopilotControlMonitor = nil -- Autopilot -AutopilotEngaged = false -- Is auto-yaw enabled? -AutoForeAft = false -- Is auto-thrust enabled? -AutopilotDesiredSpeed = 0 -- Signed thrust value to compare against VelocityVectors["x"] -AutopilotDesiredHeading = 0 -- If NavTableHasTarget == true this gets ignored in favor of TargetRelativeAngle +Config.Autopilot.AutopilotEngaged = false -- Is auto-yaw enabled? +Config.Autopilot.AutoForeAft = false -- Is auto-thrust enabled? +Config.Autopilot.AutopilotDesiredSpeed = 0 -- Signed thrust value to compare against VelocityVectors["x"] +Config.Autopilot.AutopilotDesiredHeading = 0 -- If NavTableHasTarget == true this gets ignored in favor of TargetRelativeAngle -- Gimbal Sensor Values Angles = { @@ -155,25 +178,15 @@ function ThrottleInit() end function PropellerInit() - local propellerTypes = { - "gyroscopic_propeller_bearing", - "propeller", - "propeller_bearing" - } - - local transmissionTypes = { - "analog_transmission", - "Create_RotationSpeedController" - } local transmissions = {} local propellers = {} - for _, v in ipairs(transmissionTypes) do + for _, v in ipairs(TransmissionTypes) do table.insert(transmissions, peripheral.find(v)) end - for _, v in ipairs(propellerTypes) do + for _, v in ipairs(PropellerTypes) do table.insert(propellers, peripheral.find(v)) end @@ -214,16 +227,10 @@ function PropellerInit() end function ThrusterInit() - local thrusterTypes = { - "thruster", - "ion_thruster", - "vector_thruster", - "liquid_vector_thruster" - } local thrusters = {} - for _, v in ipairs(thrusterTypes) do + for _, v in ipairs(ThrusterTypes) do table.insert(thrusters, peripheral.find(v)) end @@ -265,27 +272,15 @@ function Update() end local function checkIfThrusterIsIndexed() - local thrusterTypes = { - "thruster", - "ion_thruster", - "vector_thruster", - "liquid_vector_thruster" - } local thrusters = {} local unindexedThrusters = {} - for _, v in ipairs(thrusterTypes) do + for _, v in ipairs(ThrusterTypes) do table.insert(thrusters, peripheral.find(v)) end - local propellerTypes = { - "gyroscopic_propeller_bearing", - "propeller", - "propeller_bearing" - } - - for _, v in ipairs(propellerTypes) do + for _, v in ipairs(PropellerTypes) do table.insert(thrusters, peripheral.find(v)) end @@ -315,8 +310,10 @@ local function partiallyUpdateThrusters(thrusterList) "propeller_bearing" } + -- for every thruster in the input array + -- check if they are one of thrusterTypes for _, tv in ipairs(thrusterList) do - for _, tt in ipairs(thrusterTypes) do + for _, tt in ipairs(ThrusterTypes) do if peripheral.getType(tv) == tt then Thrusters[peripheral.getName(tv)] = { thruster = tv, @@ -332,6 +329,34 @@ local function partiallyUpdateThrusters(thrusterList) } end end + + for _, pt in ipairs(PropellerTypes) do + if peripheral.getType(tv) == pt then + local thisThruster = { + thruster = tv, + transmission = nil, + type = "rotator" + affectVectors = { + yaw = nil, + roll = nil, + pitch = nil + lateral = nil + }, + power = tv.getPower() + } + + for _, tt in ipairs(TransmissionTypes) do + local transmissions = peripheral.find(tt) + for _, t in ipairs(transmissions) do + if tv.getSubnetworkAnchorId() == t.getSelfId() then + thisThruster.transmission = t + end + end + end + + Thrusters[peripheral.getName(tv)] = thisThruster + end + end end end @@ -475,7 +500,7 @@ function UpdateGlobalThrust() for _, d in ipairs(thrustDirections) do for _, t in ipairs(Thrusters) do if t.affectVectors.lateral == d then - SetThrusterPower(d) + SetThrusterPower(t, d) end end end diff --git a/thrusters.lua b/thrusters.txt.example similarity index 100% rename from thrusters.lua rename to thrusters.txt.example