Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Help with a Rotor Alignment Script

Discussion in 'Programming Questions and Suggestions' started by rickyralph, Apr 28, 2019.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. rickyralph Trainee Engineer

    I created a Mining Rig that is broken into three sections: The Front (Cockpit), The Mid (Miner), and Rear (Hangar). The three sections are joined by advanced rotors. There is 3 in the front and 3 in the back. There are two horizontal rotors and one rotational rotor per section. The horizontal rotors allow the rigs sections to bend while it moves up an down terrain and the rotational allows the sections to rotate freely over the terrain. I am trying to write a script that will constantly run to align the horizontal rotors to 0 degrees but i can't get the code to work. Any advice or help is appreciated.

    int x = 2;
    	public Program()
    		Runtime.UpdateFrequency = UpdateFrequency.Update10;
    	void Main(string argument)
    		var RotorMost = GridTerminalSystem.GetBlockWithName("Advanced Rotor Free Forward1") as IMyMotorStator;
    		var RotorMost2 = GridTerminalSystem.GetBlockWithName("Advanced Rotor Free Forward2") as IMyMotorStator;
    		var RotorMost3 = GridTerminalSystem.GetBlockWithName("Advanced Rotor Free Rear1") as IMyMotorStator;
    		var RotorMost4 = GridTerminalSystem.GetBlockWithName("Advanced Rotor Free Rear2") as IMyMotorStator;
    		// Rig Rotor Alignment
    		if (RotorMost.Angle > 1)
    		{ RotorMost.TargetVelocityRPM = -x; }
    		else if (RotorMost.Angle < -1)
    		{ RotorMost.TargetVelocityRPM = x; }
    		if (RotorMost2.Angle > 1)
    		{ RotorMost2.TargetVelocityRPM = -x; }
    		else if (RotorMost2.Angle < -1)
    		{ RotorMost2.TargetVelocityRPM = x; }
    		if (RotorMost3.Angle > 1)
    		{ RotorMost3.TargetVelocityRPM = -x; }
    		else if (RotorMost3.Angle < -1)
    		{ RotorMost3.TargetVelocityRPM = x; }
    		if (RotorMost4.Angle > 1)
    		{ RotorMost4.TargetVelocityRPM = -x; }
    		else if (RotorMost4.Angle < -1)
    		{ RotorMost4.TargetVelocityRPM = x; }
Thread Status:
This last post in this thread was made more than 31 days old.