Tahir Mahmood
Tahir Mahmood

Reputation: 313

How to import Webots controller library in a simple python script in a ROS worskapce

Is there a way to import Webots controller library in a simple python script running a ROS node inside a ROS workspace?

I have seen the Webots ROS_Python exmaple and understand the concept behind. But I am unable to import

from controller import Robot

and get the error

ImportError: No module named rospy

while running the ROS_Python example package provided already.

Edit: Changing python variable /usr/local/webots/lib/python35 finds the controller but now, a new error occurs:

ImportError: libCppController.so: cannot open shared object file: No such file or directory

Upvotes: 1

Views: 2825

Answers (1)

David Mansolino
David Mansolino

Reputation: 1733

Your approach of calling the libcontroller from within the ROS workspace is very good. This is actually the approach used for the Webots-ROS2 integration.

They are a few environmental variables that you need to set before starting your node. They are mainly LD_LIBRARY_PATH and PYTHONPATH, you can find a complete description of how to start a controller outside of Webots here:

https://www.cyberbotics.com/doc/guide/running-extern-robot-controllers#environment-variables

For the reference, this is implemented in the webots_ros2 package for ROS2:

Upvotes: 4

Related Questions