コード例 #1
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            int speedA, speedB, time;

            try
            {
                speedA = Convert.ToInt32(textBoxSpeedMotorA.Text);
                speedB = Convert.ToInt32(textBoxSpeedMotorB.Text);
                time   = Convert.ToInt32(textBoxMotorTime.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }
            if (speedA > MaxSpeed || speedA < MinSpeed)
            {
                MessageBox.Show("Please check your input - motor A!");
                return;
            }
            if (speedB > MaxSpeed || speedB < MinSpeed)
            {
                MessageBox.Show("Please check your input - motor B!");
                return;
            }
            if (time < 0)
            {
                MessageBox.Show("Please check your input - time!");
                return;
            }
            MotorDirection dirA = (MotorDirection)comboBoxMotorA.SelectedIndex;
            MotorDirection dirB = (MotorDirection)comboBoxMotorB.SelectedIndex;

            Arduino.GetInstance().Send(dirA, speedA, dirB, speedB, time);
        }
コード例 #2
0
        private void buttonSample_Click(object sender, EventArgs e)
        {
            Image <Rgb, Byte> rawImage;
            string            tempPath = VideoSourceDevice.GetCurrentPicturePath();

            try
            {
                rawImage = new Image <Rgb, byte>(tempPath);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return;
            }

            double[] threshold1 = new double[]
            {
                200
            };
            double[] threshold2 = new double[]
            {
                200, 300, 400
            };
            CannyTextureAnalysisResult textureAnalysisResult = Cv.AutoCannyTextureAnalysis(rawImage, threshold1, threshold2, 0);
            float diff = textureAnalysisResult.Diff;

            /*
             * ZedGraphForm tempGraphForm = new ZedGraphForm(textureAnalysisResult.Data);
             * tempGraphForm.Show();
             */
            Debug.ShowImg(textureAnalysisResult.Img);

            textBoxConsole.AppendText("Center: " + textureAnalysisResult.Center + Environment.NewLine);

            // if center is close to 0.5, it means the car direction is nearly towards the path.
            float threadhold = 0.05f;

            if (Math.Abs(diff) > threadhold)
            {
                if (diff > threadhold)
                {
                    if (_previousDiff < -threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 35, MotorDirection.Backward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Backward, 75, 200);
                    }
                }
                else if (diff < -threadhold)
                {
                    if (_previousDiff > threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 35, MotorDirection.Forward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 75, MotorDirection.Forward, 75, 200);
                    }
                }
            }
            else
            {
                Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Forward, 75, 200);
            }
            _previousDiff = diff;
        }
コード例 #3
0
        private static void G1T1Loop()
        {
            Image <Rgb, Byte> rawImage;
            string            tempPath = VideoSourceDevice.GetCurrentPicturePath();

            try
            {
                rawImage = new Image <Rgb, byte>(tempPath);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return;
            }

            double[] threshold1 = new double[]
            {
                200
            };
            double[] threshold2 = new double[]
            {
                200, 300, 400
            };
            CannyTextureAnalysisResult textureAnalysisResult = Cv.AutoCannyTextureAnalysis(rawImage, threshold1, threshold2, 0);
            float center = textureAnalysisResult.Center;
            float diff   = textureAnalysisResult.Diff;

            // if center is close to 0.5, it means the car direction is nearly towards the path.
            float threadhold = 0.02f;

            if (Math.Abs(diff) > threadhold)
            {
                if (diff > threadhold)
                {
                    if (_previousDiff < -threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 35, MotorDirection.Backward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Backward, 75, 200);
                    }
                }
                else if (diff < -threadhold)
                {
                    if (_previousDiff > threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 35, MotorDirection.Forward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 75, MotorDirection.Forward, 75, 200);
                    }
                }
            }
            else
            {
                Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Forward, 75, 200);
            }
            _previousDiff = diff;
        }