Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
db-guided-mrmp
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rmoan2
db-guided-mrmp
Commits
e50d671e
Commit
e50d671e
authored
5 months ago
by
rachelmoan
Browse files
Options
Downloads
Patches
Plain Diff
Fix the weird oscillations in trajectory plotting. Was caused by a rounding error.
parent
eafdfb6c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
guided_mrmp/planners/db_guided_mrmp.py
+24
-37
24 additions, 37 deletions
guided_mrmp/planners/db_guided_mrmp.py
guided_mrmp/simulator.py
+17
-17
17 additions, 17 deletions
guided_mrmp/simulator.py
with
41 additions
and
54 deletions
guided_mrmp/planners/db_guided_mrmp.py
+
24
−
37
View file @
e50d671e
...
...
@@ -18,32 +18,8 @@ from guided_mrmp.controllers.utils import get_ref_trajectory, compute_path_from_
from
guided_mrmp.controllers.mpc
import
MPC
from
guided_mrmp.utils.library
import
Library
def
initialize_libraries
(
library_fnames
=
[
"
guided_mrmp/database/2x3_library
"
,
"
guided_mrmp/database/3x3_library
"
,
"
guided_mrmp/database/5x2_library
"
]):
"""
Load the 2x3, 3x3, and 2x5 libraries. Store them in self.lib-x-
Inputs:
library_fnames - the folder containing the library files
"""
# Create each of the libraries
print
(
f
"
Loading libraries. This usually takes about 10 seconds...
"
)
lib_2x3
=
Library
(
library_fnames
[
0
])
lib_2x3
.
read_library_from_file
()
lib_3x3
=
Library
(
library_fnames
[
1
])
lib_3x3
.
read_library_from_file
()
lib_2x5
=
Library
(
library_fnames
[
2
])
lib_2x5
.
read_library_from_file
()
return
[
lib_2x3
,
lib_3x3
,
lib_2x5
]
class
GuidedMRMP
:
def
__init__
(
self
,
env
,
robots
,
dynamics_models
,
T
,
DT
,
settings
):
def
__init__
(
self
,
env
,
robots
,
dynamics_models
,
T
,
DT
,
libs
,
settings
):
"""
inputs:
- robots (list): list of Robot class objects
...
...
@@ -79,7 +55,7 @@ class GuidedMRMP:
self
.
scaling_factor
=
self
.
settings
[
'
simulator
'
][
'
scaling_factor
'
]
self
.
libs
=
initialize_libraries
()
self
.
libs
=
libs
def
ego_to_global
(
self
,
robot
,
mpc_out
):
"""
...
...
@@ -219,6 +195,8 @@ class GuidedMRMP:
curr_state
=
np
.
array
([
0
,
0
,
0
])
x_mpc
,
u_mpc
=
mpc
.
step
(
curr_state
,
target_traj
,
np
.
array
(
r
.
control
))
self
.
add_vis_target_traj
(
screen
,
self
.
scaling_factor
,
r
,
x_mpc
)
# only the first one is used to advance the simulation
...
...
@@ -228,6 +206,12 @@ class GuidedMRMP:
# print(f"control = {u_mpc}")
next_trajs
.
append
(
self
.
ego_to_global
(
r
,
x_mpc
))
# use matplotlib to plot the trajectories
# for r, traj in zip(self.robots, next_trajs):
# plt.plot(traj[0], traj[1], label=r.label)
# plt.legend()
# plt.show()
return
next_controls
,
next_trajs
def
advance
(
self
,
screen
,
state
,
time
,
dt
=
0.1
):
...
...
@@ -241,11 +225,14 @@ class GuidedMRMP:
"""
# get the next control for each robot
next_desired_controls
,
trajectories
=
self
.
get_next_controls_and_trajectories
(
screen
)
if
self
.
settings
[
'
model_predictive_controller
'
][
'
parallelize
'
]:
next_desired_controls
,
trajectories
=
self
.
get_next_controls_and_trajectories_parallel
(
screen
)
else
:
next_desired_controls
,
trajectories
=
self
.
get_next_controls_and_trajectories
(
screen
)
# find all the conflicts at the next time horizon
conflicts
=
self
.
find_all_conflicts
(
trajectories
,
dt
)
conflicts
=
[]
#
conflicts = self.find_all_conflicts(trajectories, dt)
conflicts
=
[]
if
len
(
conflicts
)
==
0
:
# no conflicts, return the desired controls
...
...
@@ -262,7 +249,7 @@ class GuidedMRMP:
# resolve the conflicts using the database
# resolver = TrajOptDBResolver(10, 60, conflicts, self.robots)
rad
=
self
.
robots
[
0
].
radius
resolver
=
TrajOptDBResolver
(
rad
*
2
,
5
,
conflicts
,
self
.
robots
,
trajectories
,
dt
,
rad
,
self
.
env
,
1
,
1
,
1
,
self
.
libs
[
0
],
self
.
libs
[
1
],
self
.
libs
[
2
])
resolver
=
TrajOptDBResolver
(
rad
*
2
,
5
,
conflicts
,
self
.
robots
,
trajectories
,
dt
,
rad
,
self
.
env
,
1
0
,
1
0
,
5
,
self
.
libs
[
0
],
self
.
libs
[
1
],
self
.
libs
[
2
])
next_desired_controls
,
trajs
=
resolver
.
get_local_controls
(
next_desired_controls
)
self
.
add_vis_conflict_free_traj
(
screen
,
self
.
scaling_factor
,
trajs
)
...
...
@@ -283,7 +270,7 @@ class GuidedMRMP:
# return the valid controls
for
r
,
next_control
in
zip
(
self
.
robots
,
next_desired_controls
):
r
.
control
=
[
next_control
[
0
][
-
1
],
next_control
[
1
][
-
1
]]
r
.
control
=
next_control
return
True
,
next_desired_controls
...
...
@@ -323,14 +310,14 @@ class GuidedMRMP:
"""
Add the visualization to the screen.
"""
# scaling_factor = 1
traj
=
self
.
ego_to_global
(
robot
,
traj
)
for
i
in
range
(
len
(
traj
[
0
])
-
1
):
x
=
int
(
traj
[
0
,
i
])
y
=
int
(
traj
[
1
,
i
])
next_x
=
int
(
traj
[
0
,
i
+
1
])
next_y
=
int
(
traj
[
1
,
i
+
1
])
pygame
.
draw
.
line
(
screen
,
(
255
,
0
,
0
),
(
x
*
scaling_factor
,
y
*
scaling_factor
),
(
next_x
*
scaling_factor
,
next_y
*
scaling_factor
),
2
)
x
=
traj
[
0
,
i
]
*
scaling_factor
y
=
traj
[
1
,
i
]
*
scaling_factor
next_x
=
traj
[
0
,
i
+
1
]
*
scaling_factor
next_y
=
traj
[
1
,
i
+
1
]
*
scaling_factor
pygame
.
draw
.
line
(
screen
,
(
255
,
0
,
0
),
(
x
,
y
),
(
next_x
,
next_y
),
3
)
def
add_vis_conflict_free_traj
(
self
,
screen
,
scaling_factor
,
trajs
):
"""
...
...
This diff is collapsed.
Click to expand it.
guided_mrmp/simulator.py
+
17
−
17
View file @
e50d671e
...
...
@@ -37,24 +37,24 @@ class Simulator:
"""
conflict_detected
,
controls
=
self
.
policy
.
advance
(
screen
,
self
.
state
,
self
.
time
,
dt
)
if
not
conflict_detected
:
for
i
in
range
(
self
.
num_robots
):
new_state
=
self
.
dynamics_models
[
i
].
next_state
(
self
.
state
[
i
],
controls
[
i
],
dt
)
self
.
robots
[
i
].
current_position
=
new_state
self
.
state
[
i
]
=
new_state
self
.
time
+=
dt
#
if not conflict_detected:
for
i
in
range
(
self
.
num_robots
):
new_state
=
self
.
dynamics_models
[
i
].
next_state
(
self
.
state
[
i
],
controls
[
i
],
dt
)
self
.
robots
[
i
].
current_position
=
new_state
self
.
state
[
i
]
=
new_state
self
.
time
+=
dt
if
conflict_detected
:
print
(
"
Executing full trajectory
"
)
for
i
in
range
(
self
.
num_robots
):
controls_list
=
controls
[
i
]
for
j
in
range
(
len
(
controls_list
)):
next_control
=
[
controls_list
[
0
][
j
],
controls_list
[
1
][
j
]]
print
(
f
"
next control =
{
next_control
}
"
)
new_state
=
self
.
dynamics_models
[
i
].
next_state
(
self
.
state
[
i
],
next_control
,
dt
)
self
.
robots
[
i
].
current_position
=
new_state
self
.
state
[
i
]
=
new_state
self
.
time
+=
dt
#
if conflict_detected:
#
print("Executing full trajectory")
#
for i in range(self.num_robots):
#
controls_list = controls[i]
#
for j in range(len(controls_list)):
#
next_control = [controls_list[0][j], controls_list[1][j]]
#
print(f"next control = {next_control}")
#
new_state = self.dynamics_models[i].next_state(self.state[i], next_control, dt)
#
self.robots[i].current_position = new_state
#
self.state[i] = new_state
#
self.time += dt
def
draw_environment
(
self
,
screen
):
screen
.
fill
((
255
,
255
,
255
))
...
...
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