Exemplo n.º 1
0
        private async static Task HandleStepwiseMotions(ISteppedMotionClient client, IMoveGroup group)
        {
            string channelName = "MotionDialog";
            string topic       = "SteppedMotions";
            string disposition = "SteppedMotion";

            using (var RosRoboChatClient = new RosRoboChatActionClient(rosClient.GlobalNodeHandle))
            {
                RosRoboChatClient.CreateChat(channelName, topic);
                var messageBody = new SteppedMotionMessage {
                    GoalId = client.GoalId, Progress = 0, MoveGroupName = group.Name
                }.ToString();
                string messageId = RosRoboChatClient.CallMessageCommand(channelName, "add", messageBody, null, new string[] { disposition });
                try
                {
                    var cancelReport = new CancellationTokenSource();
                    xamlamoveit.StepwiseMoveJResult result;
                    var updateProgressTask = UpdateProgress(client, RosRoboChatClient, channelName, messageId, disposition, group.Name, cancelReport.Token);
                    try
                    {
                        result = await client.GoalTask;
                    }
                    finally
                    {
                        cancelReport.Cancel();
                        await updateProgressTask.WhenCompleted();
                    }

                    if (result.result < 0)
                    {
                        throw new Exception($"SteppedMotion was not finished: { result.result }");
                    }
                }
                finally
                {
                    RosRoboChatClient.CallMessageCommand(channelName, "remove", null, messageId, new string[] { disposition });
                }
            }
        }