Skip to content
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

Merged
merged 12 commits into from
Jun 28, 2017

Conversation

TSC21
Copy link
Member

@TSC21 TSC21 commented May 2, 2017

  • Sync between thrust and pose msg
  • Sync between thrust and twist msg
  • Sync between thrust and transform

Eigen::Vector3d::Zero(),
accel,
0.0, 0.0);
utils::enum_value(MAV_FRAME::LOCAL_NED),
Copy link
Member Author

@TSC21 TSC21 May 2, 2017

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>
Copy link
Member Author

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.

Copy link
Member Author

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

@TSC21 TSC21 changed the title [WIP] Plugins: setpoint_attitude: add sync between throttle and attitude [WIP] Plugins: setpoint_attitude: add sync between thrust and attitude May 2, 2017
@TSC21
Copy link
Member Author

TSC21 commented May 2, 2017

Seems like APM is also able to handle RPY together with throttle. Will add it then

@TSC21
Copy link
Member Author

TSC21 commented May 2, 2017

@rmackay9 FYI

@TSC21 TSC21 added PX4 and removed PX4 labels May 2, 2017
@TSC21 TSC21 modified the milestone: Version 0.20 May 3, 2017
@TSC21
Copy link
Member Author

TSC21 commented May 11, 2017

ping @vooon

@TSC21
Copy link
Member Author

TSC21 commented Jun 11, 2017

@vooon please review. thanks

@TSC21
Copy link
Member Author

TSC21 commented Jun 15, 2017

@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 &))
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member Author

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.

@TSC21 TSC21 force-pushed the attitude_plug_msg_sync branch 2 times, most recently from 8bf9304 to 18ffd0a Compare June 15, 2017 15:46
@TSC21
Copy link
Member Author

TSC21 commented Jun 15, 2017

@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.

@TSC21 TSC21 closed this Jun 15, 2017
@TSC21 TSC21 reopened this Jun 15, 2017
@TSC21 TSC21 closed this Jun 17, 2017
@TSC21 TSC21 reopened this Jun 17, 2017
@TSC21
Copy link
Member Author

TSC21 commented Jun 22, 2017

@vooon ok better now I kept the template for the class and only added the template for the tf2_start in case of sync needed. Can you review and merge of ok, please? Thanks

@TSC21 TSC21 closed this Jun 23, 2017
@TSC21 TSC21 reopened this Jun 23, 2017
Copy link
Member

@vooon vooon left a 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;
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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::.

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

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>?

Copy link
Member

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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't work

@TSC21
Copy link
Member Author

TSC21 commented Jun 23, 2017

but also please update config yaml in launch.

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));
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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.

@TSC21
Copy link
Member Author

TSC21 commented Jun 24, 2017

@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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/sub/thd_sub/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Member

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;
Copy link
Member

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]() {
Copy link
Member

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]() {
...

@vooon vooon merged commit df9f380 into mavlink:master Jun 28, 2017
@TSC21 TSC21 deleted the attitude_plug_msg_sync branch June 28, 2017 17:10
TSC21 added a commit to TSC21/mavros that referenced this pull request Aug 19, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants