コード例 #1
0
        /// <summary>
        /// Finch will try to get out of a room
        /// </summary>
        static void Maze()
        {
            DisplayHeader("Running");
            myFinch.wait(1000);
            Console.WriteLine("Trying to get out of the room...");

            int  speed    = 100;
            int  waitTime = 1000;
            bool running  = true;

            while (running)
            {
                myFinch.setLED(255, 255, 255);
                myFinch.setMotors(speed, speed);

                if (myFinch.isObstacleLeftSide())
                {
                    myFinch.setLED(0, 0, 255);
                    myFinch.setMotors(-speed, -speed);
                    myFinch.wait(waitTime);
                    myFinch.setMotors(speed, 0);
                    myFinch.wait(waitTime);
                    myFinch.setLED(255, 255, 255);
                }
                if (myFinch.isObstacleRightSide())
                {
                    myFinch.setLED(255, 0, 0);
                    myFinch.setMotors(-speed, -speed);
                    myFinch.wait(waitTime);
                    myFinch.setMotors(0, speed);
                    myFinch.wait(waitTime);
                    myFinch.setLED(255, 255, 255);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NathanZak321/Finch
        /// <summary>
        /// Talent Show
        /// </summary>
        /// <param name="finchRobot"></param>
        static void DisplayTalentShow(Finch finchRobot)
        {
            DisplayScreenHeader("Talent Show");

            Console.WriteLine("The Finch robot is ready to show you its talent.");
            DisplayContinuePrompt();


            //ENTER MY CODE HERE TO MOVE IT AND STUFF
            finchRobot.setMotors(75, 75);


            finchRobot.isObstacleLeftSide();
            finchRobot.isObstacleRightSide();

            Console.ReadKey(); finchRobot.setMotors(75, 75);


            finchRobot.isObstacleLeftSide();
            finchRobot.isObstacleRightSide();

            Console.ReadKey();

            finchRobot.setMotors(100, 75);


            finchRobot.isObstacleLeftSide();
            finchRobot.isObstacleRightSide();

            Console.ReadKey(); finchRobot.setMotors(100, 75);

            finchRobot.setLED(255, 0, 0);
            finchRobot.wait(9000);
            finchRobot.noteOn(10000);
            finchRobot.wait(1000);
            finchRobot.noteOff();

            finchRobot.setLED(0, 255, 0);
            finchRobot.wait(11000);
            finchRobot.noteOn(7000);
            finchRobot.wait(1500);

            finchRobot.setLED(0, 0, 255);
            finchRobot.wait(12000);
            finchRobot.noteOn(6500);
            finchRobot.wait(500);

            //for (int lightLevel = 0; lightLevel < 255; lightLevel++)
            //{
            //    finchRobot.setLED(234, 132, 0);
            //}

            DisplayContinuePrompt();
        }
コード例 #3
0
        private static void AdvoidLightAndObsticales(Finch alma)
        {
            alma.connect();
            int light;
            int lightThreshold = 8;



            DisplayHeader("Finch flees before the spotlight");
            Console.WriteLine("Finch will Avoid the spotlight (flashlight) for 10 seconds. The Finch will also Avoid  Obsitacls");

            light = alma.getRightLightSensor();

            for (int i = 0; i < 17; i++)
            {
                alma.setMotors(100, 100);
                alma.setLED(0, 255, 0);
                alma.wait(500);

                //
                //avoid light
                //
                if ((lightThreshold + light) < alma.getRightLightSensor())
                {
                    alma.setMotors(255, 0);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                    alma.setMotors(255, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(1500);
                    alma.setMotors(0, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }
                if (alma.isObstacleLeftSide())
                {
                    alma.setMotors(0, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }

                else if (alma.isObstacleRightSide())
                {
                    alma.setMotors(255, 0);
                    alma.setLED(255, 0, 0);
                }
            }
            alma.disConnect();
            DisplayContinuePrompt();
        }
コード例 #4
0
        static void DisplayTimObstacle(string timSide, Finch tim)
        {
            DisplayHeader("Tim Obstacle Detection");

            if (timSide == "left")
            {
                Console.WriteLine($"Obstacle detected in Tims left eye: {tim.isObstacleLeftSide()}");
            }
            else if (timSide == "right")
            {
                Console.WriteLine($"Obstacle detected in Tims right eye: {tim.isObstacleRightSide()}");
            }

            DisplayKeyToContinue();
        }
コード例 #5
0
        private static void advoidobstacles(Finch alma)
        {
            alma.connect();



            DisplayHeader("Finch Avoids Obstacles.");
            Console.WriteLine("Finch will Avoid  objects for 10 seconds. While moving in a straight line");
            for (int i = 0; i < 17; i++)
            {
                //
                //avoid obstiacles
                //
                if (alma.isObstacleLeftSide())
                {
                    alma.setMotors(0, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }

                else if (alma.isObstacleRightSide())
                {
                    alma.setMotors(255, 0);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }
                else
                {
                    alma.setMotors(100, 100);
                    alma.setLED(0, 255, 0);
                    alma.wait(500);

                    DisplayHeader("Finch Avoids Obstacles.");
                    Console.WriteLine("Finch will Avoid  objects for 10 seconds. While moving in a straight line");
                    Console.WriteLine("No Obstacle Found");
                }
            }
            alma.disConnect();
            DisplayContinuePrompt();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            // create Finch
            Finch bot = new Finch();

            bot.connect();

            Console.WriteLine("Start XGamepadApp");
            // Initialize XInput
            var controllers = new[] { new Controller(UserIndex.One), new Controller(UserIndex.Two), new Controller(UserIndex.Three), new Controller(UserIndex.Four) };

            // Get 1st controller available
            Controller controller = null;

            foreach (var selectControler in controllers)
            {
                if (selectControler.IsConnected)
                {
                    controller = selectControler;
                    break;
                }
            }

            if (controller == null)
            {
                Console.WriteLine("No XInput controller installed");
            }
            else
            {
                Console.WriteLine("Found a XInput controller available");

                while (controller.IsConnected)
                {
                    if (IsKeyPressed(ConsoleKey.Escape))
                    {
                        break;
                    }
                    var state    = controller.GetState();
                    var LeftJoyX = state.Gamepad.LeftThumbX;
                    var LeftJoyY = state.Gamepad.LeftThumbY;
                    //Console.WriteLine($"X: {LeftJoyX} Y: {LeftJoyY}");
                    int lmotor = (LeftJoyY / 128) + (LeftJoyX / 128);
                    int rmotor = (LeftJoyY / 128) - (LeftJoyX / 128);
                    bot.setMotors(lmotor, rmotor);
                    if (state.Gamepad.RightThumbY > 0)
                    {
                        bot.noteOn(state.Gamepad.RightThumbY / 20);
                    }
                    if (state.Gamepad.RightThumbY < 0)
                    {
                        bot.noteOn((-(state.Gamepad.RightThumbY)) / 20);
                    }
                    int Red   = 0;
                    int Green = 0;
                    int Blue  = 0;
                    if (state.Gamepad.Buttons == GamepadButtonFlags.B)
                    {
                        Red = Red + 255;
                        Console.WriteLine($"Temperature: {bot.getTemperature()}");
                    }
                    if (state.Gamepad.Buttons == GamepadButtonFlags.A)
                    {
                        Green = Green + 255;
                    }
                    if (state.Gamepad.Buttons == GamepadButtonFlags.X)
                    {
                        Blue = Blue + 255;
                    }
                    if (state.Gamepad.Buttons == GamepadButtonFlags.Y)
                    {
                        Red   = Red + 255;
                        Green = Green + 255;
                        Console.WriteLine($"Light Level: {bot.getLeftLightSensor()}");
                    }
                    bot.setLED(Red, Green, Blue);
                    while (bot.isObstacleLeftSide() || bot.isObstacleRightSide())
                    {
                        bot.setMotors(-255, -255);
                    }
                }
            }
            Console.WriteLine("End XGamepadApp");
            bot.disConnect();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: nslush24/Finch-Sensors
        /// <summary>
        /// Finches Got Talent Application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // **************************************************
            //
            // Title: Finches Got Talent
            // Description: Sensors
            // Application Type: Console
            // Author: Nate Schlusler
            // Dated Created: 2/7/2018
            // Last Modified:
            //
            // **************************************************

            // variables
            bool   isConnected;
            double finchTemp;
            int    rightLightSensor;
            int    leftLightSensor;
            bool   rightObstacle;



            // create (instantiate) a new finch object
            //
            Finch myFinch = new Finch();

            //
            // connect to the finch robot using the finch connnect method
            //
            isConnected = myFinch.connect();
            if (isConnected)
            {
                Console.WriteLine("Finch is connected.");
            }
            else
            {
                Console.WriteLine("Finch is broke.");
            }
            Console.WriteLine();

            // describe app
            Console.WriteLine("Demo of Finch Sensors");
            Console.WriteLine();

            // pause for user
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
            Console.Clear();



            // application loop
            rightObstacle = false;
            while (!rightObstacle)
            {
                // get temperature
                finchTemp = myFinch.getTemperature();
                Console.WriteLine($"Current Temperature: {finchTemp} celsius.");

                // get light sensor value
                leftLightSensor  = myFinch.getLeftLightSensor();
                rightLightSensor = myFinch.getRightLightSensor();
                Console.WriteLine();
                Console.WriteLine($"Current Left Light Sensor: {leftLightSensor}");
                Console.WriteLine($"Current Right Light Sensor: {rightLightSensor}");
                Console.WriteLine($"Current Average Light Sensor: {((leftLightSensor) + (rightLightSensor)) / 2}");
                Console.WriteLine();

                // check right obstacle

                rightObstacle = myFinch.isObstacleRightSide();
                if (rightObstacle)
                {
                    Console.WriteLine("Right obstacle detected!");
                }

                myFinch.wait(1000);
                Console.Clear();
            }



            // pause for user
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();


            //
            // end application code here
            //

            //
            // disconnect from the finch robot using the finch disconnect method
            //
            myFinch.disConnect();
        }