Change feedback callback in ROS action client

2 visualizzazioni (ultimi 30 giorni)
Martina Lippi
Martina Lippi il 16 Mag 2022
Risposto: Maneet Kaur Bagga il 21 Set 2023
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!

Risposte (1)

Maneet Kaur Bagga
Maneet Kaur Bagga il 21 Set 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