Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main(string arg)
- {
- /* Twinkie Industries™ Automation Presents
- * Multiple Hinge Control v1.1
- This script will allow you to add as many hinges as you like and then control their angles
- in one easy step.
- Add one programming block for each set of hinges that you want to control.
- Add all of your hinges to the script and set the desired velocity.
- Set the programming block argument to the angle you want the hinges to move to and run it. All of the hinges will move to that angle.
- You can create cockpit toolbar buttons from the programming block to make preset angles.
- */
- //PLEASE EDIT THIS SECTION ONLY------------------------------------------------------------------------------------------------------------------------------
- /*Add your hinges here
- Each hinge will need its own line with a unique name between the quotation marks. */
- listHinges.Add(GridTerminalSystem.GetBlockWithName("Conveyor Hinge") as IMyMotorStator);
- listHinges.Add(GridTerminalSystem.GetBlockWithName("Conveyor Hinge 2") as IMyMotorStator);
- //Movement velocity
- float velocity = 30f;
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------
- setAngle = Single.Parse(arg);
- if (setAngle <= 90 && setAngle >= -90)//Check angle limits
- {
- //Loop through each hinge on the list
- for (int i = 0; i < listHinges.Count; i++)
- {
- IMyMotorStator currentHinge = listHinges[i];
- if (currentHinge == null)
- continue;
- //Find the rotation direction needed
- float curAngle = getAngle(currentHinge);
- if (debug)
- {
- Echo("current angle " + curAngle);
- Echo("set angle " + setAngle);
- }
- if (curAngle == setAngle) setVelocity = 0f;
- else setVelocity = (curAngle < setAngle) ? velocity : -velocity;
- if (debug) Echo("setVelocity " + setVelocity);
- //Set the appropriate limit
- if (setVelocity > 0) currentHinge.SetValue<float>("UpperLimit", (float)setAngle);
- else currentHinge.SetValue<float>("LowerLimit", (float)setAngle);
- //Set the velocity
- currentHinge.SetValue<float>("Velocity", setVelocity);
- }
- }
- }
- /// <summary>Returns the current angle of a hinge</summary>
- float getAngle(IMyMotorStator hinge)
- {
- string data = hinge.DetailedInfo;
- string[] dataSplit = data.Split(':');
- return float.Parse(dataSplit[1].Substring(0, dataSplit[1].Length - 1));
- }
- /// <summary>Velocity to be set</summary>
- float setVelocity;
- /// <summary>The angle to be set</summary>
- double setAngle;
- /// <summary>List of hinges</summary>
- List<IMyMotorStator> listHinges = new List<IMyMotorStator>();
- /// <summary>Enable debugging</summary>
- bool debug = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement