Giter VIP home page Giter VIP logo

drl_local_planner_ros_stable_baselines's Introduction

What is this repository for?

Installation (Else: Docker below)

  1. Standart ROS setup (Code has been tested with ROS-kinetic on Ubuntu 16.04)

  2. Install additional packages

    apt-get update && apt-get install -y \
    libqt4-dev \
    libopencv-dev \
    liblua5.2-dev \
    virtualenv \
    screen \
    python3-dev \
    ros-kinetic-tf2-geometry-msgs \
    ros-kinetic-navigation \
    ros-kinetic-rviz 
    
  3. Setup repository:

    • Clone this repository in your src-folder of your catkin workspace
    cd <path_to_catkin_ws>/src/drl_local_planner_ros_stable_baselines
    cp .rosinstall ../
    cd ..
    rosws update
    cd <path_to_catkin_ws>
    catkin_make -DCMAKE_BUILD_TYPE=Release
    

    (please install missing packages)

  4. Setup virtual environment to be able to use python3 with ros (consider also requirements.txt)

     virtualenv <path_to_venv>/venv_p3 --python=python3
     source <path_to_venv>/venv_p3/bin/activate
     <path_to_venv>/venv_p3/bin/pip install \
         pyyaml \
         rospkg \
         catkin_pkg \
         exception \
         numpy \
         tensorflow=="1.13.1" \
         gym \
         pyquaternion \ 
         mpi4py \
         matplotlib
     cd <path_to_catkin_ws>/src/drl_local_planner_forks/stable_baselines/
     <path_to_venv>/venv_p3/bin/pip install -e path_to_catkin_ws>/src/drl_local_planner_forks/stable-baselines/
    
  5. Set system-relevant variables

    • Modify all relevant pathes rl_bringup/config/path_config.ini

Example usage

  1. Train agent

    • Open first terminal (roscore):
    roscore
    
    • Open second terminal (simulationI:
    roslaunch rl_bringup setup.launch ns:="sim1" rl_params:="rl_params_scan"
    
    • Open third terminal (DRL-agent):
    source <path_to_venv>/bin/activate 
    python rl_agent/scripts/train_scripts/train_ppo.py
    
    • Open fourth terminal (Visualization):
    roslaunch rl_bringup rviz.launch ns:="sim1"
    
  2. Execute self-trained ppo-agent

    • Copy your trained agent in your "path_to_models"
    • Open first terminal:
    roscore
    
    • Open second terminal:
    roslaunch rl_bringup setup.launch ns:="sim1" rl_params:="rl_params_scan"
    
    • Open third terminal:
    source <path_to_venv>/venv_p3/bin/activate 
    roslaunch rl_agent run_ppo_agent.launch mode:="train"
    
    • Open fourth terminal:
    roslaunch rl_bringup rviz.launch ns:="sim1"
    
    • Set 2D Navigation Goal in rviz

Run pretrained Agents

Note: To be able to load the pretrained agents, you need to install numpy version 1.17.0.

<path_to_venv>/venv_p3/bin/pip install numpy==1.17

Run agent trained on raw data, discrete action space, stack size 1

  1. Copy the example_agents in your "path_to_models"
  2. Open first terminal:
    roscore
    
  3. Open second terminal for visualization:
    roslaunch rl_bringup rviz.launch ns:="sim1"
    
  4. Open third terminal:
    roslaunch rl_bringup setup.launch ns:="sim1" rl_params:="rl_params_scan"
    
  5. Open fourth terminal:
    source <path_to_venv>/venv_p3/bin/activate 
    roslaunch rl_agent run_1_raw_disc.launch mode:="train"
    

Run agent trained on raw data, discrete action space, stack size 3

  1. Step 1 - 4 are the same like in the first example
  2. Open fourth terminal:
    source <path_to_venv>/venv_p3/bin/activate 
    roslaunch rl_agent run_3_raw_disc.launch mode:="train"
    

Run agent trained on raw data, continuous action space, stack size 1

  1. Step 1 - 4 are the same like in the first example
  2. Open fourth terminal:
    source <path_to_venv>/venv_p3/bin/activate 
    roslaunch rl_agent run_1_raw_cont.launch mode:="train"
    

Run agent trained on image data, discrete action space, stack size 1

  1. Step 1 - 3 are the same like in the first example
  2. Open third terminal:
    roslaunch rl_bringup setup.launch ns:="sim1" rl_params:="rl_params_img"
    
  3. Open fourth terminal:
    source <path_to_venv>/venv_p3/bin/activate 
    roslaunch rl_agent run_1_img_disc.launch mode:="train"
    

Training in Docker

I set up a docker image, that allows you to train a DRL-agent in parallel simulation environments. Furthermore, it simplifies the deployment on a server. Using docker you don't need to follow the steps in the Installation section.

  1. Build the Docker image (This will unfortunately take about 15 minutes):
cd drl_local_planner_ros_stable_baselines/docker
docker build -t ros-drl_local_planner .

Training from scratch

  1. In start_scripts/training_params/ppo2_params, define the agents training parameters.

    Parameter Desctiption
    agent_name Number of timestamps the agent will be trained.
    total_timesteps Number of timestamps the agent will be trained.
    policy see PPO2 Doc
    gamma see PPO2 Doc
    n_steps see PPO2 Doc
    ent_coef see PPO2 Doc
    learning_rate see PPO2 Doc
    vf_coef see PPO2 Doc
    max_grad_norm see PPO2 Doc
    lam see PPO2 Doc
    nminibatches see PPO2 Doc
    noptepochs see PPO2 Doc
    cliprange see PPO2 Doc
    robot_radius The radius if the robot footprint
    rew_func The reward functions that should be used. They can be found and defined in rl_agent/src/rl_agent/env_utils/reward_container.py.
    num_stacks State representation includes the current observation and (num_stacks - 1) previous observation.
    stack_offset The number of timestamps between each stacked observation.
    disc_action_space 0, if continuous action space. 1, if discrete action space.
    normalize 0, if input should not be normalized. 1, if input should be normalized.
    stage stage number of your training. It is supposed to be 0, if you train for the first time. If it is > 0, it loads the agent of the "pretrained_model_path" and continues training.
    pretrained_model_name If stage > 0 this agent will be loaded and training can be continued.
    task_mode - "ped" for training on pedestrians only; "static" for training on static objects only; "ped_static" for training on both, static
  2. There are some predefined agents. As example I will use the ppo2_1_raw_data_disc_0 in the training session.

    docker run --rm -d \
        -v <folder_to_save_data>:/data \
        -v drl_local_planner_ros_stable_baselines/start_scripts/training_params:/usr/catkin_ws/src/drl_local_planner_ros_stable_baselines/start_scripts/training_params \
        -e AGENT_NAME=ppo2_1_raw_data_disc_0 \
        -e NUM_SIM_ENVS=4 \
        ros-drl_local_planner
    
  3. If you want to display the training in Rviz, run the docker container in the hosts network. In order to use rviz, the relevant packages need to be compiled on your machine.

    docker run --rm -d \
        -v <folder_to_save_data>:/data \
        -v drl_local_planner_ros_stable_baselines/start_scripts/training_params:/usr/catkin_ws/src/drl_local_planner_ros_stable_baselines/start_scripts/training_params \
        -e AGENT_NAME=ppo2_1_raw_data_disc_0 \
        -e NUM_SIM_ENVS=4 \
        --net=host \
        ros-drl_local_planner
    

    Now you can display the different simulation environments:

    • Simulation 1:
      roslaunch rl_bringup rviz.launch ns:="sim1"
      
    • Simulation 2:
      roslaunch rl_bringup rviz.launch ns:="sim2"
      
    • etc. ...

Train with pre-trained agents

Run agent trained on raw data, discrete action space, stack size 1

```
docker run --rm -d \
    -v drl_local_planner_ros_stable_baselines/example_agents:/data/agents \
    -v drl_local_planner_ros_stable_baselines/start_scripts/training_params:/usr/catkin_ws/src/drl_local_planner_ros_stable_baselines/start_scripts/training_params \
    -e AGENT_NAME=ppo2_1_raw_data_disc_0_pretrained \
    -e NUM_SIM_ENVS=4 \
    --net=host \
    ros-drl_local_planner
```

Run agent trained on image data, discrete action space, stack size 1

```
docker run --rm -d \
    -v drl_local_planner_ros_stable_baselines/example_agents:/data/agents \
    -v drl_local_planner_ros_stable_baselines/start_scripts/training_params:/usr/catkin_ws/src/drl_local_planner_ros_stable_baselines/start_scripts/training_params \
    -e AGENT_NAME=ppo2_1_img_disc_1_pretrained \
    -e NUM_SIM_ENVS=4 \
    --net=host \
    ros-drl_local_planner
```

drl_local_planner_ros_stable_baselines's People

Contributors

rgring avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

drl_local_planner_ros_stable_baselines's Issues

Issue loading pre-trained models

Hi,

I've been trying to load the PPO2 models

PPO2.load("example_agents/ppo2_1_raw_data_cont_0/ppo2_1_raw_data_cont_0.pkl")

And get the following error: ValueError: Cannot feed value of shape (1344, 256) for Tensor 'Placeholder_4:0', which has shape '(1600, 256)'

I did some digging, one one hand the weights saved in your pickle file are for a fc1 layer of size 1344, 256. On the other hand, the conv1d operations defined in your custom stable-baselines fork lead to a fc1 layer of size 1600, 256.

In order for the weights to be the correct size (1344, 256), the output of the second conv1d should be of size (?, 21, 64), but instead we obtain (?, 25, 64).

In common_custom_policies.py

def laser_cnn_multi_input(state, **kwargs):
    """
    1D Conv Network

    :param state: (TensorFlow Tensor) state input placeholder
    :param kwargs: (dict) Extra keywords parameters for the convolutional layers of the CNN
    :return: (TensorFlow Tensor) The CNN output layer
    """
    # scan = tf.squeeze(state[:, : , 0:kwargs['laser_scan_len'] , :], axis=1)
    scan = tf.squeeze(state[:, : , 0:kwargs['laser_scan_len'] , :], axis=1)
    wps = tf.squeeze(state[:, :, kwargs['laser_scan_len']:, -1], axis=1)
    # goal = tf.math.multiply(goal, 6)

    kwargs_conv = {}
    activ = tf.nn.relu
    layer_1 = activ(conv1d(scan, 'c1d_1', n_filters=32, filter_size=5, stride=2, init_scale=np.sqrt(2), **kwargs_conv))
    layer_2 = activ(conv1d(layer_1, 'c1d_2', n_filters=64, filter_size=3, stride=2, init_scale=np.sqrt(2), **kwargs_conv))
    layer_2f = conv_to_fc(layer_2)

where conv1d is defined here

I've been making sure to use tensorflow 1.13.1.

Could it be that you used a different version of the conv1d code during training?

Cant find LUA_INCLUDE_DIR

Hi, thanks for open-sourcing the project.

I get the following error while making the project.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: LUA_INCLUDE_DIR [(ADVANCED)]

Does the project require Lua?

Thanks,
Tanvir

How to create new scenario .xml files

Hi
Thanks for your work.

Is there any way to create new scenario xml files?
(for example, the pedsim_scenario.xml file in your project)

Thanks a lot!

Execute trained ppo-agent error

Hi,

Thanks for your great work.
There are some problems when I test the trained model.
1.I trained the model successfully.
2.However, when I execute trained ppo-agent the error showed in terminal is:
Failed to call step_simulation_ service
3.Then when I run " roslaunch rl_agent run_ppo2_agent.launch mode:="train" "
The error showed in terminal is:
File "/home/hitsz/drl_local_planner_ws/src/drl_local_planner_ros_stable_baselines/rl_agent/scripts/run_scripts/run_ppo.py", line 152, in
num_stacks=int(sys.argv[8]))
ValueError: invalid literal for int() with base 10: '__name:=run_ppo.py'
4.Then I modified the run_ppo2_agent.launch
from "node pkg="rl_agent" type="run_ppo.py" name="run_ppo.py" output="screen" args="ppo2_foo CnnPolicy_multi_input_vel2 $(arg mode) 1 0 1 ped" "
to "node pkg="rl_agent" type="run_ppo.py" name="run_ppo.py" output="screen" args="ppo2_foo CnnPolicy_multi_input_vel2 $(arg mode) 1 0 1 ped 4" /"
The error showed in 3 is solved successfully.
5.However, the other error happened in the "src/drl_local_planner_ros_stable_baselines/rl_agent/src/rl_agent/env_wrapper/ros_env_disc_img_vel.py" line 36
img_width = rospy.get_param("%s/rl_agent/img_width_pos" % ns) + rospy.get_param("%s/rl_agent/img_width_neg" % ns)
The error showed in the terminal is:
raise KeyError(key)
KeyError: 'sim1/rl_agent/img_width_pos'

Do you saw these problems?
Can you give me some suggestions?

Thanks a lot!

Cann't find the msg flatland_msgs::Step

Hello,RGring. I try to catkin_make drl_local_planner_ros_stable_baselines and there is an error that "fatal error: flatland_msgs/Step.h: No such file or directory". And I find that because toggle_setup_init.cpp(in drl_local_planner_ros_stable_baselines/rl_bringup/src ) includes <flatland_msgs/Step.h>, but in fact there is no Step.msg in flatland_msgs. So how can I solve this problem.
Thanks a lot for your answer and you codes!

Example usage-1.Train ahent

hello ,
When I tried to
python rl_agent/scripts/train_scripts/train_ppo.py

It had error here:

Traceback (most recent call last):
File "rl_agent/scripts/train_scripts/train_ppo.py", line 13, in
from rl_agent.env_wrapper.ros_env_cont_img import RosEnvContImg
File "/home/hantewin/test/src/drl_local_planner_ros_stable_baselines-master/rl_agent/src/rl_agent/env_wrapper/ros_env_cont_img.py", line 19, in
from rl_agent.env_wrapper.ros_env_img import RosEnvImg
File "/home/hantewin/test/src/drl_local_planner_ros_stable_baselines-master/rl_agent/src/rl_agent/env_wrapper/ros_env_img.py", line 15, in
from rl_agent.env_wrapper.ros_env import RosEnvAbs
File "/home/hantewin/test/src/drl_local_planner_ros_stable_baselines-master/rl_agent/src/rl_agent/env_wrapper/ros_env.py", line 32, in
from rl_agent.env_utils.task_generator import TaskGenerator
File "/home/hantewin/test/src/drl_local_planner_ros_stable_baselines-master/rl_agent/src/rl_agent/env_utils/task_generator.py", line 29, in
from pedsim_srvs.srv import SpawnPeds
ImportError: cannot import name 'SpawnPeds'

