Skip to content

Commit

Permalink
Merge branch 'release/1.15.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
jara001 committed Nov 25, 2024
2 parents 29645b6 + 1560e30 commit 0939cd1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Unreleased
## 1.15.4 - 2024-11-25
### Added
- Configuration parameter `_ng_version` that defines allowed versions of 'ng_trajectory'.

### Changed
- Criterions
- _Profile_, _Profile2_
- When first time of reference is not zero, use it as lap time.

### Fixed
- Criterions
- _Profile_, _Profile2_
- Do not estimate lap time of the reference when the first time is not zero.
- 'plot'
- `rectanglePlot()` now actually displays rectangles.

## 1.15.3 - 2024-11-18
### Added
- Criterions
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors:
given-names: "Jaroslav"
orcid: "https://orcid.org/0000-0001-8816-2773"
title: "ng_trajectory"
version: 1.15.3
date-released: 2024-11-18
version: 1.15.4
date-released: 2024-11-25
url: "https://github.com/jara001/ng_trajectory"
license: GPL-3.0
preferred-citation:
Expand Down
7 changes: 4 additions & 3 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ _lr (float) = 0.139 [Distance from center of mass to the rear axle [m]]
reference (str) = None [Name of the file to load (x, y, t) reference path that cannot be close.]
reference_dist (float) = 1.0 [Minimum allowed distance from the reference at given time [m].]
reference_rotate (int) = 0 [Number of points to rotate the reference trajectory.]
reference_laptime (float) = 0 [Lap time of the given reference. 0 = estimated from data]
reference_laptime (float) = 0 [Lap time of the given reference. 0 = estimated from data, or taken from the reference file (index 0)]
save_solution_csv (str) = $ [When non-empty, save final trajectory to this file as CSV. Use '$' to use log name instead.]
favor_overtaking (float) = 0 [Penalty value to add to the lap time when overtaking does not occur.]
friction_map (str) = None [Name of the file to load (x, y, mu*100) with friction map.]
Expand Down Expand Up @@ -333,7 +333,7 @@ _lr (float) = 0.139 [Distance from center of mass to the rear axle [m]]
reference (str) = None [Name of the file to load (x, y, t, v) reference path that cannot be close. Currently, the only supported type is .npy]
reference_dist (float) = 1.0 [Minimum allowed distance from the reference at given time [m].]
reference_rotate (int) = 0 [Number of points to rotate the reference trajectory.]
reference_laptime (float) = 0 [Lap time of the given reference. 0 = estimated from data]
reference_laptime (float) = 0 [Lap time of the given reference. 0 = estimated from data, or taken from the reference file (index 0)]
reference_obtain_start (bool) = False [When given, initial speed and initial position of the vehicle is computed.]
reference_obtain_start_td (float) = 0.0 [Time distance behind the reference [s].]
save_solution_csv (str) = $ [When non-empty, save final trajectory to this file as CSV. Use '$' to use log name instead.]
Expand Down Expand Up @@ -615,7 +615,7 @@ _lr (float) = 0.139 [Distance from center of mass to the rear axle [m]]
reference (str) = None [Name of the file to load (x, y, t) reference path that cannot be close.]
reference_dist (float) = 1.0 [Minimum allowed distance from the reference at given time [m].]
reference_rotate (int) = 0 [Number of points to rotate the reference trajectory.]
reference_laptime (float) = 0 [Lap time of the given reference. 0 = estimated from data]
reference_laptime (float) = 0 [Lap time of the given reference. 0 = estimated from data, or taken from the reference file (index 0)]
save_solution_csv (str) = $ [When non-empty, save final trajectory to this file as CSV. Use '$' to use log name instead.]
favor_overtaking (float) = 0 [Penalty value to add to the lap time when overtaking does not occur.]
friction_map (str) = None [Name of the file to load (x, y, mu*100) with friction map.]
Expand Down Expand Up @@ -794,6 +794,7 @@ Final penalty is the minimum of all of these distances.
```html
_version (int) = None [Version of the configuration.]
_comment (str) = None [Commentary of the configuration file.]
_ng_version (str) = [Specifier for supported ng_trajectory versions with the configuration file.]
cascade (list) = None [List of dicts, that is performed loops-times. Req. 'algorithm': OPTIMIZER]
start_points (str) = None [Name of the file with initial solution (i.e., centerline).]
valid_points (str) = None [Name of the file with valid positions of the track.]
Expand Down
10 changes: 7 additions & 3 deletions ng_trajectory/criterions/profile/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
P.createAdd("reference", None, str, "Name of the file to load (x, y, t) reference path that cannot be close.", "init")
P.createAdd("reference_dist", 1.0, float, "Minimum allowed distance from the reference at given time [m].", "init")
P.createAdd("reference_rotate", 0, int, "Number of points to rotate the reference trajectory.", "init")
P.createAdd("reference_laptime", 0, float, "Lap time of the given reference. 0 = estimated from data", "init")
P.createAdd("reference_laptime", 0, float, "Lap time of the given reference. 0 = estimated from data, or taken from the reference file (index 0)", "init")
P.createAdd("save_solution_csv", "$", str, "When non-empty, save final trajectory to this file as CSV. Use '$' to use log name instead.", "init")
P.createAdd("plot", False, bool, "Whether a graphical representation should be created.", "init (viz.)")
P.createAdd("plot_reference", False, bool, "Whether the reference trajectory should be plotted.", "init (viz.)")
Expand Down Expand Up @@ -358,11 +358,15 @@ def init(**kwargs) -> Optional[Dict[str, Any]]:
if P.getValue("reference") is not None:
REFERENCE = numpy.load(P.getValue("reference"))[:, :3]
# REFERENCE = numpy.hstack((numpy.roll(REFERENCE[:, :2], -P.getValue("reference_rotate"), axis=0), REFERENCE[:, 2:]))
# TODO: Lap time should be given, not estimated like this.
lap_time = P.getValue("reference_laptime")

# Use lap time from the reference, if not given explicitly
if lap_time == 0.0 and not numpy.isclose(REFERENCE[0, 2], 0.0):
lap_time = REFERENCE[0, 2]
REFERENCE[0, 2] = 0.0

# Otherwise estimate it from the data
if lap_time == 0.0:
# Lap time estimate
lap_time = REFERENCE[-1, 2] + numpy.mean([
REFERENCE[-1, 2] - REFERENCE[-2, 2],
REFERENCE[1, 2] - REFERENCE[0, 2]
Expand Down
14 changes: 11 additions & 3 deletions ng_trajectory/criterions/profile2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
P.createAdd("reference", None, str, "Name of the file to load (x, y, t, v) reference path that cannot be close. Currently, the only supported type is .npy", "init")
P.createAdd("reference_dist", 1.0, float, "Minimum allowed distance from the reference at given time [m].", "init")
P.createAdd("reference_rotate", 0, int, "Number of points to rotate the reference trajectory.", "init")
P.createAdd("reference_laptime", 0, float, "Lap time of the given reference. 0 = estimated from data", "init")
P.createAdd("reference_laptime", 0, float, "Lap time of the given reference. 0 = estimated from data, or taken from the reference file (index 0)", "init")
P.createAdd("reference_obtain_start", False, bool, "When given, initial speed and initial position of the vehicle is computed.", "init")
P.createAdd("reference_obtain_start_td", 0.0, float, "Time distance behind the reference [s].", "init")
P.createAdd("save_solution_csv", "$", str, "When non-empty, save final trajectory to this file as CSV. Use '$' to use log name instead.", "init")
Expand Down Expand Up @@ -499,11 +499,15 @@ def init(**kwargs) -> Optional[Dict[str, Any]]:
if P.getValue("reference") is not None:
REFERENCE = numpy.load(P.getValue("reference"))[:, :4]

# TODO: Lap time should be given, not estimated like this.
lap_time = P.getValue("reference_laptime")

# Use lap time from the reference, if not given explicitly
if lap_time == 0.0 and not numpy.isclose(REFERENCE[0, 2], 0.0):
lap_time = REFERENCE[0, 2]
REFERENCE[0, 2] = 0.0

# Otherwise estimate it from the data
if lap_time == 0.0:
# Lap time estimate
lap_time = REFERENCE[-1, 2] + numpy.mean([
REFERENCE[-1, 2] - REFERENCE[-2, 2],
REFERENCE[1, 2] - REFERENCE[0, 2]
Expand Down Expand Up @@ -769,6 +773,10 @@ def compute(
_a[i] > P.getValue("a_acc_max")
or _a[i] < -P.getValue("a_break_max")
):
# TODO: This negatively affects the optimization. In some cases,
# a lot of attempts fail here. This also means (as a side
# effect) that an empty plot is generated.
# FIXME: Resolve what to do properly when this occurs.
return float(penalty * abs(_a[i]))

invalid_points = []
Expand Down
13 changes: 13 additions & 0 deletions ng_trajectory/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import numpy
import json
import time
from packaging import specifiers # SpecifierSet

# from ng_trajectory.configuration import configurationLoad
# from ng_trajectory.configuration import CONFIGURATION
Expand Down Expand Up @@ -110,6 +111,7 @@
# FIXME: Actually, the default values do not work here as it was not adapted for ParameterList.
P.createAdd("_version", None, int, "Version of the configuration.", "General")
P.createAdd("_comment", None, str, "Commentary of the configuration file.", "General")
P.createAdd("_ng_version", "", str, "Specifier for supported ng_trajectory versions with the configuration file.", "General")
P.createAdd("loops", None, int, "Number of repetitions.", "Optimization")
P.createAdd("groups", None, int, "Number of segments on the track.", "Optimization")
P.createAdd("variate", None, str, "Name of the field that contains multiple values. Its values are varied, run loop-cascade times.", "Optimization")
Expand Down Expand Up @@ -215,6 +217,17 @@ def configurationLoad(filename: str) -> bool:
)
else:
CONFIGURATION = {**CONFIGURATION, **conf}

spec = specifiers.SpecifierSet(
CONFIGURATION.get("_ng_version", ""), prereleases = True
)

if ng_trajectory.__version__ not in spec:
raise ValueError (
"Unsupported version of ng_trajectory == %s. "
"Configuration requires: %s"
% (ng_trajectory.__version__, spec)
)
except Exception as e:
print (e)
return False
Expand Down
10 changes: 7 additions & 3 deletions ng_trajectory/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,15 @@ def rectanglePlot(

# Support older matplotlib
import matplotlib.transforms as tr
tra= tr.Affine2D().rotate_deg_around(centre[0], centre[1], numpy.degrees(angle))
# Note: For some reason, adding transformation directly to the patch,
# makes it unable to render.
tra = tr.Affine2D().rotate_deg_around(
centre[0], centre[1], numpy.degrees(angle)
)

rectangle = pyplot.Rectangle(
(centre[0] - (width / 2), centre[1] - (height / 2)),
width, height, transform = tra,#numpy.degrees(angle), rotation_point = 'center',
tra.transform((centre[0] - (width / 2), centre[1] - (height / 2))),
width, height, numpy.degrees(angle), # rotation_point = 'center',
**kwargs
)

Expand Down

0 comments on commit 0939cd1

Please sign in to comment.