Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Whip's Tank Skid Steering System - Revision 8 - 9/1/2015
- /// Adapted for Dwarf-Lord Pangolin's Tanks ///
- ______________________________________________________________________
- Instructions:
- Run the script with the desired arguments to execute specific movements
- ______________________________________________________________________
- Arguments:
- "advance" - Moves forward
- "reverse" - Moves Backward
- "left" - Turns left
- "right" - Turns right
- "stop" - Full stop
- Arguments should be entered without quotes; letter case is unimportant
- ______________________________________________________________________
- To-do List:
- * Add precise rotor speed settings
- Feel free to shoot me any questions!
- - Whiplash141 - http://steamcommunity.com/id/Whiplash141/
- */
- string AxleLeftName = "Rotor - Left Axle";
- string AxleRightName = "Rotor - Right Axle";
- float VelocityLeft;
- float VelocityRight;
- float VelocityAverage;
- List<IMyTerminalBlock> AxleLeft = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> AxleRight = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> AllRotors = new List<IMyTerminalBlock>();
- void Main (string argument)
- {
- GridTerminalSystem.GetBlocksOfType<IMyMotorStator>(AllRotors);
- GridTerminalSystem.SearchBlocksOfName(AxleLeftName,AxleLeft);
- GridTerminalSystem.SearchBlocksOfName(AxleRightName,AxleRight);
- for(int i = 0 ; i < AllRotors.Count ; i++)
- {
- if(AllRotors[i].CustomName.Contains(AxleLeftName))
- {
- AxleLeft.Add(AllRotors[i] as IMyMotorStator);
- }
- else if(AllRotors[i].CustomName.Contains(AxleRightName))
- {
- AxleRight.Add(AllRotors[i] as IMyMotorStator);
- }
- }
- switch(argument.ToLower())
- {
- case "right":
- Echo("Turning Right");
- TurnRight();
- break;
- case "left":
- Echo("Turning Left");
- TurnLeft();
- break;
- case "advance":
- Echo("Advancing");
- Advance();
- break;
- case "reverse":
- Echo("Reversing");
- Reverse();
- break;
- case "stop":
- Echo("Full Stop");
- FullStop();
- break;
- case "default":
- Echo("Idle");
- break;
- }
- }
- void TurnRight()
- {
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.ApplyAction("DecreaseVelocity");
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.ApplyAction("DecreaseVelocity");
- }
- }
- void TurnLeft()
- {
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.ApplyAction("IncreaseVelocity");
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.ApplyAction("IncreaseVelocity");
- }
- }
- void Advance()
- {
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.ApplyAction("IncreaseVelocity");
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.ApplyAction("DecreaseVelocity");
- }
- if(AxleRight[0] != null && AxleLeft[0] != null)
- {
- var ThisLeft = AxleLeft[0] as IMyMotorStator;
- var ThisRight = AxleRight[0] as IMyMotorStator;
- VelocityLeft = Math.Abs(ThisLeft.Velocity); Echo("Left: " + VelocityLeft);
- VelocityRight = Math.Abs(ThisRight.Velocity); Echo("Right: " + VelocityRight);
- if(VelocityLeft != VelocityRight)
- {
- VelocityAverage = Convert.ToInt32(VelocityLeft / 2 + VelocityRight / 2);
- VelocityAverage = VelocityAverage - VelocityAverage % 12; Echo("Avg: " + VelocityAverage);
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.SetValue<float>("Velocity",VelocityAverage);
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.SetValue<float>("Velocity",-1 * VelocityAverage);
- }
- }
- }
- }
- void Reverse()
- {
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.ApplyAction("DecreaseVelocity");
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.ApplyAction("IncreaseVelocity");
- }
- if(AxleRight[0] != null && AxleLeft[0] != null)
- {
- var ThisLeft = AxleLeft[0] as IMyMotorStator;
- var ThisRight = AxleRight[0] as IMyMotorStator;
- VelocityLeft = Math.Abs(ThisLeft.Velocity); Echo("Left: " + VelocityLeft);
- VelocityRight = Math.Abs(ThisRight.Velocity); Echo("Right: " + VelocityRight);
- if(VelocityLeft != VelocityRight)
- {
- VelocityAverage = Convert.ToInt32(VelocityLeft / 2 + VelocityRight / 2);
- VelocityAverage = VelocityAverage - VelocityAverage % 12; Echo("Avg: " + VelocityAverage);
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.SetValue<float>("Velocity",-1 * VelocityAverage);
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.SetValue<float>("Velocity",VelocityAverage);
- }
- }
- }
- }
- void FullStop()
- {
- for(int i = 0 ; i < AxleRight.Count ; i++)
- {
- var CurrentRight = AxleRight[i] as IMyMotorStator;
- CurrentRight.ApplyAction("ResetVelocity");
- }
- for(int i = 0 ; i < AxleLeft.Count ; i++)
- {
- var CurrentLeft = AxleLeft[i] as IMyMotorStator;
- CurrentLeft.ApplyAction("ResetVelocity");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment