//private DispatcherTimer timer; private void TrackerSensor_InterruptHandler(object sender, TrackingSensorEventArgs e) { //timer = new DispatcherTimer(); //timer.Interval = TimeSpan.FromMilliseconds(500); //timer.Tick += Timer_Tick; //timer.Start(); System.Diagnostics.Debug.WriteLine("*************************** trackersensor_interrupthandler **************************** "); var tracker = sender as ITrackingSensor; switch (tracker.PinNumber) { case 4: // todo: turn leftforward hard //if(status1 == trackerSensor1.DetectStatus()) System.Diagnostics.Debug.WriteLine("turn left"); break; case 6: // todo: turn leftforward hard System.Diagnostics.Debug.WriteLine("turn leftforward"); break; case 22: // todo: slowforward System.Diagnostics.Debug.WriteLine("slowforward"); break; case 23: // todo: turn rightforward hard System.Diagnostics.Debug.WriteLine("turn rightforward"); break; case 27: // todo: turn right hard System.Diagnostics.Debug.WriteLine("turn right"); break; default: System.Diagnostics.Debug.WriteLine("forward"); break; } System.Diagnostics.Debug.WriteLine("track sensor " + tracker.PinNumber + ", " + e.Status); }
private void TrackerSensor_InterruptHandler(object sender, TrackingSensorEventArgs e) { System.Diagnostics.Debug.WriteLine(Environment.CurrentManagedThreadId); //timer = new DispatcherTimer(); //timer.Interval = TimeSpan.FromMilliseconds(500); //timer.Tick += Timer_Tick; //timer.Start(); //System.Diagnostics.Debug.WriteLine("*************************** trackersensor_interrupthandler **************************** "); var tracker = sender as ITrackingSensor; switch (tracker.PinNumber) { case 4: // todo: turn leftforward hard //if(status1 == trackersensor1.detectstatus()) //system.diagnostics.debug.writeline("turn left"); if (TrackingSensorStatus.Active == e.Status) { fLLFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fLLFS = false; } break; case 6: // todo: turn leftforward hard //system.diagnostics.debug.writeline("turn leftforward"); if (TrackingSensorStatus.Active == e.Status) { fLRFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fLRFS = false; } break; case 22: // todo: slowforward //system.diagnostics.debug.writeline("slowforward"); if (TrackingSensorStatus.Active == e.Status) { fMFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fMFS = false; } break; case 23: // todo: turn rightforward hard //system.diagnostics.debug.writeline("turn rightforward"); if (TrackingSensorStatus.Active == e.Status) { fRLFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fRLFS = false; } break; case 27: // todo: turn right hard //system.diagnostics.debug.writeline("turn right"); if (TrackingSensorStatus.Active == e.Status) { fRRFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fRRFS = false; } break; default: //system.diagnostics.debug.writeline("stop"); fLLFS = false; fLRFS = false; fMFS = false; fRLFS = false; fRRFS = false; break; } System.Diagnostics.Debug.WriteLine("track sensor " + tracker.PinNumber + ", " + e.Status); //Task.Delay(100).Wait(); //if (tracker.DetectStatus == Active) //{ //} }
private void TrackerSensor_InterruptHandler(object sender, TrackingSensorEventArgs e) { System.Diagnostics.Debug.WriteLine(Environment.CurrentManagedThreadId); // Save previous state prevState = currState; //timer = new DispatcherTimer(); //timer.Interval = TimeSpan.FromMilliseconds(500); //timer.Tick += Timer_Tick; //timer.Start(); //System.Diagnostics.Debug.WriteLine("*************************** trackersensor_interrupthandler **************************** "); var tracker = sender as ITrackingSensor; switch (tracker.PinNumber) { case 4: // todo: turn leftforward hard //if(status1 == trackersensor1.detectstatus()) //system.diagnostics.debug.writeline("turn left"); if (TrackingSensorStatus.Active == e.Status) { fLLFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fLLFS = false; } break; case 6: // todo: turn leftforward hard //system.diagnostics.debug.writeline("turn leftforward"); if (TrackingSensorStatus.Active == e.Status) { fLRFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fLRFS = false; } break; // TODO: currState = AlphaBotState.State5; case 22: // todo: slowforward //system.diagnostics.debug.writeline("slowforward"); if (TrackingSensorStatus.Active == e.Status) { fMFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fMFS = false; } break; // TODO: currState = AlphaBotState.State5; case 23: // todo: turn rightforward hard //system.diagnostics.debug.writeline("turn rightforward"); if (TrackingSensorStatus.Active == e.Status) { fRLFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fRLFS = false; } break; // TODO: currState = AlphaBotState.State5; case 27: // todo: turn right hard //system.diagnostics.debug.writeline("turn right"); if (TrackingSensorStatus.Active == e.Status) { fRRFS = true; } else if (TrackingSensorStatus.Inactive == e.Status) { fRRFS = false; } break; // TODO: currState = AlphaBotState.State5; default: //system.diagnostics.debug.writeline("stop"); fLLFS = false; fLRFS = false; fMFS = false; fRLFS = false; fRRFS = false; break; } // State Machine switch (currState) { case AlphaBotState.State1: if (prevState == AlphaBotState.State6) { LeftMotor.TurnLeft(); } else if (prevState == AlphaBotState.State2) { RightMotor.TurnLeft(); } else { Fault(); } break; case AlphaBotState.State2: if (prevState == AlphaBotState.State6) { LeftMotor.TurnLeft(); } else if (prevState == AlphaBotState.State2) { RightMotor.TurnLeft(); } else { Fault(); } break; case AlphaBotState.State3: if (prevState == AlphaBotState.State6) { LeftMotor.TurnLeft(); } else if (prevState == AlphaBotState.State2) { RightMotor.TurnLeft(); } else { Fault(); } break; case AlphaBotState.State4: if (prevState == AlphaBotState.State6) { LeftMotor.TurnLeft(); } else if (prevState == AlphaBotState.State2) { RightMotor.TurnLeft(); } else { Fault(); } break; case AlphaBotState.State5: if (prevState == AlphaBotState.State6) { LeftMotor.TurnLeft(); } else if (prevState == AlphaBotState.State2) { RightMotor.TurnLeft(); } else { Fault(); } break; case AlphaBotState.State6: if (prevState == AlphaBotState.State6) { LeftMotor.TurnLeft(); } else if (prevState == AlphaBotState.State2) { RightMotor.TurnLeft(); } else { Fault(); } break; default: Fault(); break; } System.Diagnostics.Debug.WriteLine("track sensor " + tracker.PinNumber + ", " + e.Status); }