void Awake()
    {
        _groundCheck = transform.Find("GroundCheck");
        _anim = GetComponent<Animator>();

        _robotState = new WalkState(this);
    }
Exemplo n.º 2
0
        public bool Connect()
        {
            if (State != RobotState.Disconnected) throw new InvalidOperationException("The state should be Disconnected.");

            foreach (var component in Components)
                component.Connect();

            State = RobotState.Connected;
            return true;
        }
Exemplo n.º 3
0
        public RobotCommandMessage(int robotID, RobotCommandType type, List<Vector2> waypoints, RobotTwoWheelCommand directCmd,
			double angleWhenDone, RobotState.RobotMode mode)
        {
            this.robotID = robotID;
            Type = type;
            Waypoints = waypoints;
            DirectCmd = directCmd;
            AngleWhenDone = angleWhenDone;
            Mode = mode;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SLAM.Robot"/> class with the
 /// default settings for the Pirate robot platform.
 /// </summary>
 public Robot()
 {
     x = 0;
     y = 0;
     heading = 0;
     originalRotation = double.MaxValue;
     state = RobotState.Halted;
     width = 0.18;
     height = 0.23;
     mouseCpi = 800;
 }
Exemplo n.º 5
0
        public const float d = 5f; // offset used to move along the bing bang wall

        #endregion Fields

        #region Methods

        public static bool checkCollision(Map map, RobotState state, RobotState dest)
        {
            float radius = ((R2D2State)state).ScreenRadius;
            foreach (Obstacle obs in map) {
                Obstacle ob = obs.createExpandedObstacle(Constants.BING_BANG_OBSTACLE_PROXIMITY_MULT * radius);
                if (CollisionDetection.lineSegmentPolyIntersect(state.X, state.Y, dest.X, dest.Y, (BShape_Poly)ob))
                {
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SLAM.Robot"/> class.
        /// </summary>
        /// <param name="xPosition">X position in meters.</param>
        /// <param name="yPosition">Y position in meters.</param>
        /// <param name="currentRotation">Current rotation in radians.</param>
        /// <param name="currentState">Current state <see cref="SLAM.RobotState"/>.</param>
        /// <param name="robotWidth">Robot width in meters.</param>
        /// <param name="robotHeight">Robot height in meters.</param>
        public Robot(double xPosition, double yPosition, double currentRotation, RobotState currentState,
		              double robotWidth, double robotHeight, double cpi)
        {
            x = xPosition;
            y = yPosition;
            heading = currentRotation;
            originalRotation = heading;
            state = currentState;
            width = robotWidth;
            height = robotHeight;
            mouseCpi = cpi;
        }
Exemplo n.º 7
0
        private void PlayRequest()
        {
            RobotState    state       = GlobalVariables.CurrentRobotState;
            RemoteRequest playRequest = null;

            if (state.MusicState == RobotState.MusicStates.MusicIdled)
            {
                playRequest = state.MotionID > 2
                                  ? new RemoteRequest(RobotPacket.PacketID.SelectMotionToPlay, -1, state.MotionID)
                                  : new RemoteRequest(RobotPacket.PacketID.SelectMotionToPlay, -1,
                                                      GlobalVariables.CurrentListMotion[0].MotionID);
            }
            else
            {
                playRequest = new RemoteRequest(RobotPacket.PacketID.Play);
            }
            playRequest.ProcessSuccessfully += (data) =>
            {
                ViewModel.StateButton = PlayPauseButtonModel.ButtonState.Pause;
                Dispatcher.BeginInvoke((Action)GetState);
            };
            playRequest.ProcessError += (errorCode, msg) =>
            {
                Dispatcher.BeginInvoke((Action) delegate
                {
                    Cursor = Cursors.Arrow;
                    switch (errorCode)
                    {
                    case RobotRequest.ErrorCode.SetupConnection:
                    case RobotRequest.ErrorCode.WrongSessionID:
                        OnUpdateParentControl("MustReconnect");
                        break;
                    }
                });
                Debug.Fail(msg, Enum.GetName(typeof(RobotRequest.ErrorCode), errorCode));
            };
            GlobalVariables.RobotWorker.AddJob(playRequest);
        }
Exemplo n.º 8
0
    private void onBeatStarted(Signal signal)
    {
        BeatStartedSignal beatStartedSignal = (BeatStartedSignal)signal;

        Debug.Assert(beatStartedSignal.BeatType == BeatType.BOARD_MOVE, "Wrong BeatType during robot turn left state.  Turn left State expects to be ended by BOARD_MOVE beat");
        switch (robot.currentHeading)
        {
        case Heading.NORTH:
            robot.currentHeading = Heading.EAST;
            break;

        case Heading.EAST:
            robot.currentHeading = Heading.SOUTH;
            break;

        case Heading.SOUTH:
            robot.currentHeading = Heading.WEST;
            break;

        case Heading.WEST:
            robot.currentHeading = Heading.NORTH;
            break;

        default:
            Debug.Assert(false, "Unknown heading: " + robot.currentHeading.ToString());
            break;
        }
        Tile newTile = TileGrid.Inst.GetTileAt(robot.currentX, robot.currentZ);

        if (newTile.GetType() == typeof(TurnLeftTile))
        {
            nextState = new RobotLeftTurnTableState(robot);
        }
        else
        {
            nextState = new RobotIdleState(robot);
        }
    }
Exemplo n.º 9
0
        /// <summary>
        /// Move the Motors for a given amount of time then break.
        /// </summary>
        /// <param name="rightSpeed">Speed of the right wheel</param>
        /// <param name="leftSpeed">Speed of the left wheel</param>
        /// <param name="ms">Duration in miliseconds</param>
        private void MoveTimeInternal(int rightSpeed, int leftSpeed, long ms)
        {
            CancellationToken moveToken = restartMove();
            Stopwatch         sw        = new Stopwatch();

            ResetEncoders();
            CurrentState = RobotState.Moving;
            SetWheels(rightSpeed, leftSpeed);
            sw.Start();
            while (sw.ElapsedMilliseconds < ms)
            {
                // action overriden by another move command
                if (moveToken.IsCancellationRequested)
                {
                    return;
                }

                //Action ends
                if (token.IsCancellationRequested)
                {
                    break;
                }
                if (BumperLeft || BumperRight)
                {
                    break;
                }

                if (rightSpeed == leftSpeed)
                {
                    // Straight line course correction should only run when a straight line is actually desired.
                    CourseCorrect(rightSpeed, leftSpeed);
                }
            }
            Debug.WriteLineIf(BumperLeft || BumperRight, "Bumper finish!");
            Debug.WriteLine("Exited at: {0}", sw.ElapsedMilliseconds);
            SetWheels();
            OnMovementStop();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 初始化登录
        /// </summary>
        private void init()
        {
            if (string.IsNullOrEmpty(config_url))
            {
                state = RobotState.Wait;
                onLoginMessage?.Invoke(this, "初始化失败");
                return;
            }
            data.RegPtwebqq(config_url);
            //第二步
            var result = data.GetVfwebqq(Ptwebqq);

            if (result == null)
            {
                state = RobotState.Wait; return;
            }
            Vfwebqq = result.vfwebqq;
            //第三步 获取uin和psessionid
            var login2 = data.UinAndPsessionid(new { ptwebqq = Ptwebqq, clientid = ClientId, psessionid = "", status = "online" });

            if (login2 == null)
            {
                state = RobotState.Wait; return;
            }
            Psessionid = login2.psessionid;
            uin        = login2.uin;
            //登录完成
            state  = RobotState.PollMessage;
            status = RobotStatus.online;
            //获取最近对话

            //获取好友

            //获取qq群

            //保存
            save();
        }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        GameObject currentTarget = (GameObject)ai.GetVariable("CurrentTarget").GetValue();

        if (stunTimer > 0)
        {
            state = RobotState.STUNNED;
            animator.SetTrigger("AimDownTrigger");
        }
        else
        {
            if (currentTarget != null)
            {
                if (Vector3.Distance(currentTarget.transform.position, transform.position) < attackDistance)
                {
                    state = RobotState.ATTACKING;
                    animator.SetTrigger("AimUpTrigger");
                }
                else
                {
                    state = RobotState.CHASING;
                    animator.SetTrigger("WalkTrigger");
                }
            }
            else
            {
                state = RobotState.PATROLING;
                animator.SetTrigger("WalkTrigger");
            }
        }

        stunTimer = Mathf.Clamp(stunTimer - Time.deltaTime, 0, stunTime);

        if (stunTimer <= 0 && !aiEnabled)
        {
            EnableAI();
        }
    }
Exemplo n.º 12
0
        private void MoveTo(int robotId, RoundConfig config, GameState state, RobotAction action, int X, int Y)
        {
            RobotState self = state.robots[robotId];

            int max_distance = 10 * config.max_speed * self.speed / config.max_health * self.energy / config.max_energy;
            int distance     = CalcDistance(self.X, self.Y, X, Y);

            if (distance <= max_distance)
            {
                action.dX = X - self.X;
                action.dY = Y - self.Y;
            }
            else
            {
                if (max_distance == 0)
                {
                    max_distance = 1;
                }
                int num_steps = distance / max_distance + 1;
                action.dX = (X - self.X) / num_steps;
                action.dY = (Y - self.Y) / num_steps;
            }
        }
Exemplo n.º 13
0
        private Point GetNearestStation(int robotId, RoundConfig config, GameState state, PointType type)
        {
            RobotState self = state.robots[robotId];

            int pointDistance = config.width * config.height;
            int pointId       = 0;

            for (int id = 0; id < state.points.Count; id++)
            {
                Point pt = state.points[id];
                if (pt.type == type)
                {
                    int ptDistance = CalcDistance(self.X, self.Y, pt.X, pt.Y);
                    if (ptDistance < pointDistance)
                    {
                        pointDistance = ptDistance;
                        pointId       = id;
                    }
                }
            }

            return(state.points[pointId]);
        }
Exemplo n.º 14
0
 public Robot(Texture2D t, MainGame game, World w)
     : base(w)
 {
     timeCounter = 0.0f;
     texture     = t;
     parent      = game;
     Health      = 100;
     state       = RobotState.IDLE;
     direction   = PlayerDirection.RIGHT;
     //frameCounter = 0;
     //frameRate = 1.0f / 24.0f;
     srcRect  = new Rectangle(0, 0, width, height);
     destRect = new Rectangle((int)Position.X, (int)Position.Y, 50, 50);
     myWorld  = w;
     lastFire = -1.0;
     fireRate = 1000;
     this.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(ConvertUnits.ToSimUnits(width / 2), ConvertUnits.ToSimUnits(height / 2)), 1.0f));
     this.BodyType         = BodyType.Dynamic;
     this.Restitution      = 0.3f;
     this.Friction         = 1.0f;
     this.IgnoreGravity    = true;
     this.MarkedForRemoval = false;
 }
Exemplo n.º 15
0
        int getTargetWithCondition(RoundConfig round_config, RobotState self, GameState state)
        {
            int Person_Id        = -1;
            int minimal_distance = 100;

            foreach (RobotState robot in state.robots)
            {
                int distance_to_enemy = distanceToEnemy(self, robot.X, robot.Y);
                if (distance_to_enemy <= minimal_distance && robot.id != self.id)
                {
                    int max_power = self.attack * self.energy / round_config.max_energy;

                    int max_target_defence = (int)Math.Round((float)robot.defence * (float)robot.energy / (float)round_config.max_energy);

                    if (max_target_defence <= max_power)
                    {
                        Person_Id        = robot.id;
                        minimal_distance = distance_to_enemy;
                    }
                }
            }
            return(Person_Id);
        }
Exemplo n.º 16
0
        public void HealthExchange(RobotState self, RoundConfig config, RobotAction action, float attack, float defence, float speed)
        {
            int health = self.attack + self.defence + self.speed;

            action.dA = (int)((attack - self.attack / (float)health) * (config.dHealth - 3));
            action.dD = (int)((defence - self.defence / (float)health) * (config.dHealth - 3));
            action.dV = (int)((speed - self.speed / (float)health) * (config.dHealth - 3));

            if (self.speed + action.dV > config.max_speed)
            {
                int delta = action.dV - (config.max_speed - self.speed);
                action.dA += delta / 2;
                action.dD += delta / 2;
                action.dV -= delta;
            }

            int sum = action.dA + action.dD + action.dV;

            if (sum != 0)
            {
                action.dV -= sum;
            }
        }
Exemplo n.º 17
0
    public RobotState UpdateTaskState(float _deltaTime, bool _proceed)
    {
        if (actionsInTask.Count > 0)
        {
            currentAction = actionsInTask.Peek();

            if (currentAction.actionComplete)
            {
                actionsInTask.Dequeue();
                currentAction = actionsInTask.Peek();
            }

            currentAction.UpdateRobotState(Time.deltaTime, _proceed);
            stateUpdate = currentAction.currentState;
        }

        else
        {
            taskComplete = true;
        }

        return(stateUpdate);
    }
Exemplo n.º 18
0
        // ReSharper restore InconsistentNaming

        public Warlock(CommandManager commandManager, WaypointManager waypointManager, ILogger logger)
        {
            _commandManager  = commandManager;
            _waypointManager = waypointManager;
            _logger          = logger;

            SummonPet        = new SummonPet(SummonImp);
            CastDrink        = new CastDrink(Drink);
            _targetManager   = new TargetManager();
            _lootManager     = new LootManager(_logger);
            _skinningManager = new SkinningManager(_logger);

            CastPetAttack    = new PetAttack();
            CastShadowBolt   = new CastOffensiveSpell(ShadowBolt);
            CastDemonSkin    = new CastBuff(DemonSkin);
            CastCorruption   = new CastDebuff(Corruption);
            CastCurseOfAgony = new CastDebuff(CurseOfAgony);
            CastImmolate     = new CastDebuff(Immolate);
            CastWand         = new CastWand(Wand);

            _state    = RobotState.Passive;
            _lootList = new List <IWowObject>();
        }
Exemplo n.º 19
0
        public static void UpdateRobotStatus(string name, string status)
        {
            Form manual = Application.OpenForms["FormManual"];

            if (manual == null)
            {
                return;
            }

            if (manual.InvokeRequired)
            {
                UpdateRobotStatus_D ph = new UpdateRobotStatus_D(UpdateRobotStatus);
                manual.BeginInvoke(ph, name, status);
            }
            else
            {
                StateUtil.Init();
                RobotState robot = StateUtil.GetDeviceState(name) != null ? (RobotState)StateUtil.GetDeviceState(name) : null;
                if (robot == null)
                {
                    return;
                }
                //update robot status
                TextBox tbRStatus = manual.Controls.Find("tbRStatus", true).FirstOrDefault() as TextBox;
                tbRStatus.Text = status;
                switch (status)
                {
                case "RUN":
                    tbRStatus.BackColor = Color.Lime;
                    break;

                case "IDLE":
                    tbRStatus.BackColor = Color.Yellow;
                    break;
                }
            }
        }
Exemplo n.º 20
0
        private Coord GetCoordXYStepToPoint(Point p, RobotState robot, decimal maxStep)
        {
            Coord   coord = new Coord();
            decimal dist  = GetDistance(p.X, p.Y, robot.X, robot.Y);

            if (dist == 0)
            {
                return(coord);
            }

            decimal sinA = (p.X - robot.X) / dist;
            decimal cosA = (p.Y - robot.Y) / dist;

            coord.X = (int)(sinA * maxStep);
            coord.Y = (int)(cosA * maxStep);

            if (coord.X == 0 && coord.Y == 0)
            {
                if (Math.Abs(sinA) < 0.5m)
                {
                    coord.Y = 1 * (int)(cosA * 1000 / Math.Abs(cosA * 1000));
                    coord.X = 0;
                }
                else if (Math.Abs(sinA) >= 0.85m)
                {
                    coord.Y = 0;
                    coord.X = 1 * (int)(sinA * 1000 / Math.Abs(sinA * 1000));
                }
                else
                {
                    coord.Y = 1 * (int)(cosA * 1000 / Math.Abs(cosA * 1000));
                    coord.X = 1 * (int)(sinA * 1000 / Math.Abs(sinA * 1000));
                }
            }

            return(coord);
        }
Exemplo n.º 21
0
        private int GetNearestRobot(int robotId, RoundConfig config, GameState state)
        {
            RobotState self = state.robots[robotId];

            int targetDistance = config.width * config.height;
            int targetId       = -1;

            for (int id = 0; id < state.robots.Count; id++)
            {
                RobotState rs = state.robots[id];

                if (rs.name != self.name && rs.isAlive)
                {
                    int rsDistance = CalcDistance(self.X, self.Y, rs.X, rs.Y);
                    if (rsDistance < targetDistance)
                    {
                        targetDistance = rsDistance;
                        targetId       = id;
                    }
                }
            }

            return(targetId);
        }
Exemplo n.º 22
0
        public void SetState(RobotState state)
        {
            currentState = state;
            switch (state)
            {
            case RobotState.Sleeping:
                Agent.speed            = 0f;
                NavMeshFollower.Target = null;
                break;

            case RobotState.GoToWork:
                NavMeshFollower.Target = Work;
                Agent.speed            = 3;
                break;

            case RobotState.GoHome:
                NavMeshFollower.Target = Home;
                Agent.speed            = 6f;
                break;

            default:
                throw new ArgumentOutOfRangeException("state", state, null);
            }
        }
Exemplo n.º 23
0
        public RobotAction Tick(int robotId, RoundConfig config, GameState state)
        {
            RobotState  self   = state.robots[robotId];
            RobotAction action = new RobotAction();
            int         health = self.attack + self.defence + self.speed;
            coord       healt  = findOutNearStatOfCharge(PointType.Health, self, state);
            coord       energy = findOutNearStatOfCharge(PointType.Energy, self, state);
            coord       move   = new coord();

            action.targetId = -1;
            if (self.attack > 30)
            {
                action.dA = -10;
                action.dD = 10;
                action.dV = 0;
            }
            if (self.attack >= 0)
            {
                action.targetId = getTargetWithCondition(config, self, state);
            }
            if (self.defence < 20)
            {
                HealthRedestribution(self, config, action, self.attack, self.defence, self.speed);
            }
            if (health < 50)
            {
                move = Movement(config, healt, self, state);
            }
            else
            {
                move = Movement(config, energy, self, state);
            }
            action.dX = move.x;
            action.dY = move.y;
            return(action);
        }
Exemplo n.º 24
0
    public void SetTarget(Waypoint targetWP, bool isConfused = false)
    {
        PlaySound((isConfused)?  Speech.I_AM_CONFUSED : Speech.BEFEHL_ERHALTEN);

        if (null != confusedSystem)
        {
            confusedSystem.SetActive(isConfused);
        }

        bool isTargetDamage = (targetWP.GetComponent <DamagePoint>() != null);

        state = (isConfused) ? RobotState.MOVE_TO_DESTROY : (isTargetDamage) ? RobotState.MOVE_TO_DAMAGE : RobotState.MOVE_TO_CONTAINER;

        goal = targetWP;

        Movement move = GetComponent <Movement>();

        if (null != move)
        {
            move.setTargetWaypoint(targetWP);
        }

        SetAnimState(AnimState.MOVE);
    }
Exemplo n.º 25
0
    void HandleExitDropper(bool isRight)
    {
        DropPointLogic dropper = _door.GetComponent <DoorRobotInteraction>().dropper;
        PointsDrop     use     = PointsDrop.EXITCORRECT;

        if (isRight)
        {
            use = PointsDrop.EXITCORRECT;
            _rm.Move(dropper.GetPoint(use));
        }
        else
        {
            use = PointsDrop.EXITINCORRECT;
            _rm.Move(dropper.GetPoint(use));
        }



        if (_rm.IsHeNearInstance(dropper.GetPoint(use)))
        {
            _door         = null;
            _currentState = RobotState.SEARCH;
        }
    }
Exemplo n.º 26
0
    void UpdateDodging()
    {
        oldVelo = newVelo;
        newVelo = rb.velocity;
        curDodgeDis += (transform.position - preDodgePos).magnitude;
        preDodgePos = transform.position;
        float factor = 1.0f - (curDodgeDis / dodgeDis);
        if (factor < endDodgeThresHold) {
            state = RobotState.idle;
            return;
        }
        Vector3 curVelo = transform.TransformDirection(dodgeDir).normalized * beginDodgingVelocity * Time.deltaTime * factor;
        rb.velocity = curVelo;

        if (focus) {
            Vector3 lookDir = transform.forward;
            lookDir.y = 0;
            lookDir.Normalize();
            Vector3 targetDir = (focus.position - transform.position).normalized;
            targetDir.y = 0;
            lookDir.Normalize();
            Vector3 curDir = Vector3.Lerp(lookDir, targetDir, followFocusSpeed);
            curDir.y = 0;
            curDir.Normalize();
            transform.LookAt(transform.position + curDir);
        }
    }
Exemplo n.º 27
0
 void Detaching()
 {
     if (InputProxy.Instance.GetAttach ()) {
         BroadcastMessage ("Attach");
         SoundManager.Instance.sfxPlay(SFXType.ROBOT_CONNECT);
         GameController.Instance.ma.targetActive = true;
         rb.constraints = RigidbodyConstraints.FreezeRotation;
         if (health <= detachThreshold) {
             health += attachRecovery;
             if (health > 100.0f) {
                 health = 100.0f;
             }
         }
         state = RobotState.idle;
     } else {
         if (health <= detachThreshold) {
             health -= healthDropRate * Time.deltaTime;
             if (health <= 0) {
                 state = RobotState.dead;
                 GameController.Instance.GameEnding(false);
                 health = 0;
             }
         }
     }
 }
Exemplo n.º 28
0
        public Conductor()
        {
            RobotState initState = new RobotState();

            leftHorizontalEye = f_leftHorizontalEye = initState.leftHorizontalEye;
            leftVerticalEye = f_leftVerticalEye = initState.leftVerticalEye;
            rightHorizontalEye = f_rightHorizontalEye = initState.rightHorizontalEye;
            rightVerticalEye = f_rightVerticalEye = initState.rightVerticalEye;
            leftEyebrow = f_leftEyebrow = initState.leftEyebrow;
            rightEyebrow = f_rightEyebrow = initState.rightEyebrow;
            rightEyelid = f_rightEyelid = initState.rightEyelid;
            leftEyelid = f_leftEyelid = initState.leftEyelid;
            leftLip = f_leftLip = initState.leftLip;
            rightLip = f_rightLip = initState.rightLip;
            jaw = f_jaw = initState.jaw;
            neckTilt = f_neckTilt = initState.neckTilt;
            neckTwist = f_neckTwist = initState.neckTwist;

            Thread thread = new Thread(new ThreadStart(WorkThreadFunction));
            thread.Start();

            lastState.leftEyebrow = 2;
            lastState.leftEyelid = 2;
            lastState.leftLip = 2;
            lastState.leftHorizontalEye = 2;
            lastState.leftVerticalEye = 2;
            lastState.jaw = 2;
            lastState.neckTilt = 2;
            lastState.neckTwist = 2;
            lastState.position = 2;
            lastState.rightEyebrow = 2;
            lastState.rightEyelid = 2;
            lastState.rightLip = 2;
            lastState.rightHorizontalEye = 2;
            lastState.rightVerticalEye = 2;
            lastState.triggerPosition = 2;
        }
Exemplo n.º 29
0
        public void TestSequenceOfCommands()
        {
            var robot = new RobotState();

            var commands = new (int, int) [] {
Exemplo n.º 30
0
        public void GoFoward()
        {
            char[] command = { 'w', '\n' };
            SerialProxy.GetInstance.Send (command);

            state = RobotState.MovingForward;
        }
Exemplo n.º 31
0
 /// <summary>
 ///     Default constructor
 /// </summary>
 /// <param name="state">current state of the robot passed to the event</param>
 public RobotStatusChangedEventArgs(RobotState state)
 {
     CurrentRobotState = state;
 }
Exemplo n.º 32
0
        private bool IsStateVisible(RobotState state)
        {
            bool R = false;
            bool G = false;
            bool B = false;

            // determine edit point color based on feature changes
            if ((state.leftHorizontalEye != -1)||(state.leftVerticalEye != -1)) R = true;
            if ((state.rightHorizontalEye != -1)||(state.rightVerticalEye != -1)) R = true;
            if ((state.leftEyebrow != -1)||(state.rightEyebrow != -1)) R = true;
            if ((state.rightEyelid != -1)||(state.leftEyelid != -1)) R = true;

            if (state.leftLip != -1) G = true;
            if (state.rightLip != -1) G = true;
            if (state.jaw != -1) G = true;

            if (state.neckTilt != -1) B = true;
            if (state.neckTwist != -1) B = true;

            if ((!showEyes) && (R) && (!G) && (!B)) return false;
            if ((!showMouth) && (G) && (!R) && (!B)) return false;
            if ((!showNeck) && (B) && (!R) && (!G)) return false;

            if ((!showMouth) && (!showEyes) && (R) && (G) && (!B)) return false;
            if ((!showNeck) && (!showEyes) && (R) && (B) && (!G)) return false;
            if ((!showMouth) && (!showNeck) && (B) && (G) && (!R)) return false;

            return true;
        }
Exemplo n.º 33
0
 public void EndSkill()
 {
     state = RobotState.idle;
 }
Exemplo n.º 34
0
        public void Scan()
        {
            char[] command = { 'e', '\n' };
            SerialProxy.GetInstance.Send (command);

            state = RobotState.Scanning;
        }
Exemplo n.º 35
0
        public void RotateRight()
        {
            char[] command = { 'd', '\n' };
            SerialProxy.GetInstance.Send (command);

            state = RobotState.RotatingRight;
        }
Exemplo n.º 36
0
        public void RotateLeft()
        {
            char[] command = { 'a', '\n' };
            SerialProxy.GetInstance.Send (command);

            state = RobotState.RotatingLeft;
        }
Exemplo n.º 37
0
        public void Reset()
        {
            char[] command = { 'z', '\n' };
            SerialProxy.GetInstance.Send (command);

            state = RobotState.Resetting;
        }
Exemplo n.º 38
0
        public void Halt()
        {
            char[] command = { 'q', '\n' };
            SerialProxy.GetInstance.Send (command);

            state = RobotState.Halted;
        }
Exemplo n.º 39
0
        public void SetAbsoluteState(RobotState curr, int stop)
        {
            RobotState last = new RobotState();
            // determine values up to this edit point
            int i;
            for (i = 0; i < stop; i++)
                UpdateState(last, editPoints[i]);

            if (curr.leftHorizontalEye == -1) curr.leftHorizontalEye = last.leftHorizontalEye;
            if (curr.leftVerticalEye == -1) curr.leftVerticalEye = last.leftVerticalEye;
            if (curr.rightHorizontalEye == -1) curr.rightHorizontalEye = last.rightHorizontalEye;
            if (curr.rightVerticalEye == -1) curr.rightVerticalEye = last.rightVerticalEye;
            if (curr.leftEyebrow == -1) curr.leftEyebrow = last.leftEyebrow;
            if (curr.rightEyebrow == -1) curr.rightEyebrow = last.rightEyebrow;
            if (curr.rightEyelid == -1) curr.rightEyelid = last.rightEyelid;
            if (curr.leftEyelid == -1) curr.leftEyelid = last.leftEyelid;
            if (curr.leftLip == -1) curr.leftLip = last.leftLip;
            if (curr.rightLip == -1) curr.rightLip = last.rightLip;
            if (curr.jaw == -1) curr.jaw = last.jaw;
            if (curr.neckTilt == -1) curr.neckTilt = last.neckTilt;
            if (curr.neckTwist == -1) curr.neckTwist = last.neckTwist;
        }
Exemplo n.º 40
0
        public void SetRelativeState(RobotState curr, int stop)
        {
            RobotState last = new RobotState();
            // determine values up to this edit point
            int i;
            if (stop>editPoints.Count) stop = editPoints.Count;
            for (i = 0; i < stop; i++)
                UpdateState(last, editPoints[i]);

            if (last.leftHorizontalEye == curr.leftHorizontalEye) curr.leftHorizontalEye = -1;
            if (last.leftVerticalEye == curr.leftVerticalEye) curr.leftVerticalEye = -1;
            if (last.rightHorizontalEye == curr.rightHorizontalEye) curr.rightHorizontalEye = -1;
            if (last.rightVerticalEye == curr.rightVerticalEye) curr.rightVerticalEye = -1;
            if (last.leftEyebrow == curr.leftEyebrow) curr.leftEyebrow = -1;
            if (last.rightEyebrow == curr.rightEyebrow) curr.rightEyebrow = -1;
            if (last.rightEyelid == curr.rightEyelid) curr.rightEyelid = -1;
            if (last.leftEyelid == curr.leftEyelid) curr.leftEyelid = -1;
            if (last.leftLip == curr.leftLip) curr.leftLip = -1;
            if (last.rightLip == curr.rightLip) curr.rightLip = -1;
            if (last.jaw == curr.jaw) curr.jaw = -1;
            if (last.neckTilt == curr.neckTilt) curr.neckTilt = -1;
            if (last.neckTwist == curr.neckTwist) curr.neckTwist = -1;
        }
Exemplo n.º 41
0
 /// <summary>
 /// Sets the state.
 /// </summary>
 /// <param name="state">State.</param>
 public void SetState(RobotState state)
 {
     _currentState = state;
 }
Exemplo n.º 42
0
 void OnNextRobot(RobotState robotState)
 {
     score.AddToScore(100);
 }
Exemplo n.º 43
0
 /// <summary>
 ///     Method used to change the robot state and fire respective events
 /// </summary>
 /// <param name="state">the robot state</param>
 public void NotifyState(RobotState state)
 {
     CurrentRobotState = state;
     RobotStatusChanged?.Invoke(this, new RobotStatusChangedEventArgs(CurrentRobotState));
 }
 public DisplayTrajectory()
 {
     this.model_id         = "";
     this.trajectory       = new RobotTrajectory[0];
     this.trajectory_start = new RobotState();
 }
        public static void Main()
        {
            //Post methods
            //THIS SECTION CREATES / INITIALIZES THE SERIAL LOGGER
            Debug.Print("Flight computer posted successfully. Beginning INIT.");

            //Initialize sensors, etc.

            Debug.Print("Starting stopwatch");
            Clock.Instance.Start();


            //Thread.Sleep(5000);
            Debug.Print("Flight computer INIT Complete. Continuing with boot.");

            //THIS SECTION INITIALIZES AND STARTS THE MEMORY MONITOR
            Debug.Print("Starting memory monitor...");
            MemoryMonitor.Instance.Start();

            var _motors = new MotorController();

            var testPing = new PingUpdater(Pins.GPIO_PIN_A0);

            testPing.Start();

            var testIR = new IRDistanceUpdater(AnalogChannels.ANALOG_PIN_A1, 25, 100);

            testIR.Start();



            // Start sensor actions here.
            Debug.Print("Flight computer boot successful.");


            while (true)
            {
                Debug.Print("IR: " + RobotState.IRDistance);
                Debug.Print("\nPing: " + RobotState.PingDistance);
                Thread.Sleep(1000);
                var oldSenV     = RobotState.LastIRDistance;
                var currentSenV = RobotState.IRDistance;

                GreenLED.Write(RobotState.CheckReady());

                BlueLED.Write(currentSenV >= 1000);
                YellowLED.Write(currentSenV >= 2000);
                if (currentSenV >= 1000)
                {
                    BlueLED.Write(true);
                }

                if (Math.Abs(oldSenV - currentSenV) > .01)
                {
                    Debug.Print("SensorValue: " + currentSenV);

                    RedLED.Write(false);
                    YellowLED.Write(false);
                    BlueLED.Write(false);

                    if (currentSenV >= 1000)
                    {
                        BlueLED.Write(true);
                    }
                    if (currentSenV >= 2000)
                    {
                        YellowLED.Write(true);
                    }
                    if (!(currentSenV >= 3000))
                    {
                        continue;
                    }

                    RedLED.Write(true);
                    _motors.Halt();

                    _motors.Backward(255);
                    Thread.Sleep(100);

                    if (currentSenV >= 2000)
                    {
                        //do nothing
                        Debug.Print("Too close...");
                        _motors.Halt();
                        _motors.Right(255);
                    }
                }
            }
        }
Exemplo n.º 46
0
 public void UpdateState(RobotState curr, RobotState next)
 {
     if (next.leftHorizontalEye != -1) curr.leftHorizontalEye = next.leftHorizontalEye;
     if (next.leftVerticalEye != -1) curr.leftVerticalEye = next.leftVerticalEye;
     if (next.rightHorizontalEye != -1) curr.rightHorizontalEye = next.rightHorizontalEye;
     if (next.rightVerticalEye != -1) curr.rightVerticalEye = next.rightVerticalEye;
     if (next.leftEyebrow != -1) curr.leftEyebrow = next.leftEyebrow;
     if (next.rightEyebrow != -1) curr.rightEyebrow = next.rightEyebrow;
     if (next.rightEyelid != -1) curr.rightEyelid = next.rightEyelid;
     if (next.leftEyelid != -1) curr.leftEyelid = next.leftEyelid;
     if (next.leftLip != -1) curr.leftLip = next.leftLip;
     if (next.rightLip != -1) curr.rightLip = next.rightLip;
     if (next.jaw != -1) curr.jaw = next.jaw;
     if (next.neckTilt != -1) curr.neckTilt = next.neckTilt;
     if (next.neckTwist != -1) curr.neckTwist = next.neckTwist;
     curr.position = next.position;
     curr.triggerPosition = next.triggerPosition;
 }
Exemplo n.º 47
0
    // Update is called once per frame
    void Update()
    {
        if (GameManager.Instance.CurrentState != GameState.Playing)
        {
            if (!agent.isStopped)
            {
                agent.isStopped = true;
            }
            return;
        }

        if (agent.isStopped)
        {
            agent.isStopped = false;
        }

        switch (currentState)
        {
        case RobotState.Moving:
            searchTimer += Time.deltaTime;
            attackTimer += Time.deltaTime;

            //Search for a nearby tower
            if (searchTimer > SEARCH_TIMER_MAX)
            {
                searchTimer -= SEARCH_TIMER_MAX;
                Targetable newTarget = FindTarget();
                if (newTarget != null)
                {
                    Target            = newTarget;
                    agent.destination = Target.transform.position;
                }
            }

            //Find a new target because this one died
            if (Target == null)
            {
                //If still  null, assign to player
                if ((Target = FindTarget()) == null)
                {
                    Target = GameManager.Instance.player;
                }
                agent.destination = Target.transform.position;
            }
            //The target is moveable, so continuously update the position
            else if (Target.IsMoveable)
            {
                agent.destination = Target.transform.position;
            }


            //Activate attack if we can
            if (attackTimer > ATTACK_TIMER_MAX &&
                Vector3.SqrMagnitude(transform.position - Target.transform.position) <= ATTACK_RANGE)
            {
                attackTimer        = 0;
                currentState       = RobotState.Attacking;
                currentAttackState = RobotAttackState.Charging;
                agent.isStopped    = true;
            }
            break;

        case RobotState.Attacking:
            switch (currentAttackState)
            {
            //Charge up the attack
            case RobotAttackState.Charging:
                attackTimer += Time.deltaTime;

                //Find a new target because this one died
                if (Target == null)
                {
                    //If still  null, assign to player
                    if ((Target = FindTarget()) == null)
                    {
                        Target = GameManager.Instance.player;
                    }
                    agent.destination = Target.transform.position;
                }

                //Rotate towards target
                Vector3    direction    = (Target.transform.position - transform.position).normalized;
                Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
                transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * CHARGE_ROTATION_SPEED);

                if (attackTimer > CHARGE_TIMER_MAX)
                {
                    attackDirection = transform.forward;
                    attackTimer     = 0;
                    hitboxObj.SetActive(true);
                    currentAttackState = RobotAttackState.Performing;
                }
                break;

            //Perform the actual attack
            case RobotAttackState.Performing:
                attackTimer += Time.deltaTime;

                //Move in attack direction
                agent.velocity = attackDirection * PERFORM_MOVE_SPEED;

                if (attackTimer > PERFORM_TIMER_MAX)
                {
                    attackTimer = 0;
                    hitboxObj.SetActive(false);
                    currentAttackState = RobotAttackState.Recovery;
                }
                break;

            //Recover from the attack
            case RobotAttackState.Recovery:
                attackTimer += Time.deltaTime;
                if (attackTimer > RECOVERY_TIMER_MAX)
                {
                    attackTimer     = 0;
                    currentState    = RobotState.Moving;
                    agent.isStopped = false;
                }
                break;

            default:
                break;
            }
            break;

        //TODO: death animations?
        case RobotState.Dying:
            break;

        default:
            break;
        }
    }
Exemplo n.º 48
0
        public static RobotState getNewDest(Map map, RobotState state, RobotState dest)
        {
            float pathSlope; // slope of current path
            float bingSlope; // bing bang slope where "bing bang" is alway perpendicular to the current path
            Line bingbang = null; // bing bang wall which is represented by a Line object
            if (state.X == dest.X)
            {
                // current path is vertical
                bingSlope = 0;
                bingbang = new Line(bingSlope, dest.Y, false);
            } else if (state.Y == dest.Y)
            {
                // current path is horizontal
                pathSlope = 0;
                bingbang = new Line(0, dest.X, true);
            } else {
                // normal case
                pathSlope = (dest.Y - state.Y) / (dest.X - state.X);
                bingSlope = -1 / pathSlope; // k1*k2 = -1  <=> two lines are perpendicular
                float b = dest.Y - bingSlope * dest.X;
                bingbang = new Line(bingSlope, b, false);
            }
            // TODO fix Aaron hack - should be RobotState or something general, not R2D2 state.
            RobotState currDest = new R2D2State { X = dest.X, Y = dest.Y, T = 0f };
            RobotState currDest1 = new R2D2State { X = dest.X, Y = dest.Y, T = 0f }; // temporary destination state with positive offset (offset added later)
            RobotState currDest2 = new R2D2State { X = dest.X, Y = dest.Y, T = 0f }; // temporary destination state with negative offset (offset added later)
            bool hasIntersect;
            bool usingPositiveOffset = true;
            float offsetX, offsetY;
            while (hasIntersect = checkCollision(map, state, currDest)) {
                if (usingPositiveOffset)
                {
                    if (bingbang.isVertical)
                    {
                        offsetX = 0;
                        offsetY = d;
                    }
                    else
                    {
                        offsetX = (float) (d / Math.Sqrt(1 + bingbang.k * bingbang.k));
                        offsetY = (float) (d * bingbang.k / Math.Sqrt(1 + bingbang.k * bingbang.k));
                    }
                    currDest1.X += offsetX;
                    currDest1.Y += offsetY;
                    currDest = currDest1;
                    usingPositiveOffset = false;
                }
                else
                {
                    if (bingbang.isVertical)
                    {
                        offsetX = 0;
                        offsetY = -d;
                    }
                    else
                    {
                        offsetX = (float) (-d / Math.Sqrt(1 + bingbang.k * bingbang.k));
                        offsetY = (float) (-d * bingbang.k / Math.Sqrt(1 + bingbang.k * bingbang.k));
                    }
                    currDest2.X += offsetX;
                    currDest2.Y += offsetY;
                    currDest = currDest2;
                    usingPositiveOffset = true;
                }
            }

            return currDest;
        }
 public DisplayTrajectory(string model_id, RobotTrajectory[] trajectory, RobotState trajectory_start)
 {
     this.model_id         = model_id;
     this.trajectory       = trajectory;
     this.trajectory_start = trajectory_start;
 }
Exemplo n.º 50
0
 public SetRobotModeMessage(int robotID, RobotState.RobotMode mode)
 {
     this.robotID = robotID;
     Mode = mode;
 }
Exemplo n.º 51
0
 public RobotState(RobotState r)
 {
     leftHorizontalEye = r.leftHorizontalEye;
     rightHorizontalEye = r.rightHorizontalEye;
     leftVerticalEye = r.leftVerticalEye;
     rightVerticalEye = r.rightVerticalEye;
     leftEyebrow = r.leftEyebrow;
     rightEyebrow = r.rightEyebrow;
     leftEyelid = r.leftEyelid;
     rightEyelid = r.rightEyelid;
     leftLip = r.leftLip;
     rightLip = r.rightLip;
     jaw = r.jaw;
     neckTilt = r.neckTilt;
     neckTwist = r.neckTwist;
     position = r.position;
 }
Exemplo n.º 52
0
 public RobotStateMessage(int robotID, RobotState state)
 {
     this.robotID = robotID;
     State = state;
 }
Exemplo n.º 53
0
 void DetachBehavior()
 {
     state = RobotState.detached;
     SoundManager.Instance.sfxPlay(SFXType.ROBOT_DISCONNECT);
     BroadcastMessage("Detach");
     rb.velocity = Vector3.zero;
     rb.constraints = RigidbodyConstraints.FreezeAll;
     GameController.Instance.ma.targetActive = false;
 }
Exemplo n.º 54
0
 public RobotCommandMessage(int robotID, RobotCommandType type, RobotState.RobotMode mode)
 {
     this.robotID = robotID;
     Type = type;
     Mode = mode;
 }
Exemplo n.º 55
0
    void OnCollisionEnter(Collision c)
    {
        if (c.gameObject.layer == LayerMask.NameToLayer ("Wall")) {
            if ((state == RobotState.dodging) || (state == RobotState.damaged)) {
                state = RobotState.idle;
            }
        }

        if ((state != RobotState.detached) && (state != RobotState.skill)) {
        if (c.gameObject.CompareTag("building")) {
            c.gameObject.SendMessage ("GiveAttack", GameController.Instance.attackPower * GameController.Instance.attackMultiplier);
            EffectManager.Instance.CameraEffects(0.1f);
            if ((state == RobotState.dodging) || (state == RobotState.damaged)) {
                rb.velocity = oldVelo;
            }
        }

        if (state != RobotState.damaged) {
                if (c.collider.gameObject.CompareTag ("normalAtk")) {
                    preDamagePos = transform.position;
                    curDamageDis = 0;
                    damageDis = 10.0f;
                    damageDir = (gameObject.transform.position - c.collider.attachedRigidbody.transform.position).normalized;
                    damageDir.y = 0;
                    damageDir.Normalize();
                    state = RobotState.damaged;
                    EffectManager.Instance.CameraEffects(0.3f);
                    SoundManager.Instance.sfxPlay(SFXType.ROBOT_HURT);
                    DamagePower dp = c.collider.gameObject.GetComponent<DamagePower> ();
                    if (PoseManager.Instance != null)
                        PoseManager.Instance.CancelCurrDodgePose();
                    if (dp) {
                        health -= dp.damagePower;
                        if (health <= detachThreshold) {
                            DetachBehavior ();
                        }
                    }
                }

                if (c.collider.gameObject.CompareTag ("specialAtk")) {
                    preDamagePos = transform.position;
                    curDamageDis = 0;
                    damageDis = 80.0f;
                    damageDir = (gameObject.transform.position - c.collider.attachedRigidbody.transform.position).normalized;
                    damageDir.y = 0;
                    damageDir.Normalize();
                    state = RobotState.damaged;
                    EffectManager.Instance.CameraEffects(0.3f);
                    SoundManager.Instance.sfxPlay(SFXType.ROBOT_HURT);
                    DamagePower dp = c.collider.gameObject.GetComponent<DamagePower> ();
                    if (dp) {
                        health -= dp.damagePower;
                        if (health <= detachThreshold) {
                            DetachBehavior ();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 56
0
        private XY ToPoint(RoundConfig config, RobotState self, XY cd)
        {
            int max_distance = 10 * config.max_speed * self.speed / config.max_health * self.energy / config.max_energy;
            XY  ResXY        = new XY();
            XY  TryXY        = new XY();


            int dx = cd.X - self.X;

            int dy = cd.Y - self.Y;

            XY SignXY = new XY();

            SignXY.X = sign(dx);
            SignXY.Y = sign(dy);


            ResXY.X = 0;
            ResXY.Y = 0;
            if (takeDistance(self.X, self.Y, cd.X, cd.Y) > max_distance)
            {
                TryXY.X = 0;
                TryXY.Y = 0;


                bool sw = false;
                while (pif(TryXY.X, TryXY.Y) <= max_distance)
                {
                    if (sw)
                    {
                        TryXY.X += SignXY.X;
                        if (pif(TryXY.X, TryXY.Y) > max_distance)
                        {
                            break;
                        }
                        else
                        {
                            ResXY.X += SignXY.X;
                        }
                    }
                    else
                    {
                        TryXY.Y += SignXY.Y;
                        if (pif(TryXY.X, TryXY.Y) > max_distance)
                        {
                            break;
                        }
                        else
                        {
                            ResXY.Y += SignXY.Y;
                        }
                    }
                    sw = !sw;
                }
            }
            else
            {
                ResXY.X = dx;
                ResXY.Y = dy;
            }
            return(ResXY);
        }
Exemplo n.º 57
0
 public void BeginSkill()
 {
     state = RobotState.skill;
 }
Exemplo n.º 58
0
 public DisplayRobotState(RobotState state, ObjectColor[] highlight_links, bool hide)
 {
     this.state           = state;
     this.highlight_links = highlight_links;
     this.hide            = hide;
 }
Exemplo n.º 59
0
 void Attacking()
 {
     if (InputProxy.Instance.GetDodge (out dodgeDir)) {
         preDodgePos = transform.position;
         curDodgeDis = 0;
         state = RobotState.dodging;
         return;
     }
     if (!InputProxy.Instance.GetAttacking ()) {
         if (rb.velocity.magnitude > velocityThresHold) {
             state = RobotState.moving;
         }
         else {
             state = RobotState.idle;
         }
     }
 }
Exemplo n.º 60
0
        // insert movement frames based on amplitude of audio
        public void InsertAmpMouthMovements()
        {
            byte[] waveData = memoryStream.GetBuffer();
            short[] processedData = new short[(memoryStream.Length / (bytesPerSample * 500))+1];

            int windowSize = 1000 * bytesPerSample;
            int globalMax=0;
            int globalMin=0;
            long n, p, q;
            for (n = p = 0; p < waveData.Length; p += bytesPerSample * 500, n++)
            {
                int max = 0;
                int min = 0;

                for (q = p; (q < waveData.Length)&&(q<p+(bytesPerSample * 500)); q += bytesPerSample)
                {
                    int val = BitConverter.ToInt16(waveData, (int)q);
                    if (val > max) max = val;
                    if (val < min) min = val;
                }

                if (min < globalMin) globalMin = min;
                if (max > globalMax) globalMax = max;

                min = -min;

                if (min>max)
                    processedData[n] = (short)(min);
                else
                    processedData[n] = (short)(max);
            }

            globalMin = -globalMin;
            if (globalMin > globalMax) globalMax = globalMin;
            float factor = 32768.0f / globalMax;

            int i;
            int last = (int)((float)processedData[0]*factor);
            for (i = 1; i < n; i++)
            {
                int val = (int)((float)processedData[i-1]*factor);
                if (Math.Abs(last - val) > 4096)
                {
                    if (val < 0) val = -val;

                    RobotState rs = new RobotState();

                    rs.leftHorizontalEye = -1.0f;
                    rs.leftVerticalEye = -1.0f;
                    rs.rightHorizontalEye = -1.0f;
                    rs.rightVerticalEye = -1.0f;
                    rs.leftEyebrow = -1.0f;
                    rs.rightEyebrow = -1.0f;
                    rs.rightEyelid = -1.0f;
                    rs.leftEyelid = -1.0f;
                    rs.neckTilt = -1.0f;
                    rs.neckTwist = -1.0f;
                    rs.triggerPosition = 0;

                    rs.position = i*bytesPerSample * 500;
                    rs.jaw = (val / 32768.0f);
                    if (rs.jaw > 1.0f) rs.jaw = 1.0f;
                    editPoints.Add(rs);
                    last = val;
                }
            }

            /*
            int i;
            memoryStream.Position = 0;
            for (i = 0; i < n; i ++)
            {
                int val = (int)((float)processedData[i]*factor);
                memoryStream.WriteByte((byte)(val & 255));
                memoryStream.WriteByte((byte)(val >> 8));
            }
            */
            Invalidate();
        }