Effacer les filtres
Effacer les filtres

Change feedback callback in ROS action client

3 vues (au cours des 30 derniers jours)
Martina Lippi
Martina Lippi le 16 Mai 2022
Hi, I'm trying to define a ROS action client with customized callbacks.
The tutorial at the link https://it.mathworks.com/help/ros/ref/simpleactionclient.html works fine but I couldn't change the callbacks of the action client. I'm using the following code to initialize the action lib which, however, does not print anything when feedback messages are received.
action_name = '/fibonacci';
action_type = 'actionlib_tutorials/Fibonacci';
[actClient,goalMsg] = rosactionclient(action_name,action_type,'DataFormat','struct');
actClient.FeedbackFcn = @(~,msg)disp(['Feedback test: ',showDetailsAnyFormat(msg)])
If I comment out the last line, I can see the default print properly. I also tried to set the field actClient.FeedbackFcn equal to a different function handle but did not succeed.
Could you please help me understanding how to set the callbacks?
Thanks in advance!

Réponses (1)

Maneet Kaur Bagga
Maneet Kaur Bagga le 21 Sep 2023
Hi Matina,
  • As per my understanding, to set the callbacks for feedback messages a custom message subscriber using the "rossubscriber" function is created. The subscriber is set to listen to the "/fibonacci/feedback" topic, which is where the feedback messages are published for the "/fibonacci" action.
  • Then define "customFeedbackCallback" function to handle the recieved feedback messages. This function will be called whenever a new feedback message is received.
Please refer to the code below:
action_name = '/fibonacci';
action_type = 'actionlib_tutorials/Fibonacci';
% Create an action client
[actClient, goalMsg] = rosactionclient(action_name, action_type, 'DataFormat', 'struct');
% Create a custom message subscriber for feedback messages
feedbackSub = rossubscriber('/fibonacci/feedback', 'actionlib_tutorials/FibonacciFeedback', @customFeedbackCallback);
% Start the action client
actClient.sendGoal(goalMsg);
% Define the custom feedback callback function
function customFeedbackCallback(~, msg)
% Custom logic for handling feedback messages
disp(['Custom Feedback: ', showDetailsAnyFormat(msg)]);
end
Please refer to the MATLAB Documentation for better understanding of the functions:
rossubscriber
rosactionclient
Hope this helps!
Thank You!
Maneet Bagga

Community Treasure Hunt

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

Start Hunting!

Translated by