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

ROS two different nodes in the same package

asked 2016-06-06 10:55:19 -0500

Geaper gravatar image

updated 2016-06-06 12:17:19 -0500

gvdhoorn gravatar image

Hello. My package name is tum_ardrone. Inside the src file I have Autopilot,StateEstimation and UINode. I Created Autopilot2,StateEstimation2 and UINode2 to run two robots.

When I run the launch file:

<launch>
<group ns="controlo_drone1">
<node name="drone_stateestimation" pkg="tum_ardrone" type="drone_stateestimation">
</node>
<node name="drone_autopilot" pkg="tum_ardrone" type="drone_autopilot">
</node>
<node name="drone_gui" pkg="tum_ardrone" type="drone_gui">
</node>
</group>

<group ns="controlo_drone2">
<node name="drone_stateestimation2" pkg="tum_ardrone" type="drone_stateestimation">
</node>
<node name="drone_autopilot2" pkg="tum_ardrone" type="drone_autopilot">
</node>
<node name="drone_gui2" pkg="tum_ardrone" type="drone_gui">
</node>
</group>
</launch>

I want to run Autopilot,StateEstimation and UINode and Autopilot2,StateEstimation2 and UINode2.

But when I run the launch file it runs two instances of Autopilot,StateEstimation and UINode and not my Autopilot2,StateEstimation2 and UINode2.

Basically I copy-paste the folders inside src ( Autopilot,StateEstimation and UINode ) and changed the code in each one to read /drone1/image_raw and /drone2_image_raw in ( Autopilot2,StateEstimation2 and UINode2 ).

The problem is that when I run roslaunch it only starts 2 instances of the nodes Autopilot,StateEstimation and UINode and not Autopilot,StateEstimation and UINode and Autopilot2,StateEstimation2 and UINode2

Any idea? Please help me.


Edit: Maybe I have to mess with CMakeLists.txt? But what can I do?

    #
# Author: Jakob Engel <jajuengel@gmail.com>
# Contributor: Stefan Wilkes <stefan.wilkes@gmail.com>
#
cmake_minimum_required(VERSION 2.8.3)
project(tum_ardrone)

## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
  ardrone_autonomy
  cv_bridge
  dynamic_reconfigure
  geometry_msgs
  sensor_msgs
  std_msgs
  std_srvs
  message_generation
  roscpp
  rospy
)

# Compile third party libs
include(ExternalProject)
ExternalProject_Add(thirdparty
    URL ${PROJECT_SOURCE_DIR}/thirdparty/thirdparty.tar.gz
    PREFIX ${CMAKE_BINARY_DIR}/thirdparty
    CONFIGURE_COMMAND ""
    BUILD_COMMAND make
    INSTALL_COMMAND ""
    BUILD_IN_SOURCE 1
)

# ------------------- add dynamic reconfigure api ------------------------------------
generate_dynamic_reconfigure_options(
  cfg/AutopilotParams.cfg
  cfg/GUIParams.cfg
  cfg/StateestimationParams.cfg
)

################################################
## Declare ROS messages, services and actions ##
################################################

## Generate messages in the 'msg' folder
add_message_files(FILES filter_state.msg)

## Generate services in the 'srv' folder
add_service_files(
    DIRECTORY srv
    FILES
    SetReference.srv
    SetMaxControl.srv
    SetInitialReachDistance.srv
    SetStayWithinDistance.srv
    SetStayTime.srv
)

## Generate added messages 
generate_messages(DEPENDENCIES std_msgs)

###################################
## catkin specific configuration ##
###################################
catkin_package(CATKIN_DEPENDS message_runtime std_msgs ardrone_autonomy)

###########
## Build ##
###########
include_directories(${catkin_INCLUDE_DIRS})

