Tf broadcaster dynamically changing values
Hi guys,
my robot's sensor angle can be changed during its run so the transformations have to be dynamically changed. For now I have a node which reads pointclouds from the sensor, detects the angle of the sensor and publishes this information on a topic. Then I have a node which publishes transformations (a simple tf broadcaster):
ros::Rate rate(1000);
while(nodeHandler.ok()){
broadcaster.sendTransform(
tf::StampedTransform(
tf::Transform(tf::Quaternion(0, detectedAngle, 0, 1), tf::Vector3(0.12, 0.0, 0.28)),
ros::Time::now(),"base_footprint", "camera_link"));
rate.sleep();
}
I need the broadcaster node to read the message from the angle topic and use it in a detectedAngle
variable, so it's always up to date. Now I'm not sure how the code should look like. I probably cannot use the typical subscriber syntax with ros::spin()
as I have this cycle in the tf broadcaster. I could write a simple subscriber to the angle topic and publish the transformation in its callback function but I'm not sure if the transformation frequency would be enough (it would be the frequency of the sensor), or would be? Isn't there any tool in ros which could be used here? I imagine something like: the tf broadcaster node publishes transformation with some rate (e.g. 100Hz) and if some message come to the angle topic, the broadcaster updates the detectedAngle
variable with the new value and continues publishing transformations.
I deleted my previous answer as I'd missed the:
bit.
Is
detectedAngle
a 1D value? If it's only a yaw fi, you could model it as a joint and then still use urdf +robot_state_publisher
to get 'dynamically updated TFs'.just noticed this:
is this correct? a
Quaternion
is not an RPY triple, so ifdetectedAngle
is supposed to be a pitch value (fi), then the resultingQuaternion
will most likely never match it.I was not sure if it is correct, I didn't run it yet. I just put it there as I thought these are the same values as the arguments for
static_transform_publisher
. And to answer ifdetectedAngle
is a 1D value, it is one float number representing the angle.Finally I used urdf, state publisher and joint publisher and its working. I'd mark your answer as correct but its deleted. Thank you anyway for showing me the right direction.