Can you help me? please,I don't know how to deal with it , I had chmod 777 als

omnidirectional or universal wheels

Hi, RGring!
May I ask if the wheels of the vehicle belong to omnidirectional or universal wheels? Is there vehocle Kinematics?
Thank you in advance!!!

Deployement the navigation learning to real robot

Hi @RGring i am new with ROS and stable-baselines. i successfully run your code. i want to deploy the trained agent to my HSR robot with laser range finder. Could you assist me which code or topic that i have to focus if i want to deploy it into my robot?

catkin_make compiling error

Hello everyone,

I am getting an error when compiling with catkin_make -DCMAKE_BUILD_TYPE=Release, it is the following:

[ 84%] Building CXX object drl_local_planner_forks/pedsim/pedsim_simulator/CMakeFiles/pedsim_simulator.dir/include/pedsim_simulator/element/moc_waypoint.cxx.o
[ 85%] Linking CXX executable /home/sasm/catkin_ws/devel/lib/pedsim_simulator/pedsim_simulator
[ 85%] Built target pedsim_simulator
Makefile:159: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

I have installed the dependencies already. When compiling with only catkin_make I get a bunch of errors from pedsim, may I compile pedsim externally?

modified diff_drive-plugin

Hi,
thanks for your work. I have read your Master Thesis, there is a modified diff_drive-plugin, where can I find the corresponding code?
Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.