# --------------------------- stateestimation & PTAM --------------------------------
# set header ans source files
set(STATEESTIMATION_SOURCE_FILES       
    src/stateestimation/GLWindow2.cc
    src/stateestimation/GLWindowMenu.cc  
    src/stateestimation/main_stateestimation.cpp
    src/stateestimation/DroneKalmanFilter.cpp
    src/stateestimation/Predictor.cpp
  src/stateestimation/PTAMWrapper.cpp
  src/stateestimation/MapView.cpp
  src/stateestimation/EstimationNode.cpp
  src/stateestimation/PTAM/ATANCamera.cc
  src/stateestimation/PTAM/Bundle.cc
  src/stateestimation/PTAM/HomographyInit.cc
  src/stateestimation/PTAM/KeyFrame.cc
  src/stateestimation/PTAM/Map.cc
  src/stateestimation/PTAM/MapMaker.cc
  src/stateestimation/PTAM/MapPoint.cc
  src/stateestimation/PTAM/MiniPatch.cc
  src/stateestimation/PTAM/PatchFinder.cc
  src/stateestimation/PTAM/Relocaliser.cc
  src/stateestimation/PTAM/ShiTomasi.cc
  src/stateestimation/PTAM/SmallBlurryImage.cc
  src/stateestimation/PTAM/Tracker.cc
)
set(STATEESTIMATION_HEADER_FILES    
  src/stateestimation/GLWindow2.h 
  src/stateestimation/GLWindowMenu.h    
  src/stateestimation/MouseKeyHandler.h  
  src/HelperFunctions.h   
  src/stateestimation/DroneKalmanFilter.h        
  src/stateestimation/Predictor.h 
  src/stateestimation/PTAMWrapper.h
  src/stateestimation/MapView.h
  src/stateestimation/EstimationNode.h
  src/stateestimation/PTAM/ATANCamera.h
  src/stateestimation/PTAM/Bundle.h
  src/stateestimation/PTAM/customFixes.h
  src/stateestimation/PTAM/HomographyInit.h
  src/stateestimation/PTAM ...
(more)
edit retag flag offensive close merge delete

Comments

1

Please don't post answers unless you are actually answering your own question. For everything else, either edit your original question to update it, or comments (but only for short bits). I've merged your last post into your question, but please keep it in mind next time.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-06 12:18:52 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2016-06-06 11:30:16 -0500

gvdhoorn gravatar image

type="drone_autopilot"

The type attribute is what ultimately determines which binary is run, not the name.

So I guess changing drone_autopilot to drone_autopilot2 would do the trick, if I understand your question correctly.

edit flag offensive delete link more

Comments

Thank you for your help. Gives me: Error Cannot launch node of type tum_ardrone_droneautopilot2.

Geaper gravatar image Geaper  ( 2016-06-06 12:01:36 -0500 )edit

Basically I copy-paste the folders inside src ( Autopilot,StateEstimation and UINode ) and changed the code in each one to read /drone1/image_raw and /drone2/image_raw in ( Autopilot2,StateEstimation2 and UINode2 ).

Geaper gravatar image Geaper  ( 2016-06-06 12:08:39 -0500 )edit

The problem is that when I run roslaunch it only starts 2 instances of the nodes Autopilot,StateEstimation and UINode and not Autopilot,StateEstimation and UINode and Autopilot2,StateEstimation2 and UINode2

Geaper gravatar image Geaper  ( 2016-06-06 12:09:10 -0500 )edit

The problem is that just copying files is not enough, they won't get build. You'll have to add them to your CMakeLists.txt, as @jarvisschultz already mentioned.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-06 12:19:33 -0500 )edit

But the bigger issue here is: why did you create exact copies of the source files in the first place? Was it to change their name? Because that is not necessary, you can just use the name attribute in the launch file, as you discovered.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-06 12:20:20 -0500 )edit
0

answered 2016-06-06 12:24:40 -0500

Geaper gravatar image

Copy paste the code in CMakeLists.txt and replace with a 2 in the end did the trick. This is bad code development xD. Thanks anyway.

edit flag offensive delete link more
0

answered 2016-06-06 11:31:20 -0500

The name field in the <node> tag of a launch file is for specifying the graph resource name. It will override the value in any call to ros::init or rospy.init_node. The type field is for specifying which node from a given package to run. If your node is a Python node, this name should be the name of the executable Python script. If the node is a compiled C++ node, then this name should come from the executable created by catkin; this is specified in the CMakeLists.txt.

If you've created new C++ nodes, be sure you are giving them unique names in your CMakeList.txt file, be sure you have compiled your workspace, and be sure that you are using the executable names in the type field of your launch files.

edit flag offensive delete link more

Comments

Thank you for your help. Gives me: Error Cannot launch node of type tum_ardrone_droneautopilot2.

Geaper gravatar image Geaper  ( 2016-06-06 12:05:38 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-06 10:55:19 -0500

Seen: 1,691 times

Last updated: Jun 06 '16