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

ros commands launched using subprocess keep repeating

asked 2019-09-05 12:41:59 -0600

mt gravatar image

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.

edit retag flag offensive close merge delete

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-09-06 07:14:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-09-09 09:07:11 -0600

mt gravatar image

updated 2019-09-09 09:08:04 -0600

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-09-05 12:41:59 -0600

Seen: 331 times

Last updated: Sep 09 '19