Esempio n. 1
0
        /**
         * ビューがアンロードロードされたときのクリーンアップ処理
         */
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            TrackingTimer.Stop();

            Ready = false;
            mPlayerElement.SetMediaPlayer(null);
            mPlayer.Pause();
            mPlayer.PlaybackSession.PlaybackStateChanged -= PBS_StateChanged;
            mPlayer.MediaFailed -= MP_Failed;
            mPlayer.Dispose();
            mPlayer = null;
        }
Esempio n. 2
0
    private void GunTrackOff()
    {
      GunTrackButton.Text = "OFF";
      GunTrackButton.BackColor = Color.Red;
      GunFireButton.Enabled = false;
      MotionDetectionButton.Enabled = true;

      TrackingTimer.Stop();
      aimDot.Visible = false;

      //Packet packet = new Packet(servos.CenterServosPosition);
      //packet.setFireOff();
      //sendData(packet);

    }
Esempio n. 3
0
    //Timer that tracks refresh of position tracking
    private void TrackingTimer_Tick(object sender, EventArgs e) //125ms refresh rate as of right now
    {
      if (cameraWindow1.Camera != null && cameraWindow1.Camera.MotionDetector != null)
      {
        CountingMotionDetector cmd = (CountingMotionDetector)cameraWindow1.Camera.MotionDetector;
        Rectangle[] rectmotion = cmd.ObjectRectangles;

        if (rectmotion.Length != 0)
        {
          if (!firingsoundplayed && soundOn)
          {
            switch (soundTracker % 4)
            {
              case 0:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target Found\\firing.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                firingsoundplayed = true;
                break;
              case 1:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target Found\\i_see_you.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                firingsoundplayed = true;
                break;
              case 2:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target Found\\target_acquired.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                firingsoundplayed = true;
                break;
              case 3:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target Found\\there_you_are.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                firingsoundplayed = true;
                break;
            }
          }
          ceasefiringsoundplayed = false;
          aimDot.BackColor = Color.Red;
          //aimDot.Visible = true;
          //calculate largest detected motion area
          Rectangle largest = rectmotion[0];
          for (int i = 1; i < rectmotion.Length; i++)
          {
            if (rectmotion[i].Width * rectmotion[i].Height > largest.Width * largest.Height)
            {
              largest = rectmotion[i];
            }
          }

          //get center of largest motion area
          int x = largest.X + largest.Width / 2 + cameraWindow1.Location.X;
          int y = largest.Y + largest.Height / 2 + cameraWindow1.Location.Y;

          //calculate difference from last center point and adjust target lead depending on speed
          if (lastCenterPosition.IsEmpty)
          {
            lastCenterPosition = new Point(x, y);
            lastLeadingPosition = new Point(lastCenterPosition.X, lastCenterPosition.Y);
          }
          else if (!lastCenterPosition.IsEmpty)
          {
            int xdiff = x - lastCenterPosition.X;
            int ydiff = y - lastCenterPosition.Y;
            lastLeadingPosition = new Point(x + multiplier*xdiff, y + ydiff);
            lastCenterPosition = new Point(x, y);
            Console.WriteLine(xdiff.ToString());
          }

          //set aimdot location
          aimDot.Location = new Point(lastLeadingPosition.X - 2, lastLeadingPosition.Y - 2);

          //create packet, set servo position, and fire
          servos.SetPorportionalMathPosition(cameraWindow1.Bounds, lastLeadingPosition);
          Packet packet = new Packet(servos.ServosPosition);
          //Console.WriteLine("(" + servos.Position.X + "," + servos.Position.Y + ")");
          //MessageBox.Show("(" + servos.Position.X + "," + servos.Position.Y + ")");
          packet.setFireOff();
          if (firingOn)
          {
            packet.setFireOn();
          }
          sendData(packet);
        }
        else if (rectmotion.Length == 0)
        {
          if (!ceasefiringsoundplayed && soundOn)
          {
            switch (soundTracker % 4)
            {
              case 0:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target lost\\searching.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);

                ceasefiringsoundplayed = true;
                break;
              case 1:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target lost\\is_anyone_there.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                ceasefiringsoundplayed = true;
                break;
              case 2:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target lost\\target_lost.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                ceasefiringsoundplayed = true;
                break;
              case 3:
                PlaySound(pwd + "\\Sounds\\Sentry Sounds\\Target Lost\\are_you_still_there.wav", IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC);
                ceasefiringsoundplayed = true;
                break;
            }
            soundTracker++;
          }
          firingsoundplayed = false;
          //when no motion, center aimDot and return servos to center position
          aimDot.Location = new Point(cameraWindow1.Location.X + cameraWindow1.Width / 2 - 2, cameraWindow1.Location.Y + cameraWindow1.Height / 2 - 2);
          aimDot.BackColor = Color.Yellow;
          //aimDot.Visible = false;
          lastCenterPosition = new Point();
          lastLeadingPosition = new Point();
          Packet packet = new Packet(servos.CenterServosPosition);
          packet.setFireOff();
          sendData(packet);
        }
      }
      else
      {
        MessageBox.Show("No Active Camera w/ Active Motion Detector!");
        TrackingTimer.Stop();
      }
    }