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


asked 2016-09-13 04:45:21 -0500

Tvlad gravatar image

updated 2016-09-13 04:46:19 -0500

Hello, I have a question to all of you. For example, I have simple publisher and subscriber. The topic name "/test". I want click button on my PHP website and in the case when I will do this the data on a topic will change. If I want to publish some data from command line, such as:

rostopic pub -1 /test std_msgs/Int32 10000

It works.

The problem is:

Can I make the next situation on my PHP file

exec("rostopic pub -1 /test std_msgs/Int32 10000")

Please help me.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-09-13 11:03:35 -0500

gvdhoorn gravatar image

This should be possible. Make sure your web server (or PHP interpreter) has the proper environment setup when it tries to invoke rostopic (ie: equivalent of source setup.bash).

Alternative (and I think preferred): use rosbridge_suite and use the JSON interface from your PHP script.

edit flag offensive delete link more


Thank you for your answer. Are you mean the next way:

exec("source /home/pi/catkin_ws/devel/setup.bash && rostopic pub -1 /test std_msgs/Int32 10000")


exec("source /opt/ros/kinetic/setup.bash && /opt/ros/kinetic/bin/rostopic pub -1 /test std_msgs/Int32 10000")
Tvlad gravatar image Tvlad  ( 2016-09-14 00:30:41 -0500 )edit

That depends: if all you want is rostopic and std_msgs, then you only need to source the base distribution. If you need custom messages and / or a custom node, then I think you'd need to source your workspace.

gvdhoorn gravatar image gvdhoorn  ( 2016-09-14 00:56:40 -0500 )edit

I need a custom node with std_msgs. I tried both of the ways but still does not work. What can be the problem?

Tvlad gravatar image Tvlad  ( 2016-09-14 01:31:24 -0500 )edit

I don't know. What does exec(..) return? Any error status/message? What "doesn't work" exactly?

gvdhoorn gravatar image gvdhoorn  ( 2016-09-14 13:03:09 -0500 )edit

Question Tools



Asked: 2016-09-13 04:45:21 -0500

Seen: 1,687 times

Last updated: Sep 13 '16