using System; using Microsoft.SPOT; using System.Text; namespace abstractState { public class Descend : StateBase { public Descend(string name) { stateName.Clear(); stateName.Append(name); ECTimeout = 10 * 1000; //seconds } private enum Action : int { stateEntry = 0, setPV, lastAction } private Action currentAction = (Action)0; private static int pressureTableNum = 0; public override int doStateActions() { int returnValue = 0; switch (currentAction) { case (Action.stateEntry): returnValue = stateEntry(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in Descend State Entry"); break; case (Action.setPV): returnValue = setPV(); if (returnValue >= 0) currentAction = (Action)returnValue; else Debug.Print("Error in InitMission moveBellowsInsideLimits"); break; } return (returnValue); } public override Program.CPFStates checkEvents() { return (Program.CPFStates.descend); } public override Program.CPFStates doTimeoutAction() { return (Program.CPFStates.ascend); } private static double depthSetPoint = double.NaN; private static double PVSetPoint = 0.0; private static double absPVSetPoint = 0.0; //absolute value of PVSetPoint private static readonly StringBuilder profileStateNone = new StringBuilder("None"); private static readonly StringBuilder profileStateInBand = new StringBuilder("In Band"); private static readonly StringBuilder profileStateOuterBand = new StringBuilder("Outer Band"); private static readonly StringBuilder profileStateOutsideBand = new StringBuilder("Outside Band"); private static StringBuilder profileState = new StringBuilder(32); private static TimeSpan parkTime; private static int stateEntry() { basicStateEntry(); SV.parked = false; pressureTableNum = 0; // depthSetPoint = Mission.descendTable[pressureTableNum].depth; // parkTime = Mission.descendTable[pressureTableNum].parkTime; BuoyancyControl.resetPVPID(); SV.runPVPID = true; profileState.Clear(); profileState.Append(profileStateNone); //BTConsole.BTSend = false; return ((int)Action.setPV); } private static int setPV() { //TODO: should these 2 assignment and PVSetPoint be moved up into state entry block and then repeated after pressure table num increments? depthSetPoint = Mission.descendTable[pressureTableNum].depth; parkTime = Mission.descendTable[pressureTableNum].parkTime; //If we're not parking at target depth if (parkTime == TimeSpan.Zero) { //keep going if (SV.pressure < depthSetPoint) { // PVSetPoint = -1.0 * System.Math.Abs(Mission.descendTable[pressureTableNum].PV); SV.runPVPID = true; } //until we pass the target depth if (SV.pressure >= depthSetPoint) { // InstrumentHandler.sampleInstruments(pressureTableNum); pressureTableNum = pressureTableNum + 1; } } //Else if we are parking at this depth check to see which of the depth bands we're in // and calculate the new PV for the correct band else if (parkTime > TimeSpan.Zero) { // absPVSetPoint = System.Math.Abs(Mission.descendTable[pressureTableNum].PV); // PVSetPoint = checkDepthBand(pressure, depthSetPoint, absPVSetPoint); } return ((int)Action.setPV); } } public class Ascend : StateBase { public Ascend(string name) { stateName.Clear(); stateName.Append(name); ECTimeout = 20000; } private enum Action : int { stateEntry = 0, lastAction } private Action currentAction = (Action)0; public override int doStateActions() { return (0); } public override Program.CPFStates checkEvents() { return (Program.CPFStates.descend); } public override Program.CPFStates doTimeoutAction() { return (Program.CPFStates.descend); } } public class Utilities { public static double checkDepthBand() { return (double.NaN); } } }