Finding a bash file inside PyQt4 GUI

I am working on a GUI created using PyQt4 and Python 2.7 that runs various demos for Clearpath Husky running ROS Indigo. GUI toggles between running demosand visualization of my physical robot. To do this, he must switch between running demos on local ROS and ROS on my Husky. When switching between two different ROS instances, I need to be able to β€œgenerate” the devel / setup.bash file for each OS so that the packages are built correctly and the Husky visualization inside Rviz is not interrupted (errors with TF frames, for example, No tf data. Actual error : Fixed Frame [odom] doesn’t exist "and with RobotModel" The URDF model could not be parsed "). In my .bashrc, if I am a Husky setup.bash source, the visualization works fine until I try to run a local demonstration. It also happens the other way around ; while searching for local setup.bash will start be just fine local demonstration, visualization Husky violated.

Is there a way to use the python subprocess (or another alternative) to source the corresponding /setup.bash developer inside the GUI instance so that the visualization does not interrupt?

+4
source share
1 answer

Yes, it should be enough to start the installation of the script immediately before executing the ROS command, for example:

#!/usr/bin/env python

from subprocess import Popen, PIPE

shell_setup_script = "/some/path/to/workspace/devel/setup.sh"
command = "echo $ROS_PACKAGE_PATH"
cmd = ". %s; %s" % (shell_setup_script, command)

output = Popen(cmd, stdout=PIPE, shell=True).communicate()[0]
print(output)

As you can see, it is used shell=True, which will execute cmdin a subshell. It then cmdcontains . <shell_setup_script>; <command>which starts the installation of the script before executing the command. Note that the file is .shused instead .bash, since the general POSIX shell is likely to be used by Popen.

+2

Source: https://habr.com/ru/post/1649573/


All Articles