Esempio n. 1
0
        // ----------------- Tick method -----------------
        /// <summary> Make a tick with robot brain.</summary>
        public void updateRobot()
        {
            if (currentStrategy != null)
            {
                currentStrategy.calculateNextMove(position, speed, heading, neighbors, out referenceSpeed, out referenceHeading);
            }
            else
            {
                setStrategy(new StandStill());
            }

            // Run collision avoidance code to check if robot is blocked.
            blocked = false;
            blocked = isBlocked();

            if (blocked)
            {
                //setMotorSignals(new int[2] { 0, 0 }); //uncomment if using m3pi robots

                //$$$$$Changes/Additions for RC car$$$$$//
                setMotorSignals(new int[2] {
                    Program.neutralSpeed, motorSignals[1]
                });
                if (neighbors[0].getID() != 0) //The updateRobot() function is called separately for each robot; therefore a new obstacle avoidance strategy needs to be set only for glyph 0.
                {
                    if (!blocktime)            //The first time obstacle is detected, calculate the final point until which obstacle avoidance strategy needs to be valid.
                    {
                        finalPositionX = 2 * neighbors[0].getPosition().X - position.X;
                        finalPositionY = 2 * neighbors[0].getPosition().Y - position.Y;
                        blocktime      = true;
                    }
                    int         nrPointsObsAvoid = 15;
                    DoublePoint positionObst     = neighbors[0].getPosition();

                    if (Math.Abs(finalPositionX - position.X) > 300 || Math.Abs(finalPositionY - position.Y) > 300)
                    {
                        setStrategy(new FollowPath("Avoid Obstacle", FollowPath.createEllipsePoints(200, 100, positionObst, nrPointsObsAvoid)));   //obstacle avoidance path.
                    }
                    else
                    {
                        currentStrategy = Program.strategyList.ElementAt(Program.activeStrategyId);     //After completing half-circle, the robot should continue on it's previous path as set in GUI.
                    }
                }
                else
                {
                    setStrategy(new StandStill());    //For the obstacle, keep the strategy as StandStill.
                }
                //$$$$$$$$$$//
            }
            //else  //uncomment if using m3pi robots
            //{ //uncomment if using m3pi robots
            //  setMotorSignals(controller(speed, heading, referenceSpeed, referenceHeading));    //uncomment if using m3pi robots
            setMotorSignals(controller(speed, heading, referenceHeading));

            //} //uncomment if using m3pi robots
        }