Working with Webots ==================== In this section we will discuss how to work with webots-based environments. The instructions here assume that you work with a Linux OS. Working with webots-based environments requires that you install the Webots simulator. General instructions how to achieve this you can find at `Installing Webots `_. In addition, you can also install Webots from source: `Installation of the Webots Development Environment `_. For Linux boxes instructions can be found at `Linux installation `_. Assuming that you have Webots installed on your machine, you need to install ``rlenvscpp`` with ``ENABLE_WEBOTS`` set to on when configuring the library i.e. .. code-block:: mkdir build cd build cmake -DENABLE_WEBOTS=ON .. make install You will need to edit the main CMakeLists.txt file and specify the paths for the variables ``WEBOTS_INCLUDE_DIRS`` and ``WEBOTS_LIB_DIRS`` to match your environment. Notice that ``cmake`` will not look into any default locations for this variables so you need to fill these in even if you do a system wide installation. .. code-block:: ... IF(ENABLE_WEBOTS) # we have webots include the directories SET(WEBOTS_LIB_DIRS "set/your/path") SET(WEBOTS_INCLUDE_DIRS "set/your/path") INCLUDE_DIRECTORIES(${WEBOTS_INCLUDE_DIRS}) LINK_DIRECTORIES(${WEBOTS_LIB_DIRS}) SET(RLENVSCPP_WEBOTS ON) ELSE() MESSAGE( WARNING "Building without Webots.") ENDIF() ... Once the ``rlenvscpp`` library is built, edit your ``~/.bashrc`` and amend the variable ``LD_LIBRARY_PATH`` as follows: .. code-block:: export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/your/path/to/rlenvscpplib" We need this in order for the Webots simulator to be able to find ``rlenvscpplib``. Source the updated ````~/.bashrc`` file: .. code-block:: source ~/.bashrc or open a new terminal. You are now ready to develop and use environments for your application. Follow the Webots tutorials in order to do so: `Tutorial 1: Your First Simulation in Webots (30 Minutes) `_ Once your environment is ready, edit the associated Makefile and amend the following lines .. code-block:: ... CFLAGS = -std=c++20 -Wno-unused-result INCLUDE = -I"/your/path/to/rlenvs_from_cpp/src" LIBRARIES = -L"/your/path/to/rlenvscpplib/dir" -lrlenvscpplib ... Update the controller source file according to your needs. Here is an example taken from ``rlenvscpp`` examples: .. code-block:: #include "rlenvs/rlenvscpp_config.h" #ifdef RLENVSCPP_WEBOTS #include "rlenvs/rlenvs_types_v2.h" #include "rlenvs/envs/time_step.h" #include "rlenvs/envs/webots_envs/epuck_simple_grid_world.h" #include #include #include #include #include #include #include #include // All the webots classes are defined in the "webots" namespace using namespace webots; using namespace rlenvscpp; namespace webots_example_1{ using rlenvscpp::envs::webots_envs::EpuckSimpleGridWorld; using rlenvscpp::uint_t; } // This is the main program of your controller. // It creates an instance of your Robot instance, launches its // function(s) and destroys it at the end of the execution. // Note that only one instance of Robot should be created in // a controller program. // The arguments of the main function can be specified by the // "controllerArgs" field of the Robot node int main() { using namespace webots_example_1; try // create the environment EpuckSimpleGridWorld env; // create the environment...this initializes // the robot sensors and motors std::unordered_map options; options["right_motor_init_velocity"] = 1.25; // 2.0; options["left_motor_init_velocity"] = 1.25; // 2.0; options["sim_time_step"] = std::any(static_cast(64)); // above this reading we assume there is a wall options["max_dist_sensor_reading_goal"] = 120.0; // we don't want the robot to be far away from the // wall either options["min_dist_sensor_reading_goal"] = 80.0; env.make("v0", options); // reset the environment...this will reload the // whole simulation world env.reset(); // access the robot auto& robot = env.get_robot(); auto time_step = robot.get_basic_time_step(); std::cout<<"Basic time step used: "< int main(){ std::cout<<"This example requires Webots enabled. Rebuild the library with -DENABLE_WEBOTS=ON"<