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

Run and Close a ros package inside python program

asked 2022-07-24 19:38:03 -0500

farhad-bat gravatar image

Hello,

I have a python program that has a GUI.

I want when a user clicks on a button to execute a ROS package. Also, I have another button, when the user clicks, I want to close the running package.

I do not know how to do that.

I know how to open the program:

```

# calibration command
    calib_command_str = "rosrun camera_calibration cameracalibrator.py --size {}x{} {} {} --square {} right:={} left:={} left_camera:={} right_camera:={}".format(interior_corner_hor_axis, interior_corner_ver_axis, camera_service_check_value, approx_str, square_len, right_camera_image_topic, left_camera_image_topic, left_camera_image_super_topic, right_camera_image_super_topic)

    os.system(calib_command_str)

```

However, I do not how to close it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-25 03:23:08 -0500

ljaniec gravatar image

In ROS, killing a node is as follows

rosnode kill node_name

What the rosnode kill does is send a SIGINT to the NodeHandle, and what the node should do is deconstruct its classes and free the NodeHandle (in correctly written code).

You can use os.system with it too.

For Custom SIGINT Handler (in C++) you can use this tutorial:

edit flag offensive delete link more

Comments

If this answers your question, you can mark it as correct, so it will be visible in the question queue :)

ljaniec gravatar image ljaniec  ( 2022-07-25 11:00:23 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-07-24 19:38:03 -0500

Seen: 46 times

Last updated: Jul 25 '22