Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
localization VROB
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Böttger
localization VROB
Commits
2d552d01
Commit
2d552d01
authored
Jun 28, 2023
by
Sebastian Böttger
Browse files
Options
Downloads
Patches
Plain Diff
Add description to grafic package
parent
f9396589
No related branches found
No related tags found
1 merge request
!1
Development
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
grafic.py
+111
-7
111 additions, 7 deletions
grafic.py
with
111 additions
and
7 deletions
grafic.py
+
111
−
7
View file @
2d552d01
...
...
@@ -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
:]
...
...
@@ -52,10 +63,21 @@ class Line_Plotter:
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
]
...
...
@@ -155,6 +197,9 @@ class Track_Plotter:
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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment