G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 31st, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private FixedSizedQueue<string> logText;
  2.     private string tempText;
  3.     private IMyTextPanel display1;
  4.     private IMyTextPanel display2;
  5.     private IMyPowerProducer s1;
  6.     private IMyPowerProducer s2;
  7.     private IMyPowerProducer s3;
  8.     private IMyPowerProducer s4;
  9.    
  10.     public Program()
  11.     {
  12.         Runtime.UpdateFrequency = UpdateFrequency.Update10;
  13.         s1 = GridTerminalSystem.GetBlockWithName("s1") as IMyPowerProducer;
  14.         s2 = GridTerminalSystem.GetBlockWithName("s2") as IMyPowerProducer;
  15.         s3 = GridTerminalSystem.GetBlockWithName("s3") as IMyPowerProducer;
  16.         s4 = GridTerminalSystem.GetBlockWithName("s4") as IMyPowerProducer;
  17.         display1 = GridTerminalSystem.GetBlockWithName("display1") as IMyTextPanel;
  18.         display2 = GridTerminalSystem.GetBlockWithName("display2") as IMyTextPanel;
  19.         logText = new FixedSizedQueue<string>(15);
  20.     }
  21.    
  22.     void Main()
  23.         {
  24.             tempText = "";
  25.  
  26.             float[] p1 = {s1.CurrentOutput,s2.CurrentOutput,s3.CurrentOutput,s4.CurrentOutput};
  27.            
  28.             float arrsum = p1.Sum();
  29.            
  30.             string powerOutput = "S1: " + s1.CurrentOutput.ToString() + "\n" +
  31.                                  "S2: " + s2.CurrentOutput.ToString() + "\n" +
  32.                                  "S3: " + s3.CurrentOutput.ToString() + "\n" +
  33.                                  "S4: " + s4.CurrentOutput.ToString() + "\n" +
  34.                                  "Sum: " + arrsum.ToString();
  35.             logTemp(powerOutput);
  36.  
  37.             //float pitch = 0;
  38.             //float yaw = 0;
  39.             bool rotate = false;
  40.  
  41.             IMyGyro g1 = GridTerminalSystem.GetBlockWithName("g1") as IMyGyro;
  42.             g1.Yaw = 0;
  43.             g1.Pitch = 0;
  44.             g1.Roll = 0;
  45.  
  46.             if (p1.Sum()==0.00)
  47.             {
  48.                 g1.Pitch = .1f;
  49.                 rotate = true;
  50.             }
  51.  
  52.             float roll = p1[0] - p1[2]; // 2 > 0, -Roll
  53.             float yaw = p1[3] - p1[1]; // 1 > 3, -Yaw
  54.             if (Math.Abs(roll) > .01 || Math.Abs(yaw)>.01)
  55.             {
  56.                 g1.Yaw = yaw;
  57.                 g1.Roll = roll;
  58.                 logPerm("Adjusting: Roll:" + roll.ToString() + " Yaw:" +yaw.ToString());
  59.                 rotate = true;
  60.             }
  61.             g1.GyroOverride = rotate;
  62.  
  63.             writeDisplayText();
  64.         }
  65.  
  66.         void writeDisplayText()
  67.         {
  68.             display1.WriteText(tempText);
  69.             string logString = "";
  70.             foreach(string line in logText.toArray())
  71.             {
  72.                 logString += line + "\n";
  73.             }
  74.            
  75.             display2.WriteText(logString);
  76.         }
  77.        
  78.         void logPerm(string input)
  79.         {
  80.             logText.insert(input);
  81.         }
  82.  
  83.         void logTemp(string input)
  84.         {
  85.             tempText += input + "\n";
  86.         }
  87.        
  88.         public void Save()
  89.         {
  90.         }
  91.        
  92.         public class FixedSizedQueue<T>
  93.         {
  94.             readonly Queue<T> queue = new Queue<T>();
  95.  
  96.             public int Size { get; private set; }
  97.  
  98.             public FixedSizedQueue(int size)
  99.             {
  100.                 Size = size;
  101.             }
  102.  
  103.             public T[] toArray()
  104.             {
  105.                 return queue.ToArray();
  106.             }
  107.            
  108.             public void insert(T obj)
  109.             {
  110.                 queue.Enqueue(obj);
  111.  
  112.                 while (queue.Count > Size)
  113.                 {
  114.                     T outObj;
  115.                     queue.TryDequeue(out outObj);
  116.                 }
  117.             }
  118.         }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top