Commit 9b4d80e2 authored by Tim Übelhör's avatar Tim Übelhör
Browse files

Initial commit

parents
cmake_minimum_required(VERSION 2.8.3)
project(tf_low_pass)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED
dynamic_reconfigure
roscpp
tf2_ros)
generate_dynamic_reconfigure_options(
cfg/tf_low_pass.cfg)
catkin_package(CATKIN_DEPENDS
dynamic_reconfigure
roscpp
tf2_ros)
add_executable(tf_low_pass src/tf_low_pass.cpp)
target_include_directories(tf_low_pass PUBLIC
${catkin_INCLUDE_DIRS})
add_dependencies(tf_low_pass
${PROJECT_NAME}_gencfg
${catkin_EXPORTED_TARGETS})
target_link_libraries(tf_low_pass
${catkin_LIBRARIES})
install(TARGETS tf_low_pass
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
MIT License
Copyright (c) 2019 irt - RWTH Aachen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#!/usr/bin/env python
from dynamic_reconfigure.parameter_generator_catkin import ParameterGenerator
from dynamic_reconfigure.parameter_generator_catkin import double_t
PACKAGE = "tf_low_pass"
gen = ParameterGenerator()
gen.add("smoothing_factor", double_t, 0,
"low factor leads to smoother signal", 0.5, 0, 1)
exit(gen.generate(PACKAGE, "tf_low_pass", "tf_low_pass"))
<?xml version="1.0"?>
<package format="2">
<name>tf_low_pass</name>
<version>0.0.1</version>
<description>
Low pass filter (time discrete exponential smoothing) for transforms.
</description>
<maintainer email="tim.uebelhoer@irt.rwth-aachen.de">Tim Übelhör</maintainer>
<license>MIT</license>
<author email="tim.uebelhoer@irt.rwth-aachen.de">Tim Übelhör</author>
<depend>dynamic_reconfigure</depend>
<depend>roscpp</depend>
<depend>tf2_ros</depend>
<doc_depend>doxygen</doc_depend>
<buildtool_depend>catkin</buildtool_depend>
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>
#include <dynamic_reconfigure/server.h>
#include <ros/ros.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include <tf_low_pass/tf_low_passConfig.h>
#include <tf2_ros/transform_broadcaster.h>
#include <tf2_ros/transform_listener.h>
// declaration
class TfLowPass
{
public:
TfLowPass();
private:
ros::NodeHandle nh;
ros::Timer timer;
double smoothing_factor;
std::string frame_id, child_frame_id, filtered_frame_id;
tf2_ros::Buffer tf_buffer;
tf2_ros::TransformListener tf_listener;
tf2_ros::TransformBroadcaster tf_broadcaster;
void dynamic_reconfigure_callback(tf_low_pass::tf_low_passConfig &config,
uint32_t level);
void timer_callback(const ros::TimerEvent &timerEvent);
};
// implementation
TfLowPass::TfLowPass() : tf_listener(tf_buffer)
{
ros::NodeHandle pnh("~");
pnh.param<std::string>("frame_id", frame_id, "world");
pnh.param<std::string>("child_frame_id", child_frame_id, "object");
pnh.param<std::string>("filtered_frame_id", filtered_frame_id,
"object_filtered");
double timer_duration = pnh.param("timer_duration", 0.01);
dynamic_reconfigure::Server<tf_low_pass::tf_low_passConfig> server;
server.setCallback(std::bind(&TfLowPass::dynamic_reconfigure_callback,
this,
std::placeholders::_1,
std::placeholders::_2));
timer = nh.createTimer(ros::Duration(timer_duration),
&TfLowPass::timer_callback,
this);
}
void TfLowPass::dynamic_reconfigure_callback(
tf_low_pass::tf_low_passConfig &config, uint32_t level)
{
smoothing_factor = config.smoothing_factor;
}
void TfLowPass::timer_callback(const ros::TimerEvent &timerEvent)
{
try
{
// find transform for the expected timer time (steady intervals)
geometry_msgs::TransformStamped current_msg, last_msg;
current_msg = tf_buffer.lookupTransform(frame_id, child_frame_id,
timerEvent.current_expected);
last_msg = tf_buffer.lookupTransform(frame_id, child_frame_id,
timerEvent.last_expected);
tf2::Transform current, last;
tf2::fromMsg(current_msg.transform, current);
tf2::fromMsg(last_msg.transform, last);
// apply exponential smoothing
current.setRotation(last.getRotation().slerp(
current.getRotation(), smoothing_factor));
current.setOrigin(last.getOrigin().lerp(
current.getOrigin(), smoothing_factor));
// publish
current_msg.transform = tf2::toMsg(current);
tf_broadcaster.sendTransform(current_msg);
}
catch (tf2::TransformException &ex)
{
ROS_WARN("%s", ex.what());
ros::Duration(1.0).sleep();
}
}
// init ros node in main
main(int argc, char *argv[])
{
ros::init(argc, argv, "tf_low_pass");
TfLowPass tf_low_pass;
ros::spin();
return EXIT_SUCCESS;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment