tomasvr / turtlebot3_drlnav

A ROS2-based framework for TurtleBot3 DRL autonomous navigation
128 stars 18 forks source link

Small patch for commit 6f80041 #3

Open loikun opened 1 year ago

loikun commented 1 year ago

To mention that commit 6f80041 introduces import errors when running the native code. A simple patch that corrects the issue is:

diff --git a/src/turtlebot3_drl/turtlebot3_drl/common/logger.py b/src/turtlebot3_drl/turtlebot3_drl/common/logger.py
index 392ef33..cce23c7 100644
--- a/src/turtlebot3_drl/turtlebot3_drl/common/logger.py
+++ b/src/turtlebot3_drl/turtlebot3_drl/common/logger.py
@@ -1,5 +1,5 @@
 from numpy.core.numeric import Infinity
-from common.settings import COLLISION_OBSTACLE, COLLISION_WALL, TUMBLE, SUCCESS, TIMEOUT, RESULTS_NUM
+from ..common.settings import COLLISION_OBSTACLE, COLLISION_WALL, TUMBLE, SUCCESS, TIMEOUT, RESULTS_NUM
 import time
 import os

diff --git a/src/turtlebot3_drl/turtlebot3_drl/common/utilities.py b/src/turtlebot3_drl/turtlebot3_drl/common/utilities.py
index 9d506fe..96e62b2 100644
--- a/src/turtlebot3_drl/turtlebot3_drl/common/utilities.py
+++ b/src/turtlebot3_drl/turtlebot3_drl/common/utilities.py
@@ -7,7 +7,7 @@ import time
 import rclpy
 import torch
 import numpy
-from ..common.settings import REWARD_FUNCTION, COLLISION_OBSTACLE, COLLISION_WALL, COLLISION_REAL, TUMBLE, SUCCESS, TIMEOUT, RESULTS_NUM
+from ..common.settings import REWARD_FUNCTION, COLLISION_OBSTACLE, COLLISION_WALL, TUMBLE, SUCCESS, TIMEOUT, RESULTS_NUM

 import xml.etree.ElementTree as ET

Best regards.

loikun commented 1 year ago

And below a possible solution to the periodic plots (class Graph()) that were always blank during training. The issue was the redundant ax = plt.subplot(2, 2, i+1) inside the loop that set the subfigures titles. I believe it creates a new subplot that acts as an overlay and hides the initial subplot.

Besides, it seems needed to force the color of the plots for the outcome graph. Otherwise colors in the legend are not consistant along time.

Best.

diff --git a/src/turtlebot3_drl/turtlebot3_drl/common/graph.py b/src/turtlebot3_drl/turtlebot3_drl/common/graph.py
index f1e6db5..748328b 100644
--- a/src/turtlebot3_drl/turtlebot3_drl/common/graph.py
+++ b/src/turtlebot3_drl/turtlebot3_drl/common/graph.py
@@ -13,6 +13,7 @@ class Graph():
         self.session_dir = ""
         self.bin_size_average_reward = 3
         self.legend_labels = ['Unknown', 'Success', 'Collision Wall', 'Collision Dynamic', 'Timeout', 'Tumble']
+        self.legend_colors = ['b', 'g', 'r', 'c', 'm', 'y']

         self.outcome_histories = []

@@ -29,7 +30,6 @@ class Graph():
         titles = ['outcomes', 'avg critic loss over episode', 'avg actor loss over episode', 'avg reward over 10 episodes']
         for i in range(4):
             ax = self.ax[int(i/2)][int(i%2!=0)]
-            ax = plt.subplot(2, 2, i+1)
             ax.set_title(titles[i])
         self.legend_set = False

@@ -64,7 +64,7 @@ class Graph():
         if len(self.data_outcome_history) > 0:
             i = 0
             for outcome_history in self.outcome_histories:
-                self.ax[0][0].plot(xaxis, outcome_history, label=self.legend_labels[i])
+                self.ax[0][0].plot(xaxis, outcome_history, color=self.legend_colors[i], label=self.legend_labels[i])
                 i += 1
             if not self.legend_set:
                 self.ax[0][0].legend()
tomasvr commented 1 year ago

To mention that commit 6f80041 introduces import errors when running the native code. A simple patch that corrects the issue is:

Thanks, a small oversight fixed now with 0a71463

And below a possible solution to the periodic plots (class Graph()) that were always blank during training. The issue was the redundant ax = plt.subplot(2, 2, i+1) inside the loop that set the subfigures titles. I believe it creates a new subplot that acts as an overlay and hides the initial subplot.

Besides, it seems needed to force the color of the plots for the outcome graph. Otherwise colors in the legend are not consistant along time.

Best.

The graph is only updated periodically to save time by not having to redraw the plot after every episode. You should see the first results appear after the first 100 episodes which is the case for me. The line ax = plt.subplot(2, 2, i+1) does seem to be redundant so I removed it in 80f58de. Thanks!

loikun commented 1 year ago

(Even after 100 episodes, plots were blank with default python package on my computer if ax = plt.subplot(2, 2, i+1); is kept).

tomasvr commented 1 year ago

Interesting. The plots are also still not as stable as I would want them to be, any suggestions are welcome.

loikun commented 1 year ago

To clear any misunderstanding : the plots are running well on my intel and my arm ubuntu, when the redundant ax = plt.subplot(2, 2, i+1) has been removed. Also the visualization of the neural network activity is running so far. Good work and thanks again.

loikun commented 2 months ago

Interesting. The plots are also still not as stable as I would want them to be, any suggestions are welcome.

I found it frustrating to encounter a entirely blank plot initially (of course no data, but annoyingly no axes), unresponsive plot windows, and seldomly blank windows after plot updates. This small modification appears to enhance the stability of the plots: improved_graph_stability.patch

Furthermore, I advise against updating the native rosdep from ROS2 Foxy's official installation guide to rosdep2. It's unnecessary and often disrupts systems that are functioning properly with rosdep. I recommend removing the following step from the installation procedure: Next, install the correct rosdep tool sudo apt install python3-rosdep2

Best regards