ros commands launched using subprocess keep repeating
I am trying to execute a bunch of ROS commands using a shell script in a python node. However, everytime I launch a process using subprocess.call(['./config/reset.sh'])
, the script keeps looping and does not stop executing. The contents of the reset.sh
script are as follows:
#!/usr/bin/env bash
rosservice call /controller_manager/switch_controller [] ["arm_position_controller"] 2
rosservice call /gazebo/pause_physics
rosservice call /gazebo/set_model_configuration '{model_name: robot, joint_names: [joint_a1, joint_a2, joint_a3, joint_a4, joint_a5, joint_a6], joint_positions: [0, -1.5, 1.5, 0, 1, 0]}'
sleep 2
rosservice call /controller_manager/switch_controller ["arm_position_controller"] [] 2 &
sleep 2
rosservice call /gazebo/unpause_physics
I should add that executing the script from the terminal runs it once successfully.
Asked by mt on 2019-09-05 12:41:59 UTC
Answers
Upon further investigation, it is linked to ROS; I naively hadn't given the full details as I thought it was not necessary.
The script is being executed in a callback on a button press from the /joy
topic. The button press event lasts for several frames which is normal however this means that the script is executed several times.
Setting the argument queue_size=1
when initialising the subscriber for the /joy
topic resolves the issue although I need to test if this causes issues with other inputs from the joystick.
Asked by mt on 2019-09-09 09:07:11 UTC
Comments
This is most likely not a ROS problem, but something with how you use
subprocess
or how your script is setup.It would perhaps be better to post this question on a forum that is focused on solving these kinds of problems.
Asked by gvdhoorn on 2019-09-06 07:14:56 UTC