mirror of
https://github.com/CopterExpress/clover.git
synced 2026-05-26 21:19:35 +00:00
vpe_publisher: implement ~reset service
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
using std::string;
|
||||
using namespace geometry_msgs;
|
||||
|
||||
bool reset_flag = false;
|
||||
string local_frame_id, frame_id, child_frame_id, offset_frame_id;
|
||||
tf2_ros::Buffer tf_buffer;
|
||||
ros::Publisher vpe_pub;
|
||||
@@ -84,13 +85,14 @@ void callback(const T& msg)
|
||||
|
||||
// offset
|
||||
if (!offset_frame_id.empty()) {
|
||||
if (msg->header.stamp - vpe.header.stamp > offset_timeout) {
|
||||
if (reset_flag || msg->header.stamp - vpe.header.stamp > offset_timeout) {
|
||||
// calculate the offset
|
||||
offset = tf_buffer.lookupTransform(local_frame_id, frame_id,
|
||||
msg->header.stamp, ros::Duration(0.02));
|
||||
// offset.header.frame_id = vpe.header.frame_id;
|
||||
offset.child_frame_id = offset_frame_id;
|
||||
br.sendTransform(offset);
|
||||
reset_flag = false;
|
||||
ROS_INFO("offset reset");
|
||||
}
|
||||
// apply the offset
|
||||
@@ -106,6 +108,13 @@ void callback(const T& msg)
|
||||
}
|
||||
}
|
||||
|
||||
bool reset(std_srvs::Trigger::Request& req, std_srvs::Trigger::Response& res)
|
||||
{
|
||||
reset_flag = true;
|
||||
res.success = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ros::init(argc, argv, "vpe_publisher");
|
||||
ros::NodeHandle nh, nh_priv("~");
|
||||
@@ -139,6 +148,8 @@ int main(int argc, char **argv) {
|
||||
local_position_sub = nh.subscribe("mavros/local_position/pose", 1, &localPositionCallback);
|
||||
}
|
||||
|
||||
auto reset_serv = nh_priv.advertiseService("reset", &reset);
|
||||
|
||||
ROS_INFO("ready");
|
||||
ros::spin();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user