ROS catkin_init_workspace not found when spawned as process by PHP

百般思念 提交于 2019-12-24 04:01:19

问题


Let me elaborate: I am trying to spawn the catkin_init_workspace from PHP, using the proc_open like so:

touch( "$dir/stderr.txt" );
chmod( "$dir/stderr.txt", 0755 );
$fp = fopen("$dir/stderr.txt", "w");
fclose($fp);

$descr = array(
                0 => array("pipe", 'r'), // stdin
                1 => array("pipe", 'w'), // stdout
                2 => array("file", "$dir/stderr.txt", "w")to file
              );

$pid = proc_open( "catkin_init_workspace", $descr, $pipes, $dir );

if (!is_resource( $pid) ) 
    throw new Exception ( "`catkin_init_workspace` exec failed");

else if ( is_resource( $pid ) )
{   
    fclose( $pipes[1] );
    $retval = proc_close( $pid );
}

The above code has worked with CMake, with GCC and other applications. However, when I try this with catkin_init_workspace, I get:

sh: 1: catkin_init_workspace: not found

Now, as far as I understand, catkin_init_workspace is a python script at:

/opt/ros/indigo/bin/catkin_init_workspace

I tried invoking it directly by using the absolute path, but that didn't work.

As a user, everything works fine. But not when I am executing via www-data, the user/group setup for Apache2.

ROS tutorial explain that I need to setup my environment variables, by running

source /opt/ros/indigo/setup.bash

Which I also tried doing via PHP, right before I invoke the proc_open, but to no avail. My understanding is that I need to setup the environment variables correctly.

Doing

export | grep ROS

shows:

declare -x ROSLISP_PACKAGE_DIRECTORIES="/home/alex/Projects/ros_ws/devel/share/common-lisp"
declare -x ROS_DISTRO="indigo"
declare -x ROS_ETC_DIR="/opt/ros/indigo/etc/ros"
declare -x ROS_MASTER_URI="http://localhost:11311"
declare -x ROS_PACKAGE_PATH="/home/alex/Projects/ros_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks"
declare -x ROS_ROOT="/opt/ros/indigo/share/ros"
declare -x ROS_TEST_RESULTS_DIR="/home/alex/Projects/ros_ws/build/test_results"

Are those the environment variables I need to setup for www-data to correctly invoke catkin?

If so, how do I pass as an env array to PHP's proc_open, those variables?


回答1:


As you already figured out, source /opt/ros/indigo/setup.bash has to be called in advance, otherwise your environment is not set up to find the ROS commands.

When you did this in PHP, I guess you used something like an additional proc_open or exec call or something similar before you call proc_open("catkin_init_workspace", ...)?
By doing this, the environment is probably only set up for this single call and it is not kept until you run catkin_init_workspace in another proc_open-call.

Possible Solution

I cannot test this here right now (no PHP installed), but the following should work:

  1. Create a simple bash script with the following content:

    #!/bin/bash
    source /opt/ros/indigo/setup.bash
    catkin_init_workspace
    
  2. In PHP, call this script instead of catkin_init_workspace


来源:https://stackoverflow.com/questions/30340534/ros-catkin-init-workspace-not-found-when-spawned-as-process-by-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!