[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

Jonathan Binney via ros-users


I wrote a simple package with class and library to subscribe and publish using rclcpp.

My CMakeLists.txt is:

    cmake_minimum_required(VERSION 3.5)

    project(testpackage)

    if(NOT WIN32)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
    endif()

    find_package(ament_cmake REQUIRED)
    find_package(rclcpp REQUIRED)
    find_package(std_msgs REQUIRED)

    include_directories(include
    ${rclcpp_INCLUDE_DIRS}
                        ${rmw_implementation_INCLUDE_DIRS}
                        ${std_msgs_INCLUDE_DIRS})

    add_library(test_lib
    src/test.cpp
    )

    target_link_libraries(test_lib ${rclcpp_LIBRARIES} ${rmw_implementation_LIBRARIES} ${std_msgs_LIBRARIES})

    add_executable(test_node src/test_node.cpp)
    add_dependencies(test_node test_lib)
    target_link_libraries(test_node test_lib)

    install(
      DIRECTORY include/${PROJECT_NAME}
      DESTINATION include
    )

    install(
      TARGETS test_lib test_node
      ARCHIVE DESTINATION lib
      LIBRARY DESTINATION lib
      RUNTIME DESTINATION bin
    )

    ament_package()


It builds well. However when I try to run the package like this:
 
`ros2 run testpackage test_node`
it says no executable found.

Is there something like roscore in ros2 to have the ROS_MASTER and ros services running? I have sourced `install/local_setup.bash` as given in the tutorials.

I have built using the command =  `ament build --symlink-install --only-package testpackage`
Also i realised, my library is not created inside install/lib/.





---
[Visit Topic](https://discourse.ros.org/t/cannot-run-executable-and-lib-using-ros2-run-after-building-using-ament/2640/1) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

Jonathan Binney via ros-users


Your CMake installs you binary to bin, but ros2 run only looks in the "libexec" folder (actually `lib/pkg`) for executables. Your binary is just on the PATH, so you don't need ros2 run to easily execute it.

See our examples for how to install to libexec:

https://github.com/ros2/examples/blob/9a819e007c13a5fb243641d300d6300306750cb0/rclcpp/minimal_publisher/CMakeLists.txt#L26





---
[Visit Topic](https://discourse.ros.org/t/cannot-run-executable-and-lib-using-ros2-run-after-building-using-ament/2640/2) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Thanks WIlliam ! could we do something like `rostopic pub` from the terminal in ros2?

Is it going to be like ros2 topic pub [args]?? @wjwwood





---
[Visit Topic](https://discourse.ros.org/t/cannot-run-executable-and-lib-using-ros2-run-after-building-using-ament/2640/3) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Also, I realized when I run my executable like `ros2 run testpackage test_node` ... and then do `ros2 node list.` It shows me the right name. However, when I exit my program (Ctrl+C) I still happen to find my `ros2 node` if I do a `ros2 node list`. The instance continues to be there which is sometimes also seen in ROS 1 if a large number of nodes are running however not for just one node.

Another point is my topic names. Even after exiting my running executable `ros2 topic list` still, shows the topic names. I changed the topic names in my program and built it again and ran it, however, the topic names weren't changed or I don't know if it's the old instance running. Regardless of that, I tried killing the node by `ros2 node kill --all` however seems like that is not the command to kill anymore.





---
[Visit Topic](https://discourse.ros.org/t/cannot-run-executable-and-lib-using-ros2-run-after-building-using-ament/2640/4) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


[quote="arunava_nag, post:3, topic:2640"]
Is it going to be like ros2 ropic pub /test_topic std_msgs/msgs/String "hello there"??
[/quote]

Please see `ros2 topic pub --help` for an example.

[quote="arunava_nag, post:4, topic:2640"]
Also, I realized when I run my executable like ros2 run testpackage test_node  and then do ros2 node list. It shows me the right name. However, when I exit my program (Ctrl+C) I still happen to find my ros2 node if I do a ros2 node list.
[/quote]

For me it works for the `demo_nodes_cpp` / `demo_nodes_py` `talker` and `listener` using FastRTPS on Ubuntu using Beta 3. Maybe you can provide more information what environment / version / nodes you are experiencing it with.





---
[Visit Topic](https://discourse.ros.org/t/cannot-run-executable-and-lib-using-ros2-run-after-building-using-ament/2640/5) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Cannot run executable and lib using ros2 run after building using ament

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


I am using Ubuntu 16.04 Beta 2.
This is my simple package: https://github.com/arunavanag591/test_ros2

When I try this
`ros2 topic pub /test_topic std_msgs/String "hello"`

It throws me this:

    Traceback (most recent call last):
      File "/home/artc/ros2_ws/install/bin/ros2", line 9, in <module>
        load_entry_point('ros2cli==0.0.0', 'console_scripts', 'ros2')()
      File "/home/artc/ros2_ws/install/lib/python3.5/site-packages/ros2cli/cli.py", line 64, in main
        rc = extension.main(parser=parser, args=args)
      File "/home/artc/ros2_ws/install/lib/python3.5/site-packages/ros2topic/command/topic.py", line 38, in main
        return extension.main(args=args)
      File "/home/artc/ros2_ws/install/lib/python3.5/site-packages/ros2topic/verb/pub.py", line 43, in main
        return main(args)
      File "/home/artc/ros2_ws/install/lib/python3.5/site-packages/ros2topic/verb/pub.py", line 47, in main
        return publisher(args.message_type, args.topic_name, args.values)
      File "/home/artc/ros2_ws/install/lib/python3.5/site-packages/ros2topic/verb/pub.py", line 78, in publisher
        set_msg_fields(msg, values_dictionary)
      File "/home/artc/ros2_ws/install/lib/python3.5/site-packages/ros2topic/verb/pub.py", line 92, in set_msg_fields
        for field_name, field_value in values.items():
    AttributeError: 'str' object has no attribute 'items'





---
[Visit Topic](https://discourse.ros.org/t/cannot-run-executable-and-lib-using-ros2-run-after-building-using-ament/2640/6) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Unable to publish from command line

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Did you try passing a yaml dictionnary as the help message suggests?
`ros2 topic pub /test_topic std_msgs/String "data: Hello World"`

Copied from:
```$ ros2 topic pub --help
usage: ros2 topic pub [-h] topic_name message_type [values]

Publish a message to a topic

positional arguments:
  topic_name    Name of the ROS topic to publish to (e.g. '/chatter')
  message_type  Type of the ROS message (e.g. 'std_msgs/String')
  values        Values to fill the message with in YAML format (e.g. "data:
                Hello World"), otherwise the message will be published with
                default values
```





---
[Visit Topic](https://discourse.ros.org/t/unable-to-publish-from-command-line/2640/7) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Unable to publish from command line

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Ah thanks yes I tried earlier, however I totally did not give the space between data: and Hello. Thanks much





---
[Visit Topic](https://discourse.ros.org/t/unable-to-publish-from-command-line/2640/8) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Unable to publish from command line

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


Just a quick question, do we create metapackages in ament ros2 the same way as in ros1?





---
[Visit Topic](https://discourse.ros.org/t/unable-to-publish-from-command-line/2640/9) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Unable to publish from command line

Jonathan Binney via ros-users
In reply to this post by Jonathan Binney via ros-users


[quote="arunava_nag, post:8, topic:2640"]
however I totally did not give the space between data: and Hello.
[/quote]

Ah yeah the space is not obvious given that the help message wraps the line just after the `:`. That tricked me recently as well. The error message has been [improved recently](https://github.com/ros2/ros2cli/pull/48) to make it clearer that a YAML dictionary is expected.

[quote="arunava_nag, post:9, topic:2640, full:true"]
Just a quick question, do we create metapackages in ament ros2 the same way as in ros1?
[/quote]

This has been [brought up recently](https://github.com/ros2/common_interfaces/pull/41) but it hasn't been decided yet if metapackages should exist as ament packages or if they should be stored in a central place given that they are for producing binaries only and should not be used as dependencies





---
[Visit Topic](https://discourse.ros.org/t/unable-to-publish-from-command-line/2640/10) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>