Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private FixedSizedQueue<string> logText;
- private string tempText;
- private IMyTextPanel display1;
- private IMyTextPanel display2;
- private IMyPowerProducer s1;
- private IMyPowerProducer s2;
- private IMyPowerProducer s3;
- private IMyPowerProducer s4;
- public Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update10;
- s1 = GridTerminalSystem.GetBlockWithName("s1") as IMyPowerProducer;
- s2 = GridTerminalSystem.GetBlockWithName("s2") as IMyPowerProducer;
- s3 = GridTerminalSystem.GetBlockWithName("s3") as IMyPowerProducer;
- s4 = GridTerminalSystem.GetBlockWithName("s4") as IMyPowerProducer;
- display1 = GridTerminalSystem.GetBlockWithName("display1") as IMyTextPanel;
- display2 = GridTerminalSystem.GetBlockWithName("display2") as IMyTextPanel;
- logText = new FixedSizedQueue<string>(15);
- }
- void Main()
- {
- tempText = "";
- float[] p1 = {s1.CurrentOutput,s2.CurrentOutput,s3.CurrentOutput,s4.CurrentOutput};
- float arrsum = p1.Sum();
- string powerOutput = "S1: " + s1.CurrentOutput.ToString() + "\n" +
- "S2: " + s2.CurrentOutput.ToString() + "\n" +
- "S3: " + s3.CurrentOutput.ToString() + "\n" +
- "S4: " + s4.CurrentOutput.ToString() + "\n" +
- "Sum: " + arrsum.ToString();
- logTemp(powerOutput);
- //float pitch = 0;
- //float yaw = 0;
- bool rotate = false;
- IMyGyro g1 = GridTerminalSystem.GetBlockWithName("g1") as IMyGyro;
- g1.Yaw = 0;
- g1.Pitch = 0;
- g1.Roll = 0;
- if (p1.Sum()==0.00)
- {
- g1.Pitch = .1f;
- rotate = true;
- }
- float roll = p1[0] - p1[2]; // 2 > 0, -Roll
- float yaw = p1[3] - p1[1]; // 1 > 3, -Yaw
- if (Math.Abs(roll) > .01 || Math.Abs(yaw)>.01)
- {
- g1.Yaw = yaw;
- g1.Roll = roll;
- logPerm("Adjusting: Roll:" + roll.ToString() + " Yaw:" +yaw.ToString());
- rotate = true;
- }
- g1.GyroOverride = rotate;
- writeDisplayText();
- }
- void writeDisplayText()
- {
- display1.WriteText(tempText);
- string logString = "";
- foreach(string line in logText.toArray())
- {
- logString += line + "\n";
- }
- display2.WriteText(logString);
- }
- void logPerm(string input)
- {
- logText.insert(input);
- }
- void logTemp(string input)
- {
- tempText += input + "\n";
- }
- public void Save()
- {
- }
- public class FixedSizedQueue<T>
- {
- readonly Queue<T> queue = new Queue<T>();
- public int Size { get; private set; }
- public FixedSizedQueue(int size)
- {
- Size = size;
- }
- public T[] toArray()
- {
- return queue.ToArray();
- }
- public void insert(T obj)
- {
- queue.Enqueue(obj);
- while (queue.Count > Size)
- {
- T outObj;
- queue.TryDequeue(out outObj);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement