Skip to content

Instantly share code, notes, and snippets.

@hmmdeif
Last active August 9, 2023 11:04
Show Gist options
  • Save hmmdeif/de9b2dd7c0c559a2f86c to your computer and use it in GitHub Desktop.
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.
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);
}
}
}
@hmmdeif
Copy link
Author

hmmdeif commented Aug 9, 2023

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