Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rclcpp::init must be called before everything? #188

Closed
reed-lau opened this issue Aug 23, 2018 · 3 comments
Closed

rclcpp::init must be called before everything? #188

reed-lau opened this issue Aug 23, 2018 · 3 comments
Labels
question Further information is requested

Comments

@reed-lau
Copy link

Recently, I find that we must call rclcpp::init (or rclpy::init in python) before everything. But in some cases, I wana just make a node and create some publishers and subscribers for later usage. For example, i would like put the node( with some publishers and subscribers) into a library. but the init make it hard todo that. In ros1 it easy to do that. Do i have some workaround to achieve it.

@wjwwood
Copy link
Member

wjwwood commented Aug 23, 2018

No, from a conceptual stand point, you must call init before creating a Node.

You should have your users (the users of your library) call init before using your library or, if you're not sure if they're going to use ROS or not, then you could check if init has been done and do it yourself if not (relies on the feature request I linked to above). There is already an issue on rclpy for checking if init has been called: ros2/rclpy#190

Another future option would be to have the ability to init multiple times in the same process (non-global init), which is a refactor we've been wanting to do for a while now. But that's not an option right now.

@wjwwood wjwwood added the question Further information is requested label Aug 23, 2018
@wjwwood
Copy link
Member

wjwwood commented Aug 23, 2018

Please close this issue if that answers your question and/or consider closing this in favor of feature requests on one of the client libraries (rclpy or rclcpp).

@reed-lau
Copy link
Author

for multiple rclpy.init() call and init fail will both throw RuntimeError. the right way to avoid multiple init is like that ?

try:
    rclpy.init()
execpt Execption:
    if rclpy.ok():
       print("multiple init")
    else:
       printf("init fail")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants