示例#1
0
        public void TestChannels()
        {
            const string topicName = "/my_test_topic_xyz";

            using var client          = new RosClient(MasterUri, CallerId, CallerUri);
            using var publisher       = new RosChannelWriter <String>(client, topicName);
            publisher.LatchingEnabled = true;

            var systemState = client.GetSystemState();

            Assert.True(
                systemState.Publishers.Any(tuple => tuple.Topic == topicName && tuple.Members.Contains(CallerId)));

            const string msgText = "test message";

            publisher.Write(new String(msgText));

            using var subscriber = new RosChannelReader <String>(client, topicName);

            using var source = new CancellationTokenSource(5000);

            foreach (var msg in subscriber.ReadAll(source.Token))
            {
                if (msg.Data == msgText)
                {
                    break;
                }
            }
        }
示例#2
0
        // this gets called when we're connected to the master
        async void Start()
        {
            Uri masterUri = new Uri("http://141.3.59.5:11311");
            Uri myUri     = RosClient.TryGetCallerUriFor(masterUri, 7635) ?? RosClient.TryGetCallerUri(7635);

            connectionClient = await RosClient.CreateAsync(masterUri, "/iviz_test", myUri);

            scenePublisher = new RosChannelWriter <PlanningScene> {
                LatchingEnabled = true
            };
            await scenePublisher.StartAsync(connectionClient, "/move_group/monitored_planning_scene");

            //Logger.LogDebug = Debug.Log;
            Logger.Log      = Debug.Log;
            Logger.LogError = Debug.LogWarning;

            Debug.Log($"{this}: Connected!");
            while (true)
            {
                if (this == null)
                {
                    return;
                }

                // keep checking whether the moveit_test node is on
                const string trajectoryService = "/moveit_test/calculate_trajectory";
                var          systemState       = await connectionClient.GetSystemStateAsync();

                bool hasService = systemState.Services.Any(service => service.Topic == trajectoryService);
                if (hasService)
                {
                    break;
                }

                Debug.LogWarning($"{this}: Service not detected! Retrying...");
                await Task.Delay(2000);
            }

            Debug.Log($"{this}: Service found. Starting robot and listeners.");

            // generate two robots: 'robot' for the real robot, and 'planRobot' for the plan
            await GenerateRobotAsync();

            // start listening to the joints topic
            // these joints apply only for 'robot'.
            jointsListener = new RosChannelReader <JointState>();
            await jointsListener.StartAsync(connectionClient, "/joint_states");

            // here we create a new collision object for the scene
            PlanningScene scene = new PlanningScene();

            scene.Name = "(noname+)"; // taken from rviz
            scene.World.CollisionObjects = new[]