From 2d552d0103ca68beb2993ef8e85c63a572b36fe0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20B=C3=B6ttger?=
 <sebastian.boettger@stud.hs-bochum.de>
Date: Wed, 28 Jun 2023 22:30:11 +0200
Subject: [PATCH] Add description to grafic package

---
 grafic.py | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 111 insertions(+), 7 deletions(-)

diff --git a/grafic.py b/grafic.py
index a88a975..c8f8759 100644
--- a/grafic.py
+++ b/grafic.py
@@ -19,7 +19,15 @@ import random
 
 
 #%% class
+"""
+# This class can plot values as a consistant graph.
+# With the method update you can insert a new value to the graph and the grafic will refresh automaticly.
+"""
 class Line_Plotter:
+    """
+    # The constructor needs a title, for the diagramm as well as a lable for the x and y axses.
+    # Optional you can set the number of values that are plottet on the x-axses.
+    """
     def __init__(self, title, x_lable, y_lable ,x_scale = 100):
         self.counter = 0
         self.fig = plt.figure()
@@ -35,7 +43,10 @@ class Line_Plotter:
         self.fig.canvas.draw()
         self.fig.canvas.flush_events()
         
-    
+    """
+    # The method update insert a new value to the graph an refresh the graph automaticly.
+    # It needs only the value as a parameter.
+    """
     def update(self, value):
         self.y = np.append(self.y, value)
         self.y = self.y[1:]
@@ -51,11 +62,22 @@ class Line_Plotter:
         self.ax.set_ylim(self.y.min(), self.y.max())
         
         self.counter = self.counter + 1
-        
+    
+    """
+    # The method close ensures that the window is closed.
+    """
     def close(self):
         plt.close(self.fig)
 
+"""
+# This class can plot values as a continues graph.
+# It can plot the values with a given timedelta to the last known value.
+"""
 class Line_Plotter_Time:
+    """
+    # The constructor needs a title, for the diagramm as well as a lable for the x and y axses.
+    # Optional you can set the number of values that are plottet on the x-axses.
+    """
     def __init__(self, title, x_lable, y_lable ,x_scale = 100):
         self.x_scale = x_scale
         self.fig = plt.figure()
@@ -69,7 +91,11 @@ class Line_Plotter_Time:
         self.ax.set_xlabel(x_lable)
         self.ax.set_ylabel(y_lable)
         
-    
+    """
+    # The method update insert a new value to the graph on the timestamp delte which is given an refresh the graph automaticly.
+    # It needs the value and a given time delta to the last value as a parameter.
+    # The timedelta will be summed to the hight time of a datapoint in the digramm and will plot at this time the new value.
+    """
     def update(self, value, time_delta):
         self.y = np.append(self.y, value)
         self.x = np.append(self.x, self.x[self.x.size -1] + time_delta)
@@ -85,10 +111,20 @@ class Line_Plotter_Time:
         self.ax.set_xlim(self.x[0],self.x[self.x.size -1])
         self.ax.set_ylim(self.y.min(), self.y.max())
     
+    """
+    # The method close ensures that the window is closed.
+    """
     def close(self):
         plt.close(self.fig)
 
+"""
+# This class can plot the racetrack and highlighte the current section.
+# It should also display a little robot an update the position, but unfortunately, it's not function properly.
+"""
 class Track_Plotter:
+    """
+    # This constructor needs a set of trackparts which contains a URL to the backgroundimage for the plot.
+    """
     def __init__(self, background_url, track, ratio = 1):
         self.background = img.imread(background_url)
         self.track = track
@@ -104,6 +140,9 @@ class Track_Plotter:
         plt.show(block=False)
         plt.pause(0.1)
     
+    """
+    # Wich this funtion you get a set of trackparts. The URLs are not includet in this git.
+    """
     def get_set_of_trackparts_3():
         # Track plotting
         trackparts = []
@@ -127,6 +166,9 @@ class Track_Plotter:
         
         return (background, track)
     
+    """
+    # This method is internal used to create the robot. 
+    """
     def __create_triangle(self, position, direction):
         # Definiere die Position der Ecke des Dreiecks
         x = position[0]
@@ -154,7 +196,10 @@ class Track_Plotter:
         # Erstelle das Dreieck
         self.__triangle = patches.Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, fill=True, facecolor='green', alpha=0.5)
         return self.__triangle
-        
+    
+    """
+    # This function is used to select a section and set up that backgorundimage
+    """
     def select_trackpart(self, trackpart_name):
         trackpart = self.track[self.track.name == trackpart_name]
         image = img.imread(trackpart.iloc[0].image_url)
@@ -162,12 +207,20 @@ class Track_Plotter:
         self.fig.canvas.draw()
         self.fig.canvas.flush_events()
     
