-
Notifications
You must be signed in to change notification settings - Fork 983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Plugins: setpoint_attitude: add sync between thrust and attitude #700
Conversation
TSC21
commented
May 2, 2017
•
edited
edited
- Sync between thrust and pose msg
- Sync between thrust and twist msg
- Sync between thrust and transform
…pics to be sent together
Eigen::Vector3d::Zero(), | ||
accel, | ||
0.0, 0.0); | ||
utils::enum_value(MAV_FRAME::LOCAL_NED), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied the uncrustify to the wrong file initially so that's why this changed.
#include <geometry_msgs/PoseStamped.h> | ||
#include <geometry_msgs/TwistStamped.h> | ||
#include <std_msgs/Float64.h> | ||
#include <mavros_msgs/Float32Stamped.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed as Float64
doesn't have a stamp so to sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I'm changing this to a custom msg, maybe I should change to Thrust.msg
only
Seems like APM is also able to handle RPY together with throttle. Will add it then |
@rmackay9 FYI |
ba54714
to
35d31e3
Compare
ping @vooon |
@vooon please review. thanks |
@vooon this is tested. friendly ping! |
* @param _thd_name listener thread name | ||
* @param cbp plugin callback function | ||
*/ | ||
void tf2_sync_start(const char *_thd_name, void (D::*cbp)(const geometry_msgs::TransformStamped &, const mavros_msgs::Thrust::ConstPtr &)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that change. Should be better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change took me half day to figure a way to work lol If you have a different proposal that works the same way or better I accept it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides I'm doing some updates on mavteleop
that require that this PR is merged to work properly. Also, this change is required to setpoint_attitude
to work as it should, and I don't think this has to be delayed more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only optimization I can think of is generalize the type of message we are syncing the tf listener with, instead of with the thrust only. That way we have a generalized way of syncing different types of topics with the transform.
8bf9304
to
18ffd0a
Compare
18ffd0a
to
b958de3
Compare
@vooon I think right now this is the best that we can get right (a generic function template that syncs any topic with a transform listener). Besides now the templates have the same name but different classes/typenames, which in terms of code structure is better on the plugin side (is not a template friend class but a friend class with function templates). And this is working. So unless you have a better proposal, I think this is good to go. |
@vooon ok better now I kept the template for the class and only added the template for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see why you need two threads in TF2ListenerMixin.
Other looks ok, but also please update config yaml in launch.
std::thread tf_thread_1; | ||
std::thread tf_thread_2; | ||
std::string tf_thd_name_1; | ||
std::string tf_thd_name_2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you need two threads? Only one tf_start()
should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are using one thread for tf2_start
in one plugin and another tf2_start
for another plugin which is using sync (the case of setpoint_ attitude
), shouldn't two different threads be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each plugin instance (object) have their std::thread
object.
It is not shared between plugins, only inside class instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will use one only then.
@@ -46,26 +51,46 @@ class SetpointAttitudePlugin : public plugin::PluginBase, | |||
|
|||
bool tf_listen; | |||
|
|||
typedef message_filters::sync_policies::ApproximateTime<geometry_msgs::PoseStamped, mavros_msgs::Thrust> SyncPoseThrust; | |||
typedef message_filters::sync_policies::ApproximateTime<geometry_msgs::TwistStamped, mavros_msgs::Thrust> SyncTwistThrust; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use using
instead typedef
.
using SyncPoseThrust = mesage_filters::sync_polices::ApproximateTime<geometry_msgs::PoseStamped, mavros_msgs::Thrust>;
Also may be good to move out of method, e.g. place in std_plugins::
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
// tf params | ||
sp_nh.param("tf/listen", tf_listen, false); | ||
sp_nh.param<std::string>("tf/frame_id", tf_frame_id, "map"); | ||
sp_nh.param<std::string>("tf/child_frame_id", tf_child_frame_id, "aircraft"); | ||
sp_nh.param("tf/rate_limit", tf_rate, 10.0); | ||
|
||
// thrust msg subscriber to sync | ||
message_filters::Subscriber<mavros_msgs::Thrust> thrust_sub(sp_nh, "thrust", 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why subscriber here? How it can survive when initialize() returns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah mistake. I will put on public
and then initialize here, as before.
"Listen to desired attitude transform " | ||
<< tf_frame_id << " -> " << tf_child_frame_id); | ||
|
||
tf2_start<mavros_msgs::Thrust>("AttitudeSpTFSync", &SetpointAttitudePlugin::transform_cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message type should be deduced from callback type automagically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I should remove <mavros_msgs::Thrust>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and in theory is should still works :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't work
Ok sure. |
_frame_id, _child_frame_id, ros::Time(0), ros::Duration(3.0)); | ||
|
||
tf2_ros::MessageFilter<T> tf2_filter(_topic_sub, m_uas_->tf2_buffer, _frame_id, 10, _sp_nh); | ||
tf2_filter.registerCallback(boost::bind(cbp, static_cast<D *>(this), transform, _1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks weird. Creating new filter on each TF rx not good. And _topic_sub
not initialized, there no topic name.
Do you test that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had _top_sub
initialized before in a proper way. I don't know why I changed it. I would roll back and initialize it on plugin and use it here on the template by applying static_cast<D *>(this)->
. Sorry for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating new filter on each TF rx not good.
Yeah I will put it outside the while loop.
@vooon done. Do you have a suggestion on how #700 (diff) could work? |
@@ -106,7 +106,10 @@ class SetpointAttitudePlugin : public plugin::PluginBase, | |||
std::string tf_frame_id; | |||
std::string tf_child_frame_id; | |||
|
|||
message_filters::Subscriber<mavros_msgs::Thrust> sub; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/sub/thd_sub/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General "sub" bad for later support, thats why i want more specific name like thd_sub
.
And to solve problem with tf_start()
, just pass by reference.
Or move whole tf_start()
code out of mixin, since it looks specific to that plugin.
Or you plan to use that variation somewhere else?
std::string &_frame_id = static_cast<D *>(this)->tf_frame_id; | ||
std::string &_child_frame_id = static_cast<D *>(this)->tf_child_frame_id; | ||
|
||
message_filters::Subscriber<T> &_topic_sub = static_cast<D *>(this)->sub; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass it via args!
{ | ||
tf_thd_name = _thd_name; | ||
|
||
tf_thread = std::thread([this, cbp]() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void tf2_start(const char *_thd_name, message_fileters::Subscriber<T> &tsub, ...)
...
th_therad = std::thread([this, cbp, tsub]() {
...
mavlink#700) * plugins: setpoint_attitude: add sync between throttle and attitude topics to be sent together * plugins: typo correction: replace throttle with thrust * plugins: msgs: setpoint_attitude: replaces Float32Stamped for Thrust msg * plugins: setpoint_attitude: add sync between twist and thrust (RPY+Thrust) * setpoint_attitude: update the logic of thrust normalization verification * setpoint_attitude: implement sync between tf listener and thrust subscriber * TF sync listener: generalize topic type that can be syncronized with TF2 * TF2ListenerMixin: keep class template, use template for tf sync method only * TF2ListenerMixin: fix and improve sync tf2_start method * general update to yaml config files and parameters * setpoint_attitude: add note on Thrust sub name * setpoint_attitude: TF sync: pass subscriber pointer instead of binding it