forked from f1tenth/f1tenth_gym
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,374 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# MIT License | ||
|
||
# Copyright (c) 2020 Hongrui Zheng | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
FROM ros:foxy | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
|
||
# dependencies | ||
RUN apt-get update --fix-missing && \ | ||
apt-get install -y git \ | ||
nano \ | ||
python3-pip \ | ||
libeigen3-dev \ | ||
tmux \ | ||
ros-foxy-rviz2 | ||
RUN apt-get -y dist-upgrade | ||
RUN pip3 install transforms3d | ||
|
||
# f1tenth gym | ||
RUN git clone https://github.com/f1tenth/f1tenth_gym | ||
RUN cd f1tenth_gym && \ | ||
pip3 install -e . | ||
|
||
# ros2 gym bridge | ||
# RUN mkdir -p sim_ws/src/f1tenth_gym_ros | ||
# COPY ./f1tenth_gym_ros /sim_ws/src/f1tenth_gym_ros | ||
RUN git clone https://github.com/f1tenth/f1tenth_gym_ros.git /sim_ws/src/f1tenth_gym_ros && \ | ||
cd /sim_ws/src/f1tenth_gym_ros && \ | ||
git checkout 910789ad9029839abda0d7b6d66f46945fe5cef0 | ||
RUN source /opt/ros/foxy/setup.bash && \ | ||
cd sim_ws/ && \ | ||
apt-get update --fix-missing && \ | ||
rosdep install -i --from-path src --rosdistro foxy -y && \ | ||
colcon build | ||
|
||
# our dependencies | ||
RUN echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc && \ | ||
echo "source /sim_ws/install/setup.bash" >> ~/.bashrc && \ | ||
pip install --upgrade pip && \ | ||
# ROS2 packages | ||
source /opt/ros/foxy/setup.bash && \ | ||
ros2 pkg create --destination-directory /sim_ws/src car_node --build-type ament_python --dependencies rclpy && \ | ||
# f1tenth gym env branch v1.0.0 | ||
rm -rf /sim_ws/src/car_node/car_node && \ | ||
git clone --depth=1 https://github.com/f1tenth/f1tenth_gym.git /sim_ws/src/car_node/car_node && \ | ||
cd /sim_ws/src/car_node/car_node && \ | ||
git checkout cd56335eda43ff4e401331c461877227474a3ed4 && \ | ||
touch /sim_ws/src/car_node/car_node/__init__.py && \ | ||
# Put all maps maps in f1tenth gym ros | ||
cd / && \ | ||
git clone --single-branch --branch v1.0.0 https://github.com/f1tenth/f1tenth_racetracks.git && \ | ||
cp f1tenth_racetracks/*/*.{png,yaml} /sim_ws/src/f1tenth_gym_ros/maps/ && \ | ||
# Put all maps in car_node | ||
mkdir -p /sim_ws/src/car_node/car_node/map/ && \ | ||
mv f1tenth_racetracks /sim_ws/src/car_node/car_node/map/ | ||
|
||
COPY model-gym-ros-env/car_node/setup.py /sim_ws/src/car_node/setup.py | ||
COPY model-gym-ros-env/car_node/car_node/main.py model-gym-ros-env/car_node/car_node/wrapper.py model-gym-ros-env/car_node/car_node/map_utility.py model-gym-ros-env/car_node/car_node/setup.py /sim_ws/src/car_node/car_node/ | ||
COPY train_test /sim_ws/src/car_node/car_node/train_test | ||
|
||
RUN pip install -e /sim_ws/src/car_node/car_node && \ | ||
# pip install stable_baselines3 && \ | ||
# pip install 'shimmy>=0.2.1' && \ | ||
source /opt/ros/foxy/setup.bash && \ | ||
cd sim_ws/ && \ | ||
colcon build | ||
|
||
# RUN pip install setuptools==65.7.0 && \ | ||
# pip install -e /sim_ws/src/car_node/car_node && \ | ||
# pip install stable_baselines3 && \ | ||
# pip install 'shimmy>=0.2.1' && \ | ||
# cd sim_ws/ && \ | ||
# colcon build | ||
|
||
# pip install gym[atari,accept-rom-license]==0.19.0 && \ | ||
# pip install 'stable-baselines3[extra]' && \ | ||
# pip install -e /sim_ws/src/car_node/car_node && \ | ||
# source /opt/ros/foxy/setup.bash && \ | ||
# cd sim_ws/ && \ | ||
# colcon build | ||
|
||
WORKDIR '/sim_ws' | ||
ENTRYPOINT ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# MIT License | ||
|
||
# Copyright (c) 2020 Hongrui Zheng | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
version: '3' | ||
services: | ||
sim: | ||
image: manuandru/f1tenth-gym-ros-model-env:latest | ||
# volumes: | ||
# - .:/sim_ws/src/f1tenth_gym_ros | ||
# - ../src:/sim_ws/src/ | ||
environment: | ||
- DISPLAY=novnc:0.0 | ||
networks: | ||
- x11 | ||
stdin_open: true | ||
tty: true | ||
novnc: | ||
image: theasp/novnc:latest | ||
environment: | ||
- DISPLAY_WIDTH=1728 | ||
- DISPLAY_HEIGHT=972 | ||
ports: | ||
- "8080:8080" | ||
networks: | ||
- x11 | ||
networks: | ||
x11: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
# from __future__ import print_function | ||
import numpy as np | ||
import rclpy | ||
from rclpy.node import Node | ||
|
||
#ROS Imports | ||
from sensor_msgs.msg import LaserScan | ||
from ackermann_msgs.msg import AckermannDriveStamped | ||
|
||
|
||
import gym | ||
from stable_baselines3 import PPO | ||
from car_node.wrapper import F110_Wrapped | ||
from f110_gym.envs.base_classes import Integrator | ||
from car_node.map_utility import get_map, get_formatted_map, map_ext | ||
from car_node.wrapper import convert_range | ||
|
||
timestep = 0.01 | ||
tensorboard_path = './train_test/' | ||
map = "BrandsHatch" | ||
path = get_map(map) | ||
map_path = get_formatted_map(path) | ||
device = 'cpu' | ||
|
||
STEER_SCALE = 0.5 | ||
SPEED_SCALE = 0.7 | ||
|
||
class PPOModelEvaluator(Node): | ||
|
||
def __init__(self): | ||
super().__init__('wall_follow_node') | ||
|
||
#Topics & Subs, Pubs | ||
lidarscan_topic = '/scan' | ||
drive_topic = '/drive' | ||
|
||
# Model & Env | ||
self.eval_env = gym.make('f110_gym:f110-v0', map=map_path, map_ext=map_ext, num_agents=1, timestep=timestep, integrator=Integrator.RK4) | ||
self.eval_env = F110_Wrapped(self.eval_env, random_map=False) | ||
self.eval_env.set_map_path(path) | ||
self.model = PPO.load("/sim_ws/src/car_node/car_node/train_test/best_global_model", self.eval_env, device=device) | ||
self.vec_env = self.model.get_env() | ||
|
||
# ROS | ||
self.lidar_sub = self.create_subscription(LaserScan, lidarscan_topic, self.lidar_callback, 10) | ||
self.drive_pub = self.create_publisher(AckermannDriveStamped, drive_topic, 10) | ||
|
||
def lidar_callback(self, data): | ||
d = np.array(data.ranges, dtype=np.float64) | ||
d = convert_range(d, [data.angle_min, data.angle_max], [-1, 1]) | ||
|
||
action, _states = self.model.predict(d, deterministic=True) | ||
action = self.eval_env.un_normalise_actions(action) | ||
|
||
self.get_logger().info(f'{action[0], action[1]}') | ||
|
||
drive_msg = AckermannDriveStamped() | ||
drive_msg.header.stamp = self.get_clock().now().to_msg() | ||
drive_msg.header.frame_id = "laser" | ||
drive_msg.drive.steering_angle = action[0] * STEER_SCALE | ||
drive_msg.drive.speed = action[1] * SPEED_SCALE | ||
self.drive_pub.publish(drive_msg) | ||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
node = PPOModelEvaluator() | ||
rclpy.spin(node) | ||
node.destroy_node() | ||
rclpy.shutdown() | ||
|
||
if __name__=='__main__': | ||
main() |
Oops, something went wrong.