Subscribe vs. waitForMessage for a 30hz topic
I would like to read a topic (which is published at ~30hz) at specific moments in the execution of my code. This Q&A shows I have 2 ways to proceed:
- waitForMessage (from here) which is a "fairly heavy operation" and requires "frequent publishing" (how heavy? how frequent?);
- subscribing and updating a class member via the subscriber's callback, and using said member directly (from the second part of this).
I went the second way but realized I don't understand how to pass-by-reference (not good enough, at least, and I have found this which is related, but isn't working), so I went with:
void MyClass::frankaStateCallback(const franka_msgs::FrankaState& msg)
{
current_franka_state_ = msg;
}
where current_franka_state_
is of type franka_msgs::FrankaState
(i.e. here) which is not the simplest/lightest of messages.
I'm therefore wondering if I should use the other way or if someone could help me with understanding how to properly use a pointer in this case.
EDIT: as per lucascoelho's request
sub_franka_states_ = nh.subscribe("franka_state_controller/franka_states", 1, &MyClass::frankaStateCallback, this);
This is in the body of the constructor (wrote it following this page), but I don't understand how the problem would lie here.
Maybe you are not initializing the subscriber method in a proper way. Please have a look at this page, it shows how to use a callback from an object
If you could edit your question and add the lines that you are setting up the subscriber it could also be helpful for identifying your problem