protected void executeBlock(IMyTerminalBlock block) { this.myProgram.Echo(this.blockName + " " + this.action + " " + this.value); if (block == null) { this.haltError = true; return; } switch (this.action) { case "Apply": if (this.value == "On") { this.value = "OnOff_On"; } if (this.value == "Off") { this.value = "OnOff_Off"; } block.ApplyAction(this.value); return; case "Check": if (this.value == "On" || this.value == "Off") { bool onoff = block.GetValueBool("OnOff"); if (this.value == "On" && !onoff) { this.haltError = true; return; } if (this.value == "Off" && onoff) { this.haltError = true; return; } } if (this.value == "Attach" || this.value == "Detach") { bool rotorAttached = ((IMyMotorStator)block).IsAttached; if (this.value == "Attach" && !rotorAttached) { this.haltError = true; return; } if (this.value == "Detach" && rotorAttached) { this.haltError = true; return; } } if (this.value == "Extend" || this.value == "Retract") { PistonStatus pistonExtended = ((IMyPistonBase)block).Status; if (pistonExtended == PistonStatus.Stopped) { this.haltError = true; return; } if (this.value == "Extend" && pistonExtended == PistonStatus.Retracted) { this.haltError = true; return; } if (this.value == "Retract" && pistonExtended == PistonStatus.Extended) { this.haltError = true; return; } } return; case "Velocity": block.SetValue <Single>("Velocity", Single.Parse(this.value)); return; case "MaxLimit": block.SetValue <Single>("UpperLimit", Single.Parse(this.value)); return; case "MinLimit": block.SetValue <Single>("LowerLimit", Single.Parse(this.value)); return; } }
public static void SetValueFloat(this IMyTerminalBlock block, string propertyId, float value) { block.SetValue <float>(propertyId, value); }
public static void SetValueColor(this IMyTerminalBlock block, string propertyId, Color value) { block.SetValue <Color>(propertyId, value); }
public static void SetValueBool(this IMyTerminalBlock block, string propertyId, bool value) { block.SetValue <bool>(propertyId, value); }
double SetRotorZyklus(IMyTerminalBlock rotor, double AngleSol, bool stop) { //double VelIst; if (stop == true) { rotor.SetValue<float>("Velocity", 0); return 0; } if (!(rotor as IMyMotorStator).IsAttached) { // Rotor is Detached rotor.SetValue<float>("Velocity", 0); return 0; } double AngleIst = GetRotorAngle(rotor); //VelIst = rotor.GetValue < double > ("Velocity"); if (AngleIst < 0) { AngleIst += 360; } double Error = SmartAngle(AngleSol - AngleIst); // Difference from Actual Angle (Ist) to Target Angle (Soll) if (Math.Abs(Error) < 0.01) { //Error = 0; } // ###### Main PI Control Loop formula ######## double Output = Error * EndGain; double LocalTurnSpeedLimitFactor = Math.Abs(MaxTurnSpeed / Output); if (LocalTurnSpeedLimitFactor < GlobalTurnSpeedLimitFactor) { GlobalTurnSpeedLimitFactor = LocalTurnSpeedLimitFactor; return 0; } Output *= GlobalTurnSpeedLimitFactor; rotor.SetValue<float>("Velocity", Convert.ToSingle(Output)); return AngleIst; }
/// <summary> /// Nastaveni hodnoty vlastnosti /// </summary> /// <param name="block">Blok</param> /// <param name="property">Vlastnost</param> /// <param name="value">Hodnota</param> public static void SetValue <V>(IMyTerminalBlock block, string property, V value) { block.SetValue(property, value); }