Esempio n. 1
0
        public RemoteControlHub(IWillyRosService willyRosService)
        {
            // Create the cmd_vel topic
            CmdVelTopic = new RosTopic(willyRosService.RosClient, "/cmd_vel", "geometry_msgs/Twist");

            // A timer will reset the speed to 0 if it's not reset in time
            _resetTimer = new Timer(1000)
            {
                AutoReset = true
            };
            _resetTimer.Elapsed += async(sender, args) => await StopMovement();

            _resetTimer.Start();
        }
Esempio n. 2
0
        private async Task ClientStateTask()
        {
            while (_running)
            {
                if (EnableTestData)
                {
                    SendTestData();
                }

                if (RosClient.WebSocket != null && RosClient.WebSocket.State == WebSocketState.Open)
                {
                    await Task.Delay(1000);

                    continue;
                }

                // Remove the old topics if they exist
                _gpsTopic?.Dispose();
                _sonarTopic?.Dispose();

                // Create a new connection and topics
                try
                {
                    await RosClient.ConnectAsync(new Uri(_configuration["RosBridgeUri"]));
                }
                catch (Exception e)
                {
                    Console.WriteLine("ROS connection failed:");
                    Console.WriteLine(e);

                    await Task.Delay(1000);

                    continue;
                }

                _gpsTopic               = new RosTopic(RosClient, "/gps", null);
                _gpsTopic.RosMessage   += GpsTopicOnRosMessage;
                _sonarTopic             = new RosTopic(RosClient, "/sonar", null);
                _sonarTopic.RosMessage += SonarTopicOnRosMessage;

                await Task.Delay(1000);
            }
        }