Beispiel #1
0
    /// <summary>
    /// Called upon event OnModelImported in UrdfAssetImporterRuntime, when 3d model is imported.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args">Contains imported GameObject.</param>
    private void OnModelImported(object sender, ImportedModelEventArgs args)
    {
        //Debug.Log("URDF: model imported");
        Transform importedModel = args.RootGameObject.transform;

        UrdfRobot[] urdfRobots = importedModel.GetComponentsInParent <UrdfRobot>(true);
        if (urdfRobots != null)
        {
            UrdfRobot urdfRobot = urdfRobots[0];

            // TODO: make sure that this robotModel check really works
            // check if imported model corresponds to this robot
            RobotModel robotModel = GetRobotModel(urdfRobot.gameObject);
            if (robotModel != null)
            {
                if (args.CollidersOnly)
                {
                    robotModel.SetLinkCollisionLoaded(importedModel.GetComponentsInParent <UrdfLink>(true)[0].name, importedModel.GetComponentsInParent <UrdfCollision>(true)[0]);
                }
                else
                {
                    robotModel.SetLinkVisualLoaded(importedModel.GetComponentsInParent <UrdfLink>(true)[0].name, importedModel.GetComponentsInParent <UrdfVisual>(true)[0]);
                }

                //Debug.Log("URDF: model of the link: " + importedModel.parent.parent.parent.parent.name + " imported");
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Returns RobotModel of specified robotType. If there is no free RobotModel, it will create and return a new instance.
    /// </summary>
    /// <param name="robotType">Type of the robot that will be imported.</param>
    /// <returns></returns>
    public RobotModel GetRobotModelInstance(string robotType)
    {
        // Check if newer model exists

        if (RobotModels.TryGetValue(robotType, out List <RobotModel> robotModels))
        {
            if (robotModels.Count > 0)
            {
                foreach (RobotModel robotModel in robotModels)
                {
                    // if there is some instanced robot model that is not being used, return its instance
                    if (!robotModel.IsBeingUsed)
                    {
                        robotModel.IsBeingUsed = true;
                        return(robotModel);
                    }
                }
                // if no free instance of the robot is available, make a new one
                RobotModel robot = CopyRobotModel(robotModels[0]);
                RobotModels[robotType].Add(robot);
                robot.IsBeingUsed = true;
                return(robot);
            }

            Debug.LogError("Failed to get robot model instance of type: " + robotType);
        }
        else
        {
            Debug.Log("Robot model of type: " + robotType + " is not loaded yet.");
        }

        return(null);
    }
Beispiel #3
0
        private async void RobotModelLoaded()
        {
            Debug.Log("URDF: robot is fully loaded");

            RobotModel.RobotModelGameObject.transform.parent           = transform;
            RobotModel.RobotModelGameObject.transform.localPosition    = Vector3.zero;
            RobotModel.RobotModelGameObject.transform.localEulerAngles = Vector3.zero;

            // retarget OnClickCollider target to receive OnClick events
            foreach (OnClickCollider onCLick in RobotModel.RobotModelGameObject.GetComponentsInChildren <OnClickCollider>(true))
            {
                onCLick.Target = gameObject;
            }

            RobotModel.SetActiveAllVisuals(true);

            outlineOnClick.ClearRenderers();
            RobotPlaceholder.SetActive(false);
            Destroy(RobotPlaceholder);

            robotColliders.Clear();
            robotRenderers.Clear();
            robotRenderers.AddRange(RobotModel.RobotModelGameObject.GetComponentsInChildren <Renderer>());
            robotColliders.AddRange(RobotModel.RobotModelGameObject.GetComponentsInChildren <Collider>());
            outlineOnClick.InitRenderers(robotRenderers);
            outlineOnClick.OutlineShaderType = OutlineOnClick.OutlineType.TwoPassShader;
            outlineOnClick.InitGizmoMaterials();
            await WebsocketManager.Instance.RegisterForRobotEvent(GetId(), true, RegisterForRobotEventRequestArgs.WhatEnum.Joints);
        }
Beispiel #4
0
    /// <summary>
    /// Called upon event ColladaImporter.Instance.OnModelImported, when DAE file is imported.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args">Contains imported GameObject.</param>
    private void OnColladaModelImported(object sender, ImportedColladaEventArgs args)
    {
        Debug.Log("URDF: Collada model imported");
        Transform importedModel = args.Data.transform;

        UrdfRobot[] urdfRobots = importedModel.GetComponentsInParent <UrdfRobot>(true);
        if (urdfRobots != null)
        {
            UrdfRobot urdfRobot = urdfRobots[0];

            // TODO: make sure that this robotModel check really works
            // check if imported model corresponds to this robot
            RobotModel robotModel = GetRobotModel(urdfRobot.gameObject);
            if (robotModel != null)
            {
                // get rid of the placeholder object (New Game Object)
                Transform placeholderGameObject = importedModel.parent;
                importedModel.SetParent(placeholderGameObject.parent, worldPositionStays: false);

                //TODO: Temporarily, colliders are added directly to Visuals
                AddColliders(importedModel.gameObject, setConvex: true);
                Destroy(placeholderGameObject.gameObject);

                robotModel.SetLinkVisualLoaded(importedModel.parent.parent.parent.name, importedModel.parent.gameObject.GetComponent <UrdfVisual>());

                Debug.Log("URDF: dae model of the link: " + importedModel.parent.parent.parent.name + " imported");
            }
        }
    }
Beispiel #5
0
        public async Task <RobotModel> AddTaskAsync(RobotModel robot)
        {
            RobotModel bot = (await _context.Robots.AddAsync(robot)).Entity;
            await _context.SaveChangesAsync();

            return(robot);
        }
        public ActionResult RegistrationUsers(RobotRegistationViewModel model)
        {
            if (model.AccessDate.CompareTo(DateTime.Now.Date) < 0)
            {
                ModelState.AddModelError("", "Ошибка в дате доступа");
            }
            if (ModelState.IsValid)
            {
                var robotUser = new RobotModel
                {
                    UserName            = model.UserName,
                    AccessDate          = model.AccessDate,
                    CountStartsProgramm = 0,
                    CreationDate        = DateTime.Now,
                    LastAccessDate      = DateTime.Now,
                    LastBalance         = 0,
                    UniqGuid            = new Guid()
                };
                _dbContext.RobotUsers.Add(robotUser);
                _dbContext.SaveChanges();
            }
            var allUsers = _dbContext.RobotUsers;

            return(PartialView("Index", allUsers));
        }
Beispiel #7
0
        public void CreatePlayerState(int number, string name)
        {
            RobotModel robotModel = new RobotModel(number, name);

            playerState        = playerService.CreatePlayerState(robotModel, gameHistory);
            playerStateService = new PlayerStateService(playerState);
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            //Take Input
            RobotModel    robot         = new RobotModel();
            List <string> givenCommands = new List <string>();

            Console.WriteLine("Number of commands: ");
            string numberOfCommands = Console.ReadLine();

            Console.WriteLine("Starting Coordinates: ");
            string coordinates = Console.ReadLine();

            for (int i = 1; i <= Convert.ToInt32(numberOfCommands); i++)
            {
                Console.WriteLine($"Enter command {i}:");
                givenCommands.Add(Console.ReadLine());
            }

            //Execute cleaning and display results
            var service      = new RobotService();
            int cleanedSpots = service.ExecuteCommands(givenCommands, coordinates);

            Console.WriteLine($"=> Cleaned: {cleanedSpots}");
            Console.ReadLine();
        }
Beispiel #9
0
        public async Task <IActionResult> PutHead(long id, [FromBody] HeadModel headMoved)
        {
            RobotModel robot = await _context.Robots.FindAsync(id);

            if (robot is null)
            {
                return(NotFound());
            }

            var robotVO     = _mapper.Map <RobotVO>(robot);
            var headMovedVO = _mapper.Map <HeadVO>(headMoved);

            var canMoveHead = _headMovement.CanMoveHead(robotVO, headMovedVO);

            if (canMoveHead == false)
            {
                return(BadRequest(new { canMoveHead }));
            }

            robot.Head = headMoved;

            _context.Entry(robot).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(Ok(new { canMoveHead }));
        }
Beispiel #10
0
        public async Task <IActionResult> PutRightArm(long id, [FromBody] ArmModel rightArmMoved)
        {
            RobotModel robot = await _context.Robots.FindAsync(id);

            if (robot is null)
            {
                return(NotFound());
            }

            var robotVO         = _mapper.Map <RobotVO>(robot);
            var rightArmMovedVO = _mapper.Map <ArmVO>(rightArmMoved);
            var canMoveLeftArm  = _armMovement.CanMoveArm(robotVO, rightArmMovedVO, ArmSide.Right);

            if (canMoveLeftArm == false)
            {
                return(BadRequest());
            }

            robot.RightArm = rightArmMoved;
            _context.Entry(robot).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(NoContent());
        }
Beispiel #11
0
        public override Robot CreateRobot(RobotModel model)
        {
            Robot robot = new WorkerRobot(model);

            robot.DecodingProbability = 100;
            robot.Carrying            = 10;
            return(robot);
        }
 public static Robot ToRobot(this RobotModel robot)
 {
     return(new Robot
     {
         Id = Guid.Parse(robot.Id),
         Status = (RobotStatus)robot.Status
     });
 }
Beispiel #13
0
        public IActionResult Delete(Guid id)
        {
            var model = new RobotModel();

            model.Disable(id);

            return(RedirectToAction("Index"));
        }
Beispiel #14
0
        public RobotModel Reset(RobotModel robot)
        {
            robot.Head     = RobotHelper.CreadDefaultHead();
            robot.LeftArm  = RobotHelper.CreateDefaultArm();
            robot.RightArm = RobotHelper.CreateDefaultArm();

            return(robot);
        }
Beispiel #15
0
        public override Robot CreateRobot(RobotModel model)
        {
            Robot robot = new CyborgRobot(model);

            robot.DecodingProbability = 60;
            robot.Carrying            = 15;
            return(robot);
        }
        /// <summary>
        /// Start a new control command and sends it
        /// </summary>
        /// <returns></returns>
        private bool NewControlCmd()
        {
            //Change the user interface
            if (SzenarioController.Changed)
            {
                foreach (var t in RobotController.Robots)
                {
                    if (Convert.ToInt32(Robot.Identification.Id) != t.Identification.Id)
                    {
                        continue;
                    }
                    Robot = new RobotModel(t);
                    break;
                }
                SzenarioController.Changed = false;
            }

            if (!SzenarioController.Refresh)
            {
                //stop sensors
                CrossDeviceMotion.Current.Stop(MotionSensorType.Accelerometer);
                //set object active -> false
                foreach (var t in Client.Szenario.Robots)
                {
                    t.Active = false;
                }
                Client.Device.Active = false;
                //remove the szenario
                SzenarioController.Szenarios.Remove(Client.Szenario);

                //Send the control end command
                Client.Szenario.Command = ControlType.Undefinied.ToString();
                var cmd = new SzenarioCommand(CommandType.Szenario.ToString(), SzenarioCommandType.End.ToString(), Client.Identification, Client.Szenario);
                Client.SendCmd(JsonConvert.SerializeObject(cmd));

                Client.Szenario = null;

                //navigate to startpage
                var page       = FreshMvvm.FreshPageModelResolver.ResolvePageModel <HomePageModel>();
                var navigation = new FreshMvvm.FreshNavigationContainer(page)
                {
                    BarBackgroundColor = Color.FromHex("#008B8B"),
                    BarTextColor       = Color.White
                };
                Application.Current.MainPage = navigation;

                return(false);
            }

            Client.Szenario.Command  = ControlType.Control.ToString();
            Client.Szenario.Steering = new Steering((int)_direction, (int)_speed);

            var command = new SzenarioCommand(CommandType.Szenario.ToString(), Client.Szenario.Type, Client.Identification, Client.Szenario);

            Client.SendCmd(command.ToJsonString());

            return(true);
        }
Beispiel #17
0
        public async Task <ActionResult <RobotModel> > PostRobotModel()
        {
            RobotModel robot = CreateDefaultRobot();

            _context.Robots.Add(robot);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("PostRobotModel", new { id = robot.Id }, robot));
        }
Beispiel #18
0
    private RobotModel CopyRobotModel(RobotModel robotToCopy)
    {
        GameObject robotModelGameObject = Instantiate(robotToCopy.RobotModelGameObject);

        robotModelGameObject.transform.parent           = transform;
        robotModelGameObject.transform.localPosition    = Vector3.zero;
        robotModelGameObject.transform.localEulerAngles = Vector3.zero;
        RobotModel robot = new RobotModel(robotToCopy.RobotType, robotModelGameObject);

        return(robot);
    }
Beispiel #19
0
        public RobotModel NewRobot()
        {
            var robot = new RobotModel
            {
                Name  = "Robot " + (Robots.Count + 1),
                Color = Colors[_random.Next(Colors.Length)],
            };

            _log.LogInformation("created new robot: {NewRobot}", robot);
            _robots.Add(robot);
            return(robot);
        }
Beispiel #20
0
        public IActionResult Index(long id)
        {
            RobotVO robot = _robotService.GetRobot(id);

            if (robot == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            RobotModel robotModel = _mapper.Map <RobotModel>(robot);

            return(View(robotModel));
        }
        public MainViewModelIntegrationTests(ITestOutputHelper output)
        {
            _output = output;
            var resolver = new Mock <IHostNameResolver>();

            resolver.Setup(x => x.GetValidHostName(It.IsAny <string>())).Returns(Task.FromResult(_ip));
            var settings = new Mock <ISettings>();

            settings.Setup(x => x.HostName).Returns(_ip);

            IRobotModel robotModel = new RobotModel(resolver.Object, settings.Object);

            _sut = new MainViewModel(robotModel, new Mock <INavigationService>().Object);
        }
        // Reading discriminating union requires using JSValue.
        public static void ReadValue(this JSValue jsValue, out OneOf2 <T2Extra, R2D2Extra> value)
        {
            value = default;
            if (jsValue.TryGetObjectProperty("Kind", out JSValue kind))
            {
                RobotModel modelType = kind.ReadValue <RobotModel>();
                switch (modelType)
                {
                case RobotModel.T2: value = jsValue.ReadValue <T2Extra>(); break;

                case RobotModel.R2D2: value = jsValue.ReadValue <R2D2Extra>(); break;
                }
            }
        }
Beispiel #23
0
        public void CreatePlayerState_Test()
        {
            //Arrange
            var           history    = new GameHistory();
            var           robotModel = new RobotModel(1, "test");
            PlayerService service    = new PlayerService();

            //Act
            var playerState = service.CreatePlayerState(robotModel, history);

            //Assert
            Assert.NotNull(playerState);
            //TODO
        }
Beispiel #24
0
    /// <summary>
    /// Puts specified RobotModel back to the RobotModels dictionary "pool" for further use by another RobotActionObject.
    /// </summary>
    /// <param name="robotModel">RobotModel to be put back to the RobotModels dictionary.</param>
    public void ReturnRobotModelInstace(RobotModel robotModel)
    {
        robotModel.RobotModelGameObject.transform.parent           = transform;
        robotModel.RobotModelGameObject.transform.localPosition    = Vector3.zero;
        robotModel.RobotModelGameObject.transform.localEulerAngles = Vector3.zero;

        robotModel.IsBeingUsed = false;
        robotModel.SetActiveAllVisuals(false);

        // retarget OnClickCollider target to receive OnClick events
        foreach (OnClickCollider onCLick in robotModel.RobotModelGameObject.GetComponentsInChildren <OnClickCollider>(true))
        {
            onCLick.Target = null;
        }
    }
Beispiel #25
0
        static void Main(string[] args)
        {
            RobotModel hardWorkerRobot = new RobotModel(new HardWorkerFactory(), "Тяжёлый рабочий");
            RobotModel destructorRobot = new RobotModel(new DestructorFactory(), "Уничтожитель");
            RobotModel workerRobot     = new RobotModel(new WorkerFactory(), "Рабочий");

            hardWorkerRobot.Run();
            destructorRobot.Work();
            workerRobot.Work();
            hardWorkerRobot.Work();
            destructorRobot.Run();
            workerRobot.Run();

            Console.ReadKey();
        }
Beispiel #26
0
        private Robot ChooseRobot(RobotModel model)
        {
            RobotCreator creator      = null;
            double       sum          = 0;
            Random       random       = new Random();
            double       randomNumber = random.NextDouble();

            foreach (KeyValuePair <string, double> probability in ChoiceProbability)
            {
                if (randomNumber <= (sum = sum + probability.Value))
                {
                    creator = ChooseCreator(probability.Key);
                    break;
                }
            }
            return(CreateRobot(model, creator));
        }
 public void initialize()
 {
     if (0 == robots.Count)
     {
         robots.Add(new NullObjectRobot("NONE", "", 0));
         //robots.Add(new RobotModel("ID: 30", "127.0.0.1", 23));
         for (var i = 0; i < 6; i++)
         {
             var newRobot = new RobotModel("ID: 3" + i, "192.168.2.3" + i, 8000);
             robots.Add(newRobot);
         }
     }
     else
     {
         Logger.Instance.log(LogLevel.INFO, "Initialization can be called only once");
     }
 }
Beispiel #28
0
    /// <summary>
    /// Imports URDF based on a given filename. Filename has to contain a full path.
    /// <param name="filename">Filename including path to the urdf file.</param>
    /// <param name="robotType">Type of the robot.</param>
    /// </summary>
    private void ImportUrdfObject(string filename, string robotType)
    {
        UrdfRobot urdfRobot = UrdfRobotExtensionsRuntime.Create(filename, useColliderInVisuals: true, useUrdfMaterials: true);

        urdfRobot.transform.parent           = transform;
        urdfRobot.transform.localPosition    = Vector3.zero;
        urdfRobot.transform.localEulerAngles = Vector3.zero;

        urdfRobot.SetRigidbodiesIsKinematic(true);

        RobotModel robot = new RobotModel(robotType, urdfRobot.gameObject);

        robot.LoadLinks();

        RobotModels[robotType].Add(robot);

        //Debug.Log("URDF: robot created (without models yet)");
    }
Beispiel #29
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            _eng = (RobotEngine)((Value.Container)args[0]).Item;

            var nodes_in  = ((Value.List)args[1]).Item;
            var bars_in   = ((Value.List)args[2]).Item;
            var plates_in = ((Value.List)args[3]).Item;

            var nodes  = nodes_in.Select(x => ((AnalyticalNode)((Value.Container)x).Item));
            var bars   = bars_in.Select(x => ((AnalyticalBar)((Value.Container)x).Item));
            var plates = plates_in.Select(x => ((AnalyticalPlate)((Value.Container)x).Item));

            RobotModel model = new RobotModel(_eng.Application, nodes, bars, plates);

            model.Analyze();
            model.GetResults();

            return(Value.NewContainer(model));
        }
 public List <IO.Swagger.Model.Joint> GetJoints()
 {
     if (RobotModel == null)
     {
         // if urdf model is still loading, return empty joint list
         if (modelLoading)
         {
             return(new List <IO.Swagger.Model.Joint>());
         }
         else
         {
             throw new RequestFailedException("Model not found for this robot.");
         }
     }
     else
     {
         return(RobotModel.GetJoints());
     }
 }