ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Creating subscriber for a custom message type

asked 2019-03-15 11:05:54 -0600

marinePhD gravatar image

I have a publisher in a package publishing a custom message type custom_gps.msg of the following format

Header header
float64 latitude      #degree
float64 longitude     #degree
float32 altitude      #WGS 84 reference ellipsoid fused by barometer
uint16  visibleSatelliteNumber #number of visible satellites

The message is published as drone_sdk/custom_gps. I'm trying to subscribe to the message in another package using a callback. In my class, I declare the callback and I add the header file generated by ROS for the custom message type

#include <drone_sdk/custom_gps.h>

//Declare Class
void fused_gps_callback(const drone_sdk::custom_gps::ConstPtr& msg);

but when I try to implement the subscriber:

void FlightControl::fused_gps_callback(const drone_sdk::custom_gps::ConstPtr& msg)
{
   // collect data here
}

I get the following error:

error: ‘custom_gps’ in namespace ‘drone_sdk’ does not name a type
 void FlightControl::fused_gps_callback(const drone_sdk::custom_gps::ConstPtr& msg)

My publisher works fine and I can see an output on rostopic echo. Also in my CMakeLists file, I believe I've added the dependency

using the following line: add_dependencies(flight_planner drone_sdk_generate_messages_cpp)

Here's what my CMAKE file looks like:

cmake_minimum_required(VERSION 2.8.3)
project(dji_flight_planner)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## 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
  drone_sdk
  nav_msgs
  roscpp
  rospy
  std_msgs
  sensor_msgs
  geometry_msgs
)


find_package(DJIOSDK REQUIRED)
find_package(Eigen3 REQUIRED)

catkin_package(
   INCLUDE_DIRS include
  CATKIN_DEPENDS
        #message_runtime    
        geometry_msgs
        nav_msgs
        std_msgs    
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
  include ${EIGEN3_INCLUDE_DIR}
)            
add_executable(drone_flight_planner src/flight_control.cpp src/flight_planner.cpp src/mobile_comm.cpp src/PID.cpp)   

target_link_libraries(drone_flight_planner
        ${catkin_LIBRARIES}
        ${EIGEN_LIBRARIES}
    ${DJIOSDK_LIBRARIES}
        )

add_dependencies(drone_flight_planner drone_sdk_generate_messages_cpp)

target_link_libraries(drone_flight_planner
  ${catkin_LIBRARIES}
  ${DJIOSDK_LIBRARIES}
)

install(DIRECTORY launch
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
)

Unfortunately, I can't use NavSatFix due to the additional field visibleSatelliteNumber in the message. Can anyone kindly point out what I'm doing wrong here?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-03-15 11:24:56 -0600

marinePhD gravatar image

This seems to be fixed. I was adding #include <drone_sdk/customgps.h> instead of what I originally quoted in the question d'oh.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-03-15 11:05:54 -0600

Seen: 464 times

Last updated: Mar 15 '19