Ask Your Question
0

Compile error: ‘Init’ is not a member of ‘ros’

asked 2014-06-07 11:09:52 -0600

Kirill gravatar image

updated 2014-06-07 11:11:49 -0600

Ubuntu 12.04, ROS Hydro

Workspace:

$ echo $ROS_PACKAGE_PATH 

/home/kirill/dev/rosbook:/opt/ros/hydro/share:/opt/ros/hydro/stacks

Created ROS pack:

roscd chapter2_tutorials/src/
ls

bin  build  CMakeLists.txt  include  lib  mainpage.dox  Makefile  manifest.xml  src

Test ROS Package has two source files:

cd src
ls

example1_a.cpp  example1_b.cpp

example1_a.cpp:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

int main(int argc, char **argv)
{
  ros::Init(argc, argv, "example1_a");
  ros::NodeHandle n;
  ros::Publisher chatter_pub = n.advertise<std_
msgs::String>("message", 1000);
  ros::Rate loop_rate(10);
  while (ros::ok())
  {
    std_msgs:String msg;
    std::stringstream ss;
    ss << " I am the example_a node ";
    msg.data = ss.str();
    //
    chatter_pub.publish(msg);
    ros::spinOnce();
    loop_rate.sleep();
  }
  return 0;
}

example1_b.cpp:

#include "ros/ros.h"
#include "std_msgs/String.h"

void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}

int main (int argc, char **argv)
{
  ros::Init(argc, argv, "example1_b");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subcribe("message", 1000, chatterCallback);
  ros::spin();
  return 0;
}

CMakeLists.txt:

rosed chapter2_tutorials CMakeLists.txt

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})

rosbuild_add_executable(example1_a src/example1_a.cpp)
rosbuild_add_executable(example1_b src/example1_b.cpp)

Making package:

kirill@kirill-Aspire-E1-571G:~/dev/rosbook/chapter2_tutorials$ rosmake chapter2_tutorials
[ rosmake ] rosmake starting...                                                                                                                 
[ rosmake ] Packages requested are: ['chapter2_tutorials']                                                                                      
[ rosmake ] Logging to directory /home/kirill/.ros/rosmake/rosmake_output-20140607-195627                                                       
[ rosmake ] Expanded args ['chapter2_tutorials'] to:
['chapter2_tutorials']                                                                     
[rosmake-0] Starting >>> catkin [ make ]                                                                                                        
[rosmake-0] Finished <<< catkin ROS_NOBUILD in package catkin
 No Makefile in package catkin                                                    
[rosmake-0] Starting >>> genmsg [ make ]                                                                                                        
[rosmake-0] Finished <<< genmsg ROS_NOBUILD in package genmsg
 No Makefile in package genmsg                                                    
[rosmake-0] Starting >>> genlisp [ make ]                                                                                                       
[rosmake-1] Starting >>> genpy [ make ]                                                                                                         
[rosmake-0] Finished <<< genlisp ROS_NOBUILD in package genlisp
 No Makefile in package genlisp                                                 
[rosmake-2] Starting >>> gencpp [ make ]                                                                                                        
[rosmake-0] Starting >>> console_bridge [ make ]                                                                                                
[rosmake-3] Starting >>> rospack [ make ]                                                                                                       
[rosmake-3] Finished <<< rospack ROS_NOBUILD in package rospack
 No Makefile in package rospack                                                 
[rosmake-1] Finished <<< genpy ROS_NOBUILD in package genpy
 No Makefile in package genpy                                                       
[rosmake-2] Finished <<< gencpp ROS_NOBUILD in package gencpp
 No Makefile in package gencpp                                                    
[rosmake-3] Starting >>> roslib [ make ]                                                                                                        
[rosmake-2] Starting >>> message_generation [ make ]                                                                                            
[rosmake-1] Starting >>> roslang [ make ]                                                                                                       
[rosmake-0] Finished <<< console_bridge ROS_NOBUILD in package console_bridge
 No Makefile in package console_bridge                            
[rosmake-0] Starting >>> cpp_common [ make ]                                                                                                    
[rosmake-2] Finished <<< message_generation ROS_NOBUILD in package message_generation
 No Makefile in package message_generation                
[rosmake-2] Starting >>> rosgraph [ make ]                                                                                                      
[rosmake-1] Finished <<< roslang ROS_NOBUILD in ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2014-06-07 11:32:06 -0600

dornhege gravatar image

ros::init not ros::Init.

edit flag offensive delete link more

Comments

hi, dornhege! Yeah, you are right. I should to code with more care and attention. There were a several errors with literal errors. This resource was helpful for me - http://docs.ros.org/hydro/api/roscpp/html/classros_1_1NodeHandle-members.html Or we can just google this "class ros::NodeHandle" to found out members with right case sensitive. Thanks! Regards, Kirill.

Kirill gravatar imageKirill ( 2014-06-07 18:33:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-06-07 11:09:52 -0600

Seen: 1,791 times

Last updated: Jun 07 '14