-
Notifications
You must be signed in to change notification settings - Fork 990
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
Changes from 11 commits
1f01ab8
f84b046
175479e
35d31e3
008c99e
4b45304
b958de3
98e6535
f50453c
2927dc9
c4d9757
7fd9231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ | |
|
||
#include <geometry_msgs/TransformStamped.h> | ||
|
||
#include "tf2_ros/message_filter.h" | ||
#include <message_filters/subscriber.h> | ||
|
||
|
||
namespace mavros { | ||
namespace plugin { | ||
/** | ||
|
@@ -122,7 +126,7 @@ class SetPositionTargetGlobalIntMixin { | |
template <class D> | ||
class SetAttitudeTargetMixin { | ||
public: | ||
//! Message sepecification: @p http://mavlink.org/messages/common#SET_ATTITIDE_TARGET | ||
//! Message sepecification: @p http://mavlink.org/messages/common#SET_ATTITUDE_TARGET | ||
void set_attitude_target(uint32_t time_boot_ms, | ||
uint8_t type_mask, | ||
Eigen::Quaterniond orientation, | ||
|
@@ -200,6 +204,47 @@ class TF2ListenerMixin { | |
} | ||
}); | ||
} | ||
|
||
/** | ||
* @brief start tf listener syncronized with another topic | ||
* | ||
* @param _thd_name listener thread name | ||
* @param cbp plugin callback function | ||
*/ | ||
template <class T> | ||
void tf2_start(const char *_thd_name, void (D::*cbp)(const geometry_msgs::TransformStamped &, const typename T::ConstPtr &)) | ||
{ | ||
tf_thd_name = _thd_name; | ||
|
||
tf_thread = std::thread([this, cbp]() { | ||
mavconn::utils::set_this_thread_name("%s", tf_thd_name.c_str()); | ||
|
||
mavros::UAS *m_uas_ = static_cast<D *>(this)->m_uas; | ||
ros::NodeHandle &_sp_nh = static_cast<D *>(this)->sp_nh; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Pass it via args! |
||
tf2_ros::MessageFilter<T> tf2_filter(_topic_sub, m_uas_->tf2_buffer, _frame_id, 10, _sp_nh); | ||
|
||
ros::Rate rate(static_cast<D *>(this)->tf_rate); | ||
while (ros::ok()) { | ||
// Wait up to 3s for transform | ||
if (m_uas_->tf2_buffer.canTransform(_frame_id, _child_frame_id, ros::Time(0), ros::Duration(3.0))) { | ||
try { | ||
auto transform = m_uas_->tf2_buffer.lookupTransform( | ||
_frame_id, _child_frame_id, ros::Time(0), ros::Duration(3.0)); | ||
|
||
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah I will put it outside the while loop. |
||
} | ||
catch (tf2::LookupException &ex) { | ||
ROS_ERROR_NAMED("tf2_buffer", "%s: %s", tf_thd_name.c_str(), ex.what()); | ||
} | ||
} | ||
rate.sleep(); | ||
} | ||
}); | ||
} | ||
}; | ||
} // namespace plugin | ||
} // namespace mavros |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,12 +81,12 @@ class SetpointAccelerationPlugin : public plugin::PluginBase, | |
auto accel = ftf::transform_frame_enu_ned(accel_enu); | ||
|
||
set_position_target_local_ned(stamp.toNSec() / 1000000, | ||
utils::enum_value(MAV_FRAME::LOCAL_NED), | ||
ignore_all_except_a_xyz, | ||
Eigen::Vector3d::Zero(), | ||
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 commentThe 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. |
||
ignore_all_except_a_xyz, | ||
Eigen::Vector3d::Zero(), | ||
Eigen::Vector3d::Zero(), | ||
accel, | ||
0.0, 0.0); | ||
} | ||
|
||
/* -*- callbacks -*- */ | ||
|
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.