From 329d3fe6ec133ea29fa5b7101cca8bcc0ec08876 Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Thu, 23 Feb 2023 13:58:02 +0000 Subject: [PATCH] Fixed actor plugin deadlock. --- src/ign_actor_plugin/src/ActorSystem.cpp | 29 ++++++++++++------- src/ign_actor_plugin/src/ActorSystem.hpp | 2 +- .../launch/gazebo_controller_launch.py | 13 +++++---- src/moveit_test/src/test.cpp | 14 ++++----- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/ign_actor_plugin/src/ActorSystem.cpp b/src/ign_actor_plugin/src/ActorSystem.cpp index e6093dc..106419a 100644 --- a/src/ign_actor_plugin/src/ActorSystem.cpp +++ b/src/ign_actor_plugin/src/ActorSystem.cpp @@ -94,7 +94,11 @@ void ActorSystem::switchAnimation(EntityComponentManager &_ecm, char *animationN void ActorSystem::PreUpdate(const UpdateInfo &_info, EntityComponentManager &_ecm) { threadMutex.lock(); - + if(nextState != currentState){ + igndbg << "State change before: " << currentState << " -> " << nextState << std::endl; + currentState = nextState; + sendFeedback(0.0); + } switch (currentState) { case SETUP: { @@ -122,7 +126,7 @@ void ActorSystem::PreUpdate(const UpdateInfo &_info, EntityComponentManager &_ec _ecm.CreateComponent(entity, components::TrajectoryPose(ignition::math::Pose3d::Zero)); } - currentState = IDLE; + nextState = IDLE; break; } case ANIMATION: { @@ -138,7 +142,8 @@ void ActorSystem::PreUpdate(const UpdateInfo &_info, EntityComponentManager &_ec if (newTimeSeconds >= duration) { igndbg << "Animation " << animation_name << " finished." << std::endl; - currentState = IDLE; + nextState = IDLE; + sendFeedback(0.0); break; } @@ -177,8 +182,9 @@ void ActorSystem::PreUpdate(const UpdateInfo &_info, EntityComponentManager &_ec auto targetDirection = math::Vector3d(targetPose[0], targetPose[1], targetPose[2]) - actorPose.Pos(); if (targetDirection.Length() < 0.05) { + igndbg << "Finished Movement..." << std::endl; sendFeedback(1.0); - currentState = IDLE; + nextState = IDLE; break; } @@ -231,12 +237,8 @@ void ActorSystem::PreUpdate(const UpdateInfo &_info, EntityComponentManager &_ec break; } - if (lastState != currentState) { - igndbg << "State change: " << lastState << " -> " << currentState << std::endl; - sendFeedback(0.0); - } - lastState = currentState; + threadMutex.unlock(); } @@ -276,7 +278,7 @@ void ActorSystem::messageQueueInterface(const char name[256]) { // animation_speed = receivedAction.animationSpeed; animation_distance = receivedAction.animationDistance; target_position = math::Vector3d(receivedAction.positionX, receivedAction.positionY, receivedAction.positionZ); - currentState = receivedAction.state; + nextState = receivedAction.state; std::cout << "Got Action" << std::endl; threadMutex.unlock(); @@ -288,7 +290,11 @@ void ActorSystem::sendFeedback(double progress){ FeedbackMessage message; message.progress = progress; message.state = currentState; - mq_send(feedbackQueue,(char *)&message,sizeof(FeedbackMessage),0); + if(mq_send(feedbackQueue,(char *)&message,sizeof(FeedbackMessage),0)==0){ + igndbg << "Sent feedback. (State: " << lastState << "->" << currentState << " | Progress: "<< progress <<")" << std::endl; + }else{ + ignerr << "Error " << errno << " sending feedback." << std::endl; + } } // Found too late: https://github.com/AlanSixth/gazebo_ros_action_tutorial/blob/master/src/gazebo_ros_action_tutorial.cc @@ -318,6 +324,7 @@ void ActorSystem::Configure(const Entity &_entity, const std::shared_ptr states = { - {"base_rot",10.0} - }; + //std::map states = { + // {"base_rot",10.0} + //}; - move_group_interface.setJointValueTarget(states); + //move_group_interface.setJointValueTarget(states); // Create a plan to that target pose auto const [success, plan] = [&move_group_interface]{