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

error: ‘bag’ does not name a type

asked 2016-12-20 08:09:02 -0500

Mandeep Singh gravatar image

updated 2016-12-21 00:03:29 -0500

I have added rosbag dependencies in cmakefile.txt and package.xml and included essential ros headers but still catkin_make shows errors ( this not name a type that not name a type). Please help i really dont understand whats going wrong.

i have copied file from this ros tutorial : (http://wiki.ros.org/rosbag/Code%20API)

Make Error :

 error: ‘bag’ does not name a type
 bag.open("~/bagfiles/2016-12-20-18-18-30.bag", rosbag::bagmode::Read);
 ^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:11:1: error: ‘topics’ does not name a type
 topics.push_back(std::string("chatter"));
 ^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:12:1: error: ‘topics’ does not name a type
 topics.push_back(std::string("numbers"));
 ^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:16:2: error: expected unqualified-id before ‘if’
 foreach(rosbag::MessageInstance const m, view)
  ^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:16:44: error: expected unqualified-id before ‘else’
 foreach(rosbag::MessageInstance const m, view)
                                            ^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:16:897: error: expected unqualified-id before ‘else’
 foreach(rosbag::MessageInstance const m, view)

rosplay.cpp

#include <rosbag/bag.h>
#include <rosbag/view.h>

#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH

rosbag::Bag bag;
bag.open("~/bagfiles/2016-12-20-18-18-30.bag", rosbag::bagmode::Read);

std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));

rosbag::View view(bag, rosbag::TopicQuery(topics));

foreach(rosbag::MessageInstance const m, view)
{
    std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
    if (s != NULL)
        ASSERT_EQ(s->data, std::string("foo"));

    std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
    if (i != NULL)
        ASSERT_EQ(i->data, 42);
}

bag.close();

There goes my Cmakefiles.txt : Highlighted part added for rosplay.cpp

cmake_minimum_required(VERSION 2.8.3)
project(proto1_moveit)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake-modules)  ####CHANGE
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)  ####CHANGE
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)  ####CHANGE

find_package(catkin REQUIRED COMPONENTS
             moveit_core
             moveit_ros_planning
             moveit_ros_planning_interface
             pluginlib
             rosbag
             cmake_modules
             geometric_shapes
             joint_trajectory_controller
             joint_trajectory_action
             moveit_simple_controller_manager
             industrial_robot_simulator
             actionlib
             actionlib_msgs
             control_msgs
             trajectory_msgs
             moveit_msgs
             shape_msgs
             chef_arm_kinematics
)

find_package(MySqlClient REQUIRED) ###CHANGE

find_package(Boost REQUIRED system filesystem date_time thread)

find_package(Eigen REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR} ${EIGEN_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})

include_directories(${MYSQL_INCLUDE_DIRS}) ###CHANGE

catkin_package(
  INCLUDE_DIRS 
    include
  LIBRARIES 
    ik_utils_proto
    pick_proto
    place_proto
    dispense_proto
    stir_proto
  CATKIN_DEPENDS 
    rosbag
    moveit_core
    moveit_ros_planning_interface
    interactive_markers
    std_msgs
    actionlib_msgs
    shape_msgs
    chef_arm_kinematics
)

add_definitions(${MYSQL_DEFINITIONS}) ##CHANGE

add_library(pick_proto src/pick_proto.cpp) 
target_link_libraries(pick_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS pick_proto
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_library(place_proto src/place_proto.cpp) 
target_link_libraries(place_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS place_proto
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_library(dispense_proto src/dispense_proto.cpp) 
target_link_libraries(dispense_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS dispense_proto
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_library(stir_proto src/stir_proto.cpp) 
target_link_libraries(stir_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS stir_proto
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_executable(environment_proto src/environment_proto.cpp)
target_link_libraries(environment_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS environment_proto DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

**add_executable(rosplay src/rosplay.cpp)
target_link_libraries(rosplay ${catkin_LIBRARIES} ${Boost_LIBRARIES}) 
install(TARGETS rosplay DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})**

install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
install ...
(more)
edit retag flag offensive close merge delete

Comments

Please include your CMakeLists.txt and package.xml and an example of the kind of errors you are getting.

We cannot help you without the proper information.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-20 08:15:33 -0500 )edit

I have added more info please help me.

Mandeep Singh gravatar image Mandeep Singh  ( 2016-12-20 23:59:47 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2016-12-21 01:07:38 -0500

Mandeep Singh gravatar image

updated 2016-12-21 01:08:21 -0500

I have solved the problem : the cpp file given on ros tutorial is not ready for direct usage (f). We need to include it in int main() and include a few more libraries like #include <std_msgs string.h=""> #include <std_msgs int32.h=""> and remove ASSERT_EQ as it will further give error.

rosplay.cpp

#include <ros/ros.h>
#include <rosbag/view.h>

#include <gtest/gtest.h>
#include <std_msgs/String.h>
#include <std_msgs/Int32.h>
#include <boost/foreach.hpp>

#define foreach BOOST_FOREACH

int main (int argc, char** argv)
{
    ros::init (argc, argv, "bag_it");
    rosbag::Bag bag;
    bag.open("~/bagfiles/2016-12-20-18-18-30.bag", rosbag::bagmode::Read);

    std::vector<std::string> topics;
    topics.push_back(std::string("chatter"));
    topics.push_back(std::string("numbers"));

    rosbag::View view(bag, rosbag::TopicQuery(topics));

    foreach(rosbag::MessageInstance const m, view)
    {
        std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
        if (s != NULL)
            std::cout << s->data << std::endl;

        std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
        if (i != NULL)
            std::cout << i->data << std::endl;
    }

    bag.close();
    return (0);
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-20 08:08:10 -0500

Seen: 2,246 times

Last updated: Dec 21 '16