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

How can I run ros commands through a C based system() call?

asked 2021-02-09 08:37:06 -0600

States gravatar image

updated 2021-02-09 10:46:37 -0600

I have this c based program to do some benchmarking and whatnot which I use heavily. I am a ROS noob, just starting to delve into ROS code to do some analysis.

Currently, I need to be able to call ros based commands (i.e. rosbag play, roscore, etc) through the system() function. For those who do not know how it works, it basically just executes the command (i.e. system("ls"); system("./testScript.sh").

Right now I have a bash script set up to essentially run several small things including ROS commands. Executing the script works perfectly, but executing it through system always give me an error regarding ROS_cmd: Not found.

For example:

#/bin/bash
ls
echo hi
rosbag play rotating_detergent_1_6.bag

Gives me output error of : rosbag: not found - all the while executing the ls and echo This happens independent of the ROS based command.

Any one know what is wrong?

edit: So to add, the C program is called in sudo. I noticed that the problem seems to be that system() executing in sudo does not have the appropriate ROS PATH.

For example:

echo $PATH -> /opt/ros/melodic/bin : rest
sudo su; echo $PATH -> rest

How should I go about properly addressing this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-02-10 06:06:00 -0600

carlosmR gravatar image

Hi,

Can you try and add source /opt/ros/noetic or melodic/setup.bash in the script, just before rosbag command?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2021-02-09 08:37:06 -0600

Seen: 259 times

Last updated: Feb 10 '21