MATLAB has encountered an internal problem after deleting the action client

Hallo,
Before, I used MATLAB to define actionclient to control the actionserver in ROS. After using it, I didn’t want to disconnect from ROS so that I could continue to send goals to actionserver. Therefore, I only deleted the current actionclient, as in the following example.
[gripper_actClient, gripper_msg] = rosactionclient('/gripper_action');
waitForServer(gripper_actClient);
gripper_msg.Type = 0;
[resultMsg, resultState] = sendGoalAndWait(gripper_actClient, gripper_msg);
delete(gripper_actClient);
However, after that, when I wanted to perform any operation in MATLAB, an error message appeared.
Connection to process with Exchange: "45b2b5d4-bb67-48e5-bf98-267b41dba48d " was lost.
I had to close matlab and restart it. When I run the above code again, it was still the same result. Has anyone encountered the same problem?
I used MATLAB R2021b in windows. I have also tried in Ubuntu 16.04 and there was same problem, but in macOS Big Sur (Version 11) not.

4 commentaires

Prabeen Sahu
Prabeen Sahu le 8 Nov 2021
Modifié(e) : Prabeen Sahu le 8 Nov 2021
Hi Xin,
Your code looks fine and should not create any issue. I tried the same code with 'actionlib/Test' action in windows10 and it worked fine for me. Please provide me more details on the issue to debug further.
  • What is the action type of '/gripper_action'.
  • Is it a custom action that you created? If so, it is possible to share that with us?
  • Where is your action server running (os, ros-version)?
  • Do you see the error only after 'delete(gripper_actClient);' ? Or any other line of above code is responsible for this issue?
  • Do you see the same issue with some other action type as well?
-Prabeen
Xin Xing
Xin Xing le 8 Nov 2021
Modifié(e) : Xin Xing le 8 Nov 2021
Hi Prabeen,
Yes, /gripper_action is a custom action that i created. This simple action server is mainly to control the 3-finger-gripper from robotiq. Unfortunately, this code currently belongs to the research institute and has not been made public, so I cannot share it here.
I can give a brief introduction, given as parameters such as goal, grab mode, width, speed, force, etc., feedback will publish the current positions of the gripper fingers at 10hz, and as a result, the grab result will be given.
This action server is running in Ubuntu 16.04 (kinetic version). And i used MATLAB R2021 in Win 10, Win 11 and also in Ubuntu 16.04. After sending the goal, MATLAB Command will always display the current feedback unless I use delete, clear or rosshutdown. That was clear. When I used 'delete(gripper_actClient)' or 'clear('gripper_actClient')', feedback would no longer be subscribed. But then I would not be able to operate anything on the MATLAB, because once I pressed some button such as run, the same issue would occur. I also tried not to use these two, delete or clear. For example, if I used rosshutdown directly, there was no problem.
The strange thing was that when I used another action servers, this action server did not continuously send feedback. When I used delete or clear, there is no issue. (Update: There was also same issue with '/move_base', when i used delete(actClient).)
I don't know if this issue is in the action server I created, or in the MATLAB. The last time I used the version of R2019b, there was no problem. Because the next version of R2020 does not support generating action custom messages.
- Xin
Hi Xin,
When you are going to delete the simple action client and the goal is not yet completed, you probably don’t want the goal to be running in simple action server. So before deleting the client, please try cancelling the goal through the client.
gripper_actClient.cancelGoal();
pause(0.2);
delete(gripper_actClient);
This probably will resolve your issue. If not, please reach out to us through the MathWorks® Technical Support. We may need more information to help you out.
-Prabeen
Hi Prabeen,
Unfortunately, I still have the same problem after trying a few times. :( But thank you so much for your help, I will ask MathWorks® Technical Support for help.
- Xin

Connectez-vous pour commenter.

 Réponse acceptée

Hi Xin,
In the action server callback implementation, the Preempt logic is outside the while loop and is never reached when the goal is being cancelled. When the goal is running by the server and we send a cancelGoal request from action client to action server, due to incorrect implementation of action server callback the goal keeps running and tries to send the feedback even if the actionclient is deleted and hence the issue.
The goal will be active until we make the status of goal as preempted or aborted in the action server. In this case, this is being done outside of while loop, which makes it infinite loop. So, to avoid this error please follow one of the below solutions.
Solution 1: Move the Preempt logic into while condition as below.
while(as.isActive())
{
...
...
//----------------------- Preempt -----------------
if(as.isPreemptRequested() || !ros::ok())
{
ROS_WARN("%s: Preempted", action_name.c_str());
as.setPreempted();
success = false;
}
else
{
success = true;
ROS_INFO("\nType: %i [0 - Basic mode 1 - Pinch mode 2 - Wide mode 3 - Scissor mode] \nWidth: %i \nSpeed: %i of 255\nForce: %i of 255", goal->type, weite, gswk, kraft);
}
oldStatus++;
r.sleep();
}
The same is recommended by ROS Community : Link.
Solution 2: Change the while condition as below:
while(as.isActive() && !as.isPreemptRequested() && ros::ok())
{
....
}
Thanks,
Karthik Reddy

3 commentaires

你好,请问在哪里进行修改,这个文件是自己编写的还是MATLAB中的源代码
function [return_agent_pos_matrix,return_agent_index] = sendAllGoals(params,agent_pos,goal,ares_actClients,...
goalMsgs,ares_odomSubs, move_base_status_subs)
POSE_X = 1; %坐标 X
POSE_Y = 2; %坐标 Y
agent_num = params.agent_num;
agent_index = 1 : agent_num;
disp('sendgoal')
for i = 1:agent_num
goalMsgs(i).TargetPose.Pose.Position.X = goal(i,POSE_X);
goalMsgs(i).TargetPose.Pose.Position.Y = goal(i,POSE_Y);
goalMsgs(i).TargetPose.Pose.Orientation.Z = 0.99;
goalMsgs(i).TargetPose.Header.FrameId = 'map';
goalMsgs(i).TargetPose.Header.Stamp = rostime("now");
sendGoal(ares_actClients(i),goalMsgs(i));
end
...
% 仿真时间超过120s或者所有机器人到达设定的目标点
cancelAllGoals(ares_actClients(1));
...
return_agent_pos_matrix = agent_pos;
return_agent_index = agent_index;
end
上面的代码在运行时,控制台一直报错,程序无法停止

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Network Connection and Exploration dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by