/* * public static bool CheckPort(string port) * { * if(File.Exists(UtilAll.GetECapSimSignalFileName())) { //simulatedEncoder * simulated = true; * return true; * } * * simulated = false; * * LogB.Information("testing encoder port: ", port); * sp = new SerialPort(port); * sp.BaudRate = 115200; * LogB.Information("testing 1: sp created"); * try { * sp.Open(); * LogB.Information("testing 2: sp opened"); * sp.Close(); * LogB.Information("testing 3: sp closed. Success!"); * } catch { * LogB.Error("testing encoder port failed"); * return false; * } * return true; * } */ //if cont (continuous mode), then will not end when too much time passed before start public void InitGlobal(int widthG, int heightG, int time, int timeEnd, bool cont, string eccon, string port) { this.widthG = widthG; this.heightG = heightG; this.cont = cont; this.eccon = eccon; //---- a) open port ----- if (!simulated) { LogB.Debug("runEncoderCaptureCsharp start port:", port); sp = new SerialPort(port); sp.BaudRate = 115200; LogB.Information("sp created"); sp.Open(); LogB.Information("sp opened"); } //---- b) initialize variables ---- Ecca = new EncoderCaptureCurveArray(); Countdown = time; msCount = 0; //used for visual feedback of remaining time recordingTime = time * 1000; recordedTimeCont = 1; //not 0 to not have divide by zero problems encoderReaded = new List <int>(); encoderReadedInertialDisc = new List <int>(); EncoderCapturePoints = new List <Gdk.Point>(); EncoderCapturePointsInertialDisc = new List <Gdk.Point>(); EncoderCapturePointsCaptured = 0; EncoderCapturePointsPainted = 0; //-1 means delete screen sum = 0; i = -20; //delete first records because there's encoder bug /* * calculate params with R explanation */ /* 3 * / \ * / B * / \ * --1 / * \ / * \ A * \2/ * * Record the signal, when arrive to A, then store the descending phase (1-2) and calculate params (power, ...) * When arrive to B, then store the ascending phase (2-3) */ directionChangePeriod = 25; //how long (ms) to recognize as change direction. (from 2 to A in ms) //it's in ms and not in cm, because it's easier to calculate directionChangeCount = 0; //counter for this period directionNow = 1; // +1 or -1 directionLastMSecond = 1; // +1 or -1 (direction on last millisecond) directionCompleted = -1; // +1 or -1 previousEnd = 0; lastNonZero = 0; //this will be used to stop encoder automatically (on !cont mode) consecutiveZeros = -1; consecutiveZerosMax = timeEnd * 1000; //only can be true on inertial capture subclass inertialShouldCheckStartDirection = false; inertialCaptureDirectionInverted = false; initSpecific(); cancel = false; finish = false; }
/* public static bool CheckPort(string port) { if(File.Exists(UtilAll.GetECapSimSignalFileName())) { //simulatedEncoder simulated = true; return true; } simulated = false; LogB.Information("testing encoder port: ", port); sp = new SerialPort(port); sp.BaudRate = 115200; LogB.Information("testing 1: sp created"); try { sp.Open(); LogB.Information("testing 2: sp opened"); sp.Close(); LogB.Information("testing 3: sp closed. Success!"); } catch { LogB.Error("testing encoder port failed"); return false; } return true; } */ //if cont (continuous mode), then will not end when too much time passed before start public void InitGlobal(int widthG, int heightG, int time, int timeEnd, bool cont, string eccon, string port) { this.widthG = widthG; this.heightG = heightG; this.cont = cont; this.eccon = eccon; //---- a) open port ----- if(! simulated) { LogB.Debug("runEncoderCaptureCsharp start port:", port); sp = new SerialPort(port); sp.BaudRate = 115200; LogB.Information("sp created"); sp.Open(); LogB.Information("sp opened"); } //---- b) initialize variables ---- Ecca = new EncoderCaptureCurveArray(); Countdown = time; msCount = 0; //used for visual feedback of remaining time recordingTime = time * 1000; recordedTimeCont = 1; //not 0 to not have divide by zero problems encoderReaded = new List<int>(); encoderReadedInertialDisc = new List<int>(); EncoderCapturePoints = new List<Gdk.Point>(); EncoderCapturePointsInertialDisc = new List<Gdk.Point>(); EncoderCapturePointsCaptured = 0; EncoderCapturePointsPainted = 0; //-1 means delete screen sum = 0; i = -20; //delete first records because there's encoder bug /* * calculate params with R explanation */ /* 3 * / \ * / B * / \ * --1 / * \ / * \ A * \2/ * * Record the signal, when arrive to A, then store the descending phase (1-2) and calculate params (power, ...) * When arrive to B, then store the ascending phase (2-3) */ directionChangePeriod = 25; //how long (ms) to recognize as change direction. (from 2 to A in ms) //it's in ms and not in cm, because it's easier to calculate directionChangeCount = 0; //counter for this period directionNow = 1; // +1 or -1 directionLastMSecond = 1; // +1 or -1 (direction on last millisecond) directionCompleted = -1; // +1 or -1 previousEnd = 0; lastNonZero = 0; //this will be used to stop encoder automatically (on !cont mode) consecutiveZeros = -1; consecutiveZerosMax = timeEnd * 1000; //only can be true on inertial capture subclass inertialShouldCheckStartDirection = false; inertialCaptureDirectionInverted = false; initSpecific(); cancel = false; finish = false; }
//if cont (continuous mode), then will not end when too much time passed before start public bool InitGlobal(int widthG, int heightG, int time, int timeEnd, bool cont, string eccon, string port, bool capturingInertialBG, bool showOnlyBars, bool simulated) { this.widthG = widthG; this.heightG = heightG; this.cont = cont; this.eccon = eccon; this.capturingInertialBG = capturingInertialBG; this.showOnlyBars = showOnlyBars; this.simulated = simulated; //---- a) open port ----- if (simulated) { rand = new Random(40); SimulatedReset(); } else if (!simulated && !capturingInertialBG) { LogB.Debug("runEncoderCaptureCsharp start port:", port); sp = new SerialPort(port); sp.BaudRate = 115200; LogB.Information("sp created"); try { sp.Open(); } catch { LogB.Information("Error: Cannot open port"); return(false); } LogB.Information("sp opened"); } //---- b) initialize variables ---- Ecca = new EncoderCaptureCurveArray(); Countdown = time; msCount = 0; //used for visual feedback of remaining time recordingTime = time * 1000; recordedTimeCont = 1; //not 0 to not have divide by zero problems encoderReaded = new List <int>(); encoderReadedInertialDisc = new List <int>(); if (!showOnlyBars) { EncoderCapturePoints = new List <Gdk.Point>(); EncoderCapturePointsInertialDisc = new List <Gdk.Point>(); EncoderCapturePointsCaptured = 0; EncoderCapturePointsPainted = 0; //-1 means delete screen } sum = 0; i = -20; //delete first records because there's encoder bug /* * calculate params with R explanation */ /* 3 * / \ * / B * / \ * --1 / * \ / * \ A * \2/ * * Record the signal, when arrive to A, then store the descending phase (1-2) and calculate params (power, ...) * When arrive to B, then store the ascending phase (2-3) */ directionChangePeriod = 25; //how long (ms) to recognize as change direction. (from 2 to A in ms) //it's in ms and not in cm, because it's easier to calculate directionChangeCount = 0; //counter for this period directionNow = 1; // +1 or -1 directionLastMSecond = 1; // +1 or -1 (direction on last millisecond) directionCompleted = -1; // +1 or -1 previousEnd = 0; lastNonZero = 0; //this will be used to stop encoder automatically (on !cont mode) //or to save this set and wait for the next on cont mode consecutiveZeros = -1; consecutiveZerosMax = timeEnd * 1000; automaticallyEndByTime = (timeEnd >= 0); initSpecific(); //prepare for receiving triggers from encoder triggerList = new TriggerList(); Util.FileDelete(Util.GetEncoderTriggerFileName()); cancel = false; finish = false; return(true); }