+    """
+    # This funktion is used to set the robot to the startposition of a trackpart.
+    # Currently the robot simulation is not usable!
+    """
     def set_robot_to_trackpart(self, trackpart_name):
         trackpart = self.track[self.track.name == trackpart_name]
         self.robot_position = trackpart.iloc[0].start_position
         self.robot_direction = trackpart.iloc[0].start_direction
         self.update_robot()
     
+    """
+    # This funktion is used to move the robot forward.
+    # Currently the robot simulation is not usable!
+    """
     def move_robot_forward(self, distance):
         x,y = self.robot_position
         theta = np.deg2rad(self.robot_direction)
@@ -176,14 +229,26 @@ class Track_Plotter:
         self.robot_position = (x_new, y_new)
         self.update_robot()
     
+    """
+    # This funktion is used to set the robot to a specific position on the plot.
+    # Currently the robot simulation is not usable!
+    """
     def move_robot_to_position(self, position):
         self.robot_position += position
         self.update_robot()
     
+    """
+    # This funktion is used to rotate the robot.
+    # Currently the robot simulation is not usable!
+    """
     def rotate_robot(self, rotation):
         self.robot_direction += rotation
         self.update_robot()
     
+    """
+    # This funktion enable the plotting of the robot.
+    # Currently the robot simulation is not usable!
+    """
     def activate_robot(self):
         print("Do not use this method!!! - activate_robot")
         self.robot_is_active = True
@@ -194,6 +259,10 @@ class Track_Plotter:
         self.fig.canvas.draw_idle()
         self.fig.canvas.flush_events()
     
+    """
+    # This funktion is used to update the position and orientation of the robot on the plot.
+    # Currently the robot simulation is not usable!
+    """
     def update_robot(self):
         print("Do not use this method!!! - update_robot")
         if self.robot_is_active:
@@ -225,11 +294,19 @@ class Track_Plotter:
             # self.fig.canvas.blit(self.fig.bbox)
             # self.fig.canvas.flush_events()
             
-            
+    """
+    # This funktion close the window.
+    """
     def close(self):
         plt.close(self.fig)
 
+"""
+# This class creates a little Dashborad with the most important information from the robot and the localization.
+"""
 class Dashboard:
+    """
+    # This constructor needs nothing and set up all values for the dashboard.
+    """
     def __init__(self):
         self.current_section_type = ""
         self.last_sections_type = ""
@@ -265,46 +342,73 @@ class Dashboard:
         self.window.update_idletasks()
         self.window.update()
 
+    """
+    # This function sets the current section type to the dashboard
+    """
     def set_current_section_type(self, section_type):
         self.current_section_type = section_type
         self.label_current_section_type.config(text="current section type: " + self.current_section_type)
         self.update_window()
     
+    """
+    # This function sets the last sections type to the dashboard
+    """
     def set_last_sections_type(self, last_sections_type):
         self.last_sections_type = last_sections_type
         self.label_last_sections_type.config(text="last sections type: " + self.last_sections_type)
         self.update_window()
     
+    """
+    # This function sets the value enter new section to the dashboard
+    """
     def set_enter_new_section(self, enter_new_section):
         self.enter_new_section = enter_new_section
         self.label_enter_new_section.config(text="enter new section: " + self.enter_new_section)
         self.update_window()
     
+    """
+    # This function sets the last known section to the dashboard
+    """
     def set_last_known_section(self, last_known_section):
         self.last_known_section = last_known_section
         self.label_last_known_section.config(text="last known section: " + self.last_known_section)
         self.update_window()
     
+    """
+    # This function sets the counter fail localization to the dashboard
+    """
     def set_count_fail_loc(self, count_fail_loc):
         self.count_fail_loc = count_fail_loc
         self.label_count_fail_loc.config(text="count fail loc: " + str(self.count_fail_loc))
         self.update_window()
     
+    """
+    # This function sets the x position of the robot to the dashboard
+    """
     def set_x_position(self, x_position):
         self.x_position = x_position/1000
         self.label_x_position.config(text="x position: " + str(self.x_position) + " m")
         self.update_window()
-        
+    
+    """
+    # This function sets the y position of the robot to the dashboard
+    """  
     def set_y_position(self, y_position):
         self.y_position = y_position/1000
         self.label_y_position.config(text="y position: " + str(self.y_position) + " m")
         self.update_window()
-        
+    
+    """
+    # This function sets the driven distance on the section to the dashboard
+    """
     def set_driven_distance_on_section(self, driven_distance_on_section):
         self.driven_distance_on_section = driven_distance_on_section/1000
         self.label_driven_distance_on_section.config(text="driven distance on section: " + str(self.driven_distance_on_section) + " m")
         self.update_window()
     
+    """
+    # This function update the dashboard it's self. without this method, the dashboard will not refresh.
+    """
     def update_window(self):
         self.window.update_idletasks()
         self.window.update()
-- 
GitLab