Skip to content

Commit 9d65d33

Browse files
committed
update state manager for general tf support
1 parent 8553806 commit 9d65d33

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

state_manager/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ ament_target_dependencies( state_manager_node
3737
std_srvs
3838
nav_msgs
3939
tf2
40+
tf2_ros
41+
tf2_geometry_msgs
4042
)
4143

4244
install(TARGETS

state_manager/include/state_manager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <tf2/LinearMath/Quaternion.h>
2222
#include <tf2/impl/utils.h>
2323
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
24+
#include <tf2_ros/buffer.h>
2425

2526
#include "freyja_msgs/msg/current_state.hpp"
2627
#include "freyja_msgs/msg/asctec_data.hpp"
@@ -77,6 +78,11 @@ class StateManager: public rclcpp::Node
7778
std::string filter_type_;
7879
FreyjaFilters pose_filter_;
7980
FreyjaFilters rate_filter_;
81+
82+
/* tf related */
83+
std::string tf_base_frame_;
84+
std::string tf_my_frame_;
85+
std::unique_ptr<tf2_ros::Buffer> tf_buffer_;
8086

8187
/* containers for handling gps data */
8288
double home_lat_, home_lon_;
@@ -93,6 +99,7 @@ class StateManager: public rclcpp::Node
9399
StateManager();
94100
/* launch-time parameter specifies which one to pick */
95101
void initPixhawkManager();
102+
void initTfManager();
96103
void initAsctecManager();
97104
void initMocapManager();
98105
void initCameraManager();
@@ -101,6 +108,9 @@ class StateManager: public rclcpp::Node
101108
rclcpp::Subscription<TFStamped>::SharedPtr mocap_data_sub_;
102109
void mocapCallback( const TFStamped::ConstSharedPtr ) __attribute__((hot));
103110

111+
rclcpp::TimerBase::SharedPtr tf_timer_;
112+
void timerTfCallback();
113+
104114
// /* Callback handler for asctec_onboard_data */
105115
// rclcpp::Subscription asctec_data_sub_;
106116
// void asctecDataCallback( const freyja_msgs::msg::AsctecData::ConstSharedPtr );

state_manager/src/callback_implementations.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ void StateManager::mocapCallback( const TFStamped::ConstSharedPtr msg )
8383
state_pub_ -> publish( state_msg );
8484
}
8585

86+
void StateManager::timerTfCallback()
87+
{
88+
/* This is a timer callback */
89+
static TFStamped tform;
90+
91+
tform = tf_buffer_ -> lookupTransform( tf_my_frame_, tf_base_frame_, tf2::TimePointZero );
92+
93+
}
94+
8695
// void StateManager::asctecDataCallback( const freyja_msgs::AsctecData::ConstPtr &msg )
8796
// {
8897
// double time_since = (ros::Time::now() - lastUpdateTime_).toSec();

state_manager/src/state_manager.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ StateManager::StateManager() : Node( rclcpp_NODE_NAME )
2525

2626
if( state_source_ == "mocap" )
2727
initMocapManager();
28+
else if( state_source_ == "tf_mocap" )
29+
initTfManager();
2830
// else if( state_source_ == "asctec" )
2931
// initAsctecManager();
3032
// else if (state_source_ == "apm" )
@@ -90,6 +92,24 @@ void StateManager::initMocapManager()
9092
std::bind( &StateManager::mocapCallback, this, _1 ) );
9193
}
9294

95+
void StateManager::initTfManager()
96+
{
97+
declare_parameter<int>( "tf_rate", 200 );
98+
declare_parameter<std::string>( "state_base_frame", "map" );
99+
declare_parameter<std::string>( "state_my_frame", "agent_1" );
100+
101+
int tf_lookup_rate;
102+
float tf_timer_freq;
103+
104+
get_parameter( "tf_rate", tf_lookup_rate );
105+
get_parameter( "state_base_frame", tf_base_frame_ );
106+
get_parameter( "state_my_frame", tf_my_frame_ );
107+
108+
tf_timer_ = rclcpp::create_timer( this, get_clock(), std::chrono::duration<float>(1.0/tf_lookup_rate),
109+
std::bind(&StateManager::timerTfCallback, this) );
110+
tf_buffer_ = std::make_unique<tf2_ros::Buffer>( get_clock() );
111+
}
112+
93113
// void StateManager::initAsctecManager()
94114
// {
95115
// declare_parameter<std::string>( "vehicle_topic", "/asctec_onboard_data" );

0 commit comments

Comments
 (0)