Commit 4cc655a6 authored by Rousseau Vincent's avatar Rousseau Vincent
Browse files

WIP publish odom position from navsat

parents
cmake_minimum_required(VERSION 2.8.3)
project(navsat_to_odom)
set(${PROJECT_NAME}_CATKIN_DEPS roscpp sensor_msgs nav_msgs)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS ${${PROJECT_NAME}_CATKIN_DEPS})
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a run_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES navsat_to_odom
CATKIN_DEPENDS ${${PROJECT_NAME}_CATKIN_DEPS}
# DEPENDS system_lib
)
###########
## Build ##
###########
include_directories(
include ${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(navsat_to_odom
# src/${PROJECT_NAME}/navsat_to_odom.cpp
# )
## Declare a C++ executable
add_executable(navsat_to_odom_node src/navsat_to_odom.cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(navsat_to_odom_node
${catkin_LIBRARIES}
Geographic
)
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables and/or libraries for installation
# install(TARGETS navsat_to_odom navsat_to_odom_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_navsat_to_odom.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
<?xml version="1.0"?>
<package format="2">
<name>navsat_to_odom</name>
<version>0.0.0</version>
<description>The navsat_to_odom package</description>
<maintainer email="vincent.rousseau@irstea.fr">Vincent Rousseau</maintainer>
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>GPLv3</license>
<author email="vincent.rousseau@irstea.fr">Vincent Rousseau</author>
<buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>
<depend>sensor_msgs</depend>
<depend>nav_msgs</depend>
<depend>geographiclib</depend>
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
</package>
#include <ros/ros.h>
#include <sensor_msgs/NavSatFix.h>
#include <geometry_msgs/TwistStamped.h>
#include <nav_msgs/Odometry.h>
#include <GeographicLib/LocalCartesian.hpp>
class NavsatToOdom {
public:
NavsatToOdom(ros::NodeHandle n) :
n_(n),
is_enu_initialized_(false)
{
sub_fix_ = n_.subscribe("navsat/fix", 10, &NavsatToOdom::fixCallback, this);
sub_vel_ = n_.subscribe("navsat/vel", 10, &NavsatToOdom::velCallback, this);
pub_odom_ = n_.advertise<nav_msgs::Odometry>("navsat/odom", 1);
}
void fixCallback(const sensor_msgs::NavSatFix::ConstPtr & fix)
{
if(fix->status.status != sensor_msgs::NavSatStatus::STATUS_NO_FIX)
{
if(is_enu_initialized_ == false)
{
ROS_INFO_STREAM("enu_initialized");
enu_.Reset(fix->latitude, fix->longitude);
is_enu_initialized_ = true;
}
double east, north, up;
enu_.Forward(fix->latitude, fix->longitude, 0.0, east, north, up);
nav_msgs::Odometry odom;
odom.header.stamp = ros::Time::now();
odom.header.frame_id = "odom";
odom.pose.pose.position.x = east;
odom.pose.pose.position.y = north;
pub_odom_.publish(odom);
}
}
void velCallback(const geometry_msgs::TwistStamped::ConstPtr & fix)
{
}
private:
ros::NodeHandle n_;
ros::Subscriber sub_fix_, sub_vel_;
ros::Publisher pub_odom_;
GeographicLib::LocalCartesian enu_;
std::atomic<bool> is_enu_initialized_;
};
int main(int argc, char** argv)
{
ros::init(argc, argv, "navsat_to_odom");
ros::NodeHandle n;
NavsatToOdom ntoo(n);
ROS_INFO_STREAM("navsat_to_odom");
ros::spin();
return 0;
}
\ No newline at end of file
Markdown is supported
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