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

ros::InvalidNameException error [closed]

asked 2017-05-22 19:52:34 -0600

tylernaes gravatar image

Hello, I am trying to create an executable node called "motor_driver_node" in a package called "motor_driver". The purpose of this node is to run a C++ file called "ego_points.cpp". The node was created when I compiled my workspace with "catkin_make" however when I attempt to run the node, I get the following error:

student@MENG2321103LT02:~/Desktop/Naes_Thesis/src$ rosrun motor_driver motor_driver_node 
terminate called after throwing an instance of 'ros::InvalidNameException'
what():  Character [.] at element [10] is not valid in Graph Resource Name [ego_points.cpp].  Valid characters are a-z, A-Z, 
0-9, / and _.
Aborted (core dumped)

Here is my CMakeLists.txt file for the motor_driver_package:

cmake_minimum_required(VERSION 2.8.3)
project(motor_driver)

find_package(catkin REQUIRED COMPONENTS
  rplidar_ros
  roscpp
  serial
  std_msgs
  sensor_msgs
  message_generation
 )

find_package(Boost REQUIRED COMPONENTS system)

add_message_files(FILES
  Motor_speeds.msg
  cartesian.msg
)

generate_messages(DEPENDENCIES
  std_msgs
  sensor_msgs
  motor_driver
)

catkin_package(
  CATKIN_DEPENDS rospy roscpp serial std_msgs message_runtime rplidar_ros sensor_msgs
)

${catkin_EXPORTED_TARGETS})

add_executable(${PROJECT_NAME}_node src/ego_points.cpp)

add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} 
   ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_node
   ${catkin_LIBRARIES}
   )

Here is my Package.XML:

<?xml version="1.0"?>
<package>
  <name>motor_driver</name>
  <version>0.0.0</version>
  <description>The motor_driver package</description>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>serial</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>rplidar_ros</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>message_runtime</run_depend>
  <run_depend>serial</run_depend>
  <run_depend>rplidar_ros</run_depend>
  <run_depend>std_msgs</run_depend>
</package>

I assume that this error doesn't have anything to do with the ego_points.cpp file itself but I am putting it here anyways:

#include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"
#include "iostream"
using namespace std;

void ScanCallback(const sensor_msgs::LaserScan::ConstPtr& scan) {
        int test = scan->ranges[1];
        cout << test << endl;
}

int main(int argc, char** argv) {
        ros::init(argc, argv, "ego_points.cpp"); //This is always the first thing that has to happen. Allows it to use ROS.

        ros::NodeHandle nh; //First NodeHandle constructed will fully initialize this node.
        ros::Subscriber scanSub;
        scanSub = nh.subscribe<sensor_msgs::LaserScan>("/Scan",10, &ScanCallback);
        ros::spin();
        return 0;
}

Can someone please let me know what I am doing wrong? Thank you in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by tylernaes
close date 2017-05-23 10:04:52.150113

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-05-22 22:36:11 -0600

ahendrix gravatar image

Your error is saying that ego_points.cpp is not a valid name (for example a Node name or Topic name).

In your file, when you call ros::init you try to set the node's name to ego_points.cpp, but this isn't a valid name:

 ros::init(argc, argv, "ego_points.cpp");

Maybe you can just use ego_points as the node name instead:

ros::init(argc, argv, "ego_points");
edit flag offensive delete link more

Comments

Thank you so much. That was the issue. It works now.

tylernaes gravatar image tylernaes  ( 2017-05-23 10:04:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-22 19:52:34 -0600

Seen: 10,862 times

Last updated: May 22 '17