예제 #1
0
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine("OnNavigatedTo ");
     cam = new VideoCamera( CameraSource.PrimaryCamera );
     cam.Initialized += new EventHandler(cam_Initialized);
     visualer = new CameraVisualizer();
     visualer.SetSource(cam);
 }
예제 #2
0
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine("OnNavigatedTo ");
     cam              = new VideoCamera(CameraSource.PrimaryCamera);
     cam.Initialized += new EventHandler(cam_Initialized);
     visualer         = new CameraVisualizer();
     visualer.SetSource(cam);
 }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        float degreePerBuilding = 360 / numOfBuildings;

        cubeNum = numOfBuildings / 2;
        float currentDegree = 0f;

        foreach (Transform child in transform)
        {
            child.transform.rotation = Quaternion.Euler(currentDegree, 90f, 0f);
            currentDegree           += degreePerBuilding;
        }
        visualizer = cameras.GetComponent <CameraVisualizer> ();

        numRanges = visualizer._spectrum.Length / (numOfBuildings);
    }
예제 #4
0
        void Timer1Tick(object sender, System.EventArgs e)
        {
            GetData();                              //retrieve updated values from the joystick
            if (servo1on)                           //we check to see if our Phidget is still connected.
            {
                motorController.Text = "Connected"; //display the status of our phidget
            }
            else
            {
                motorController.Text = "Not Connected"; //display the status of our phidget
            }
            if (joyfound)                               //This variable was set as either true or false back in a directX function
            {
                joystick.Text = "Connected";            //we will display this information as well
                rawAxis.Text  =
                    "X:" + state.X + "\r\n" +
                    "Y:" + state.Y + "\r\n" +
                    "Z:" + state.Z + "\r\n" +
                    "Rx:" + state.Rx + "\r\n" +
                    "Ry:" + state.Ry + "\r\n" +
                    "Rz:" + state.Rz + "\r\n";
                rawAxis.Text += "POV: " + state.GetPointOfView()[0] + "\r\n";  //another value sent out for debugging.
            }
            else
            {
                joystick.Text = "Not Connected"; //we will also display if there is no joystick connected
            }
            if (!serialPort1.IsOpen)             //we will also need to check to make sure that our Pololu is connected.
            {
                try{
                    serialPort1.Open();               //try/catch allows us to try to something which could crash the program, but continue on even if it fails.
                }
                catch (Exception
                       c) {}
            }
            int HorzPort;                               //there are some variable that we might need for this section, which are commonly used in ROVs
            int VertPort;                               //there are some variable that we might need for this section, which are commonly used in ROVs
            int VertStar;                               //there are some variable that we might need for this section, which are commonly used in ROVs
            int HorzStar;                               //there are some variable that we might need for this section, which are commonly used in ROVs

            int[] servo = new int[8];                   //there are some variable that we might need for this section, which are commonly used in ROVs

            #endregion

            //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            //
            //Customize this section for your control Scheme.
            //
            //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

            //pololuEnable = false;     //the pololu unit, is coded to automatically parse through values and send it out.
            //setting this variable to false, allows the student to write thier own process for the pololu unit.
            //it defaults to true, which is the current state.

            int slider = (int)state.GetSlider()[0];


            pov     = state.GetPointOfView();          //we would like to have input from the "top-hat" on the joystick.
            buttons = state.GetButtons();              //we would also like to have input from the various joystick buttons.

            bool[] pressed = new bool[buttons.Length]; //the native format of button input from the joystick, is not a program friendly way
            for (int i = 0; i < buttons.Length; i++)
            {                                          // to read it.
                if (buttons[i] == 128)
                {
                    pressed[i] = true;
                }                                               //what we will do is a little bit of programming magic, to make it more useable.
                else
                {
                    pressed[i] = false;
                }
            }

            HorzPort = (yAxisDirection * state.Y) + (rxAxisDirection * state.Rz); // Sets variable for PulseWidthModulation using the joysticks
            HorzStar = (yAxisDirection * state.Y) - (rxAxisDirection * state.Rz); // Sets variable for PWM using the joysticks

            //determine if the sway button has been pressed
            bool swayMode   = false;
            int  swayButton = (int)swayButtonNUD.Value;
            if (pressed[swayButton])
            {
                swayMode = true;
            }



            int swayComponent = (xAxisDirection * state.X);
            if (!swayMode)
            {
                swayComponent = 0;
            }


            if (axisRadio.Checked)
            {
                VertPort = (zAxisDirection * state.Z) + (swayComponent);  // Sets variable for PWM using the joysticks
                VertStar = (zAxisDirection * state.Z) - (swayComponent);  // Sets variable for PWM using the joysticks
            }
            else
            {
                VertPort = (zAxisDirection * slider) + (swayComponent);  // Sets variable for PWM using the joysticks
                VertStar = (zAxisDirection * slider) - (swayComponent);  // Sets variable for PWM using the joysticks
            }

            /*
             * if(pressed[0]&&pressed[1]){beltSwitch = 572 ;}  //we want to do certain things when different joystick buttons are pressed.
             * else{beltSwitch = -40 ;}
             */

            /*
             *          if(pressed[2]){									//we want to do certain things when different joystick buttons are pressed.
             *                  if(!joyDelay){
             *                          if(camSwitch == 572){camSwitch = -40;}  //this is a toggle of a relay. notice that it determines it's current state
             *                          else{camSwitch = 572;}					// and uses that to decide what to do next.
             *                  joyDelay = true;
             *                  }
             *          }
             *          if(!pressed[2]){
             *                  joyDelay = false;}
             */
            PerformJoystickClick(pressed[2], ref joyDelay, ref camSwitch);
            PerformJoystickClick(pressed[3], ref joyDelay2, ref altCamSwitch);

            /*
             * if (pressed[3])
             * {									//we want to do certain things when different joystick buttons are pressed.
             *  if (!joyDelay2)
             *  {
             *      if (altCamSwitch == 572) { altCamSwitch = -40; }  //this is a toggle of a relay. notice that it determines it's current state
             *      else { altCamSwitch = 572; }					// and uses that to decide what to do next.
             *      joyDelay2 = true;
             *  }
             * }
             * if (!pressed[3])
             * {
             *  joyDelay2 = false;
             * }
             */



//			if(camSwitch == 572){axis.Text+="Camera B" + "\r\n";}else{axis.Text+="Camera A" + "\r\n";}  //we also want to display these values to help us debug our program.
//			if(altCamSwitch ==572){axis.Text+="Alt A" + "\r\n";}else{ axis.Text+="Alt B" + "\r\n";}	//we also want to display these values to help us debug our program.

            Image img = new Bitmap(cameraDiagram.Width, cameraDiagram.Height);
            CameraVisualizer.DrawVisual(ref img, (camSwitch != 572), (altCamSwitch == 572));
            cameraDiagram.Image = img;



            //camAngle = (int)((2.5)*(camAngle) + 3000);//analyze everything as a joystick input.

            int midPoint = 3040;
            int jumpAmt  = 150; // 10 is slow but easy to control. 25 is a bit faster, much choppier, still easy to control.
            //50 is a nicer speed,just as choppy as 25, same ease of use. 100 seems to match a slider, still choppy though. 150 is perfect. 200 deoesn't give any real improvement.
            //we want to know when a button has been released. after a delay of x, then modify the camera angle, however if the button is released, then restart the count.

            int delay = 1;

//            axis.Text += "counter: " + counter  + "\r\n";  //another value sent out for debugging.
            //axis.Text += "POV: " + hat + "\r\n";  //another value sent out for debugging.
            int hat = pov[0];
            if (hat == -1)
            {
                counter = 0;
            }
            else
            {
                counter++;
            }

            if (counter == delay)
            {
                if (hat == 0)
                {
                    camAngle -= jumpAmt;
                }                                           //controlling a motor with poportional control is difficult without using a proportional input.
                if (hat == 9000)
                {
                    camAngle = midPoint;
                }                                                                                                                               //so we can work out a simple way to use buttons to control.
                if (hat == 18000)
                {
                    camAngle += jumpAmt;
                }
                if (hat == 27000)
                {
                    camAngle = midPoint;
                }

                counter = 0;
            }

            camAngle = Limit_Device(camAngle, camMaxAngle, camMinAngle);  //many of the devices we may use have hardware based max and min values,
            // it is always good practice to ensure that they never get a value outside of their range.
            cameraAngle1.Angle = camAngle;


            int camVal    = (int)((2.5) * (camSwitch) + 3000);       //analyze everything as a joystick input.
            int altCamVal = (int)((2.5) * (altCamSwitch) + 3000);    //analyze everything as a joystick input.

            //camAngle = (int)camBar.Value;



            //the array of Servo objects, is used by the pololu, remember earlier when we mentioned the pololuEnable variable,
            // this is how we would normally set the values for the pololu.
            servo[0] = camAngle;
            servo[1] = camVal;            //battleswitch 1
            servo[2] = altCamVal;         // battleswitch 2
            servo[3] = 3000;              //3000 is the midpoint on the device and corresponds to a neutral position.
            servo[4] = 3000;              //For example, when dealing with motors, this is a stop position.
            servo[5] = 3000;
            servo[6] = 3000;
            servo[7] = 3000;



            //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            //
            //Do not Edit past this point.
            //
            //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

            #region hardcode B


            #region Output
            if (operate.Checked)
            {
                label6.Text      = "On";
                label6.ForeColor = Color.Green;

                HorzPort = (int)func_axis_limit(HorzPort);
                VertPort = (int)func_axis_limit(VertPort);
                VertStar = (int)func_axis_limit(VertStar);
                HorzStar = (int)func_axis_limit(HorzStar);

                plb1.PowerLevel = VertPort;
                plb2.PowerLevel = HorzPort;
                plb3.PowerLevel = HorzStar;
                plb4.PowerLevel = VertStar;

/*
 *                      axis.Text +=  "HorzPort: " + HorzPort + "\r\n";
 *                      axis.Text += "VertPort: " + VertPort + "\r\n";
 *                      axis.Text += "VertStar: " + VertStar + "\r\n";
 *                      axis.Text += "HorzStar: " + HorzStar + "\r\n";
 */
                if (servo1on)
                {
                    try
                    {
                        servo1.servos[0].Position = Limit_Device((int)(((0.052) * (HorzPort)) + 119), Phidget_Max, Phidget_Min); //sets the hardware's pin 0.
                        servo1.servos[1].Position = Limit_Device((int)(((0.052) * (VertPort)) + 119), Phidget_Max, Phidget_Min); //sets the hardware's pin 1.
                        servo1.servos[2].Position = Limit_Device((int)(((0.052) * (VertStar)) + 119), Phidget_Max, Phidget_Min); //sets the hardware's pin 2.
                        servo1.servos[3].Position = Limit_Device((int)(((0.052) * (HorzStar)) + 119), Phidget_Max, Phidget_Min); //sets the hardware's pin 3.
                        //

                        /*
                         * servo1.servos[4].Position = Limit_Device((int)(((0.052) * (HorzPort)) + 119), Phidget_Max, Phidget_Min);//sets the hardware's pin 4.
                         * servo1.servos[5].Position = Limit_Device((int)(((0.052) * (VertPort)) + 119), Phidget_Max, Phidget_Min);//sets the hardware's pin 5.
                         * servo1.servos[6].Position = Limit_Device((int)(((0.052) * (VertStar)) + 119), Phidget_Max, Phidget_Min);//sets the hardware's pin 6.
                         * servo1.servos[7].Position = Limit_Device((int)(((0.052) * (HorzStar)) + 119), Phidget_Max, Phidget_Min);//sets the hardware's pin 7.
                         */
                    }
                    catch (Exception r) {
                    }
                }

                if (pololuEnable)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        int    temp    = Limit_Device(servo[i], Pololu_Max, Pololu_Min);
                        byte[] message = Create_Message(temp, i);
                        if (serialPort1.IsOpen)
                        {
                            serialPort1.Write(message, 0, 6);
                        }
                    }
                }
            }
            else
            {
                label6.Text      = "Off";
                label6.ForeColor = Color.Red;
            }
            #endregion
        }