Last active
August 9, 2023 11:04
-
-
Save hmmdeif/de9b2dd7c0c559a2f86c to your computer and use it in GitHub Desktop.
Space Engineers script to rotate a main solar panel to check for the rotation of the sun. Once the output is high enough, the rotors will stop spinning until the max output falls below the threshold.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main(string argument) | |
{ | |
List<IMyTerminalBlock> solarRotors = new List<IMyTerminalBlock>(); | |
IMySolarPanel mainSolarPanel = GridTerminalSystem.GetBlockWithName("Main Solar Panel Optimised") as IMySolarPanel; | |
int currentPower = GetPanelPower(mainSolarPanel); | |
GridTerminalSystem.SearchBlocksOfName("Solar Rotor", solarRotors); | |
if (currentPower <= 100) { | |
RotateSolarRotors(solarRotors); | |
} else { | |
StopSolarRotors(solarRotors); | |
} | |
} | |
public int GetPanelPower(IMySolarPanel panel) | |
{ | |
var _d = panel.DetailedInfo; | |
// If you want to see what's in DetailedInfo you can write: | |
// Throw new Exception(_d); | |
// Save the code and exit, then run the script on the programmable block to see the output | |
string _power = _d.Split(new string[] {"\n"}, StringSplitOptions.None)[1].Split(' ')[2]; //Checking the MAX Output | |
int _powerOutput = Convert.ToInt32(Math.Round(Convert.ToDouble(_power))); | |
return _powerOutput; | |
} | |
public void StopSolarRotors(List<IMyTerminalBlock> solarRotors) { | |
for (var i = 0; i < solarRotors.Count; i++) { | |
IMyMotorStator rotor = solarRotors[i] as IMyMotorStator; | |
rotor.GetActionWithName("ResetVelocity").Apply(rotor); | |
} | |
} | |
public void RotateSolarRotors(List<IMyTerminalBlock> solarRotors) { | |
for (var i = 0; i < solarRotors.Count; i++) { | |
IMyMotorStator rotor = solarRotors[i] as IMyMotorStator; | |
if (rotor.Velocity < 3) { | |
rotor.GetActionWithName("IncreaseVelocity").Apply(rotor); | |
} | |
} | |
} |
Yeah the script is really primitive. I figured 100kw is good enough and if it drops just spin until it finds the new sun position. This was mainly so I could get onto other things without spending too much time in the details and it was "good enough" and useful enough for the required purpose. Plus it looks cool at night to have your solar array just spinning trying to find the sun.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. I've been looking for a simple enough solar tracking script for Space Engineers, looking for ideas to try to write a little script of my own, because as powerful as some scripts might be (with data and graph displays on screens and such) it would take the fun out of it, at least for me.
If I understand correctly, this code looks for the max (current) power of one of the panels, if it's less or equal to 100 (kW?) spin the rotors, if it's more, lock the rotors, and aligns the panels on azimuth only, on a fixed orientation on the x-axis, either on fixed blocks, or on another rotor, to be aligned manually to match the east-west direction.
So the panel would always sort of lag behind the sun, to where it makes at least 101 kW? I was thinking it might be a percentage at first, but the stop condition didn't really make sense.
I was thinking it might be possible to determine in a dynamic manner, what the max possible power output is, and adjust accordingly. I tried to write a script once where I'd store the last current power in a variable, and compare it to the current power, but it didn't really occur to me that I didn't implement a delay between samplings, and I was always getting the same current and last current power levels, which would explain why the panels wouldn't stop spinning, lol