예제 #1
0
        public bool CanMoveArm(RobotVO robot, ArmVO armMoved, ArmSide armSide)
        {
            ArmVO arm = armSide == ArmSide.Left ? robot.LeftArm : robot.RightArm;

            bool isElbowMovement = IsElbowMovement(arm, armMoved.Elbow);
            bool isWristMovement = IsWristMovement(arm, armMoved.Wrist);

            // Não se pode mexer mais de uma parte do braço por vez
            if (isElbowMovement && isWristMovement)
            {
                return(false);
            }

            if (isElbowMovement)
            {
                return(ChangeElbowMovement(arm, armMoved.Elbow));
            }

            if (isWristMovement)
            {
                return(ChangeWristMovement(arm, armMoved.Wrist));
            }

            //Não houve mudança
            return(true);
        }
예제 #2
0
        public bool PutRightArm(long id, ArmVO rightArmMoved)
        {
            bool isRightArmMoved = false;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_kraftwerkAPIUrl);

                var putTask = client.PutAsJsonAsync <ArmVO>($"api/Robot/{id}/LeftArm", rightArmMoved);
                putTask.Wait();

                var result = putTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    isRightArmMoved = true;
                }
                else if (result.StatusCode == HttpStatusCode.BadRequest)
                {
                    isRightArmMoved = false;
                }
            }

            return(isRightArmMoved);
        }
예제 #3
0
        public bool ChangeWristMovement(ArmVO arm, WristMovement wristMovement)
        {
            if (arm.Elbow != ElbowMovement.StronglyContracted)
            {
                return(false);
            }

            return(true);
        }
예제 #4
0
        public void NaoDevePermitirMovimentoDoPulso()
        {
            //Assert
            ArmVO arm = new ArmVO()
            {
                Elbow = ElbowMovement.InRest,
                Wrist = WristMovement.InRest
            };

            WristMovement wristMovement = WristMovement.Rotate135Degrees;

            //Act
            var result = _armMovement.ChangeWristMovement(arm, wristMovement);

            //Assert
            Assert.False(result);
        }
예제 #5
0
        public void DevePermitirMovimentoDoPulso()
        {
            //Arrange
            ArmVO arm = new ArmVO()
            {
                Elbow = ElbowMovement.StronglyContracted,
                Wrist = WristMovement.InRest
            };

            WristMovement wristMovement = WristMovement.Rotate135Degrees;

            //Act
            var result = _armMovement.ChangeWristMovement(arm, wristMovement);

            //Assert
            Assert.True(result);
        }
예제 #6
0
        private JsonResult ChangeWristPosition(long id, ArmVO arm, int newPositionWristNumeric, ArmSide armSide)
        {
            WristMovement newWristMovement;
            string        movementDescription = string.Empty;

            bool isValidMovement = newPositionWristNumeric.TryParseEnum(out newWristMovement);

            if (isValidMovement)
            {
                arm.Wrist           = newWristMovement;
                movementDescription = arm.Wrist.GetDescription();

                bool isArmMoved = armSide == ArmSide.Left ? _robotService.PutLeftArm(id, arm) : _robotService.PutRightArm(id, arm);

                if (isArmMoved == false)
                {
                    isValidMovement = false;
                }
            }

            return(Json(new { isValidMovement, description = movementDescription }));
        }
예제 #7
0
        public ArmVO GetRightArm(long id)
        {
            ArmVO rightArm = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_kraftwerkAPIUrl);

                Task <HttpResponseMessage> responseTask = client.GetAsync($"api/robot/{id}/RightArm");
                responseTask.Wait();

                HttpResponseMessage result = responseTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    Task <ArmVO> readTask = result.Content.ReadAsAsync <ArmVO>();
                    readTask.Wait();
                    rightArm = readTask.Result;
                }
            }

            return(rightArm);
        }
예제 #8
0
 public bool ChangeElbowMovement(ArmVO arm, ElbowMovement elbowMovement) => true;
예제 #9
0
 private bool IsWristMovement(ArmVO arm, WristMovement wristMovement) => arm.Wrist != wristMovement;
예제 #10
0
 private bool IsElbowMovement(ArmVO arm, ElbowMovement elbowMovement) => arm.Elbow != elbowMovement;