Skip to content

Commit

Permalink
Merge branch 'release/1.15.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jara001 committed Nov 12, 2024
2 parents fe4d88d + be972d4 commit b0fb3c3
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 198 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ 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.2 - 2024-11-12
### Added
- 'ng_generate_data'
- Another file, 'start_points.csv' is generated. It contains positions of the centerline along with the distances to the walls.

### Changed
- Criterions
- _Profile_
- `saveState()` now also saves backward nad maximum speeds that are computed within the speed profiler.
- _Profile2_
- Remove majority of flake8 warnings.
- 'ng_generate_data'
- Generated `start_points.npy` contains additional two columns with distances to the walls.
- 'plot'
- Support older matplotlib versions in `rectanglePlot()`.

### Fixed
- Criterions
- _Profile_
- Properly construct conditional-based dictionary is `saveState()`.
- _Profile2_
- Properly obtain logfile name.
- Load first four columns of the reference instead of just three.
- Add missing import of `pointToMap()`.
- Properly construct conditional-based dictionary is `saveState()`.

## 1.15.1 - 2024-09-10
### Added
- Optimizers
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.1
date-released: 2024-09-10
version: 1.15.2
date-released: 2024-11-12
url: "https://github.com/jara001/ng_trajectory"
license: GPL-3.0
preferred-citation:
Expand Down
28 changes: 25 additions & 3 deletions bin/ng_generate_data
Original file line number Diff line number Diff line change
Expand Up @@ -825,27 +825,49 @@ def processImage(im: Image) -> None:
saveim(nndi, "generated_data.png")


# # Compute distances to the walls # #
dists = []

walls = getWalls(im)
for wall in walls:
dists.append([
numpy.hypot(
wall[:, 0] - sorted_points[i][0],
wall[:, 1] - sorted_points[i][1]
).min() for i in range(len(sorted_points))
])


# # Save into npy # #

start_points = numpy.asarray(sorted_points).astype(float)

# Flip y-axis
start_points -= [im.size[1], 0]
start_points[:, 0] = numpy.abs(start_points[:, 0])
start_points = numpy.hstack((start_points, numpy.asarray(dists).T))

# Convert to real units (if required)
if args.resolution != 1.0 or args.scale != 1.0: # or args.resize != 1.0:
start_points *= (args.resolution * args.scale) / args.resize

# Move the origin (if required)
if args.originx != 0.0 or args.originy != 0.0:
start_points += [args.originy, args.originx]
start_points += [args.originy, args.originx, 0, 0]

# Swap yx
start_points = numpy.vstack((start_points[:, 1], start_points[:, 0])).T

start_points = numpy.hstack((
numpy.vstack((start_points[:, 1], start_points[:, 0])).T,
start_points[:, 2:]
))
save(start_points, "start_points.npy")

with open(generate_filename("start_points.csv"), "w") as f:
f.write("x_m,y_m,d1_m,d2_m\n")
for _sp in start_points:
m = [_sp[0], _sp[1], _sp[3], _sp[2]]
f.write(",".join(["%f" % v for v in m]) + "\n")

valid_points = numpy.asarray(im, dtype = int)
valid_points = numpy.argwhere(
(valid_points == FREE) & (~invalid)
Expand Down
53 changes: 41 additions & 12 deletions ng_trajectory/criterions/profile/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from ng_trajectory.segmentators.utils import pointToMap

from typing import List, Tuple, TextIO
from typing import List, Tuple, TextIO, Optional


_mu = 0.2 # Friction coeficient
Expand Down Expand Up @@ -339,7 +339,10 @@ def saveState(
points: numpy.ndarray,
t: numpy.ndarray,
v: numpy.ndarray,
a: numpy.ndarray) -> bool:
a: numpy.ndarray,
*,
bwd: Optional[numpy.ndarray] = None,
mx: Optional[numpy.ndarray] = None) -> bool:
"""Save the computed profile into a CSV file.
Arguments:
Expand All @@ -349,6 +352,11 @@ def saveState(
a -- acceleration profile of the trajectory, [m.s^-2], nx1 numpy.ndarray
t -- time of reaching the points of the trajectory,
[s], nx1 or (n+1)x1 numpy.ndarray
*
bwd -- speed profile after the backward pass, [m.s^-1],
optional, nx1 numpy.ndarray
mx -- maximum permissible speed, [m.s^-1],
optional, nx1 numpy.ndarray
Returns:
success -- True if saved, otherwise False
Expand Down Expand Up @@ -407,6 +415,12 @@ def saveState(
x, y, k = points[:, :3].T
t, v, a = t.flatten(), v.flatten(), a.flatten()

if bwd is not None:
bwd = bwd.flatten()

if mx is not None:
mx = mx.flatten()

# Line distance (d) !! NOT TRACK PROGRESS !!
d = pointsDistance(points)
_d = d[0]
Expand Down Expand Up @@ -436,12 +450,18 @@ def saveState(
with open(filename, "w", newline = "") as f:
writer = csv.DictWriter(
f,
fieldnames = [
"t_s", "d_m", "x_m", "y_m",
"psi_rad", "k_radpm",
"vx_mps", "vy_mps", "a_mps2",
"omega_radps", "delta_rad"
] + ([] if CENTERLINE is None else ["s_m"])
fieldnames = (
[
"t_s", "d_m", "x_m", "y_m",
"psi_rad", "k_radpm",
"vx_mps", "vy_mps", "a_mps2",
"omega_radps", "delta_rad"
]
+ ([] if CENTERLINE is None else ["s_m"])
+ ["vfwd_mps"]
+ ([] if bwd is None else ["vbwd_mps"])
+ ([] if mx is None else ["vmax_mps"])
)
)

writer.writeheader()
Expand All @@ -462,14 +482,23 @@ def saveState(
"a_mps2": a[_i],
"omega_radps": v[_i] * math.cos(_beta) * k[_i],
"delta_rad": math.atan((_lf + _lr) * k[_i])
}, **{
[] if CENTERLINE is None
else "s_m": cd[
}, **(
{} if CENTERLINE is None
else {"s_m": cd[
trajectoryClosestIndex(
CENTERLINE,
numpy.asarray([x[_i], y[_i]])
)
]}
), **{
"vfwd_mps": v[_i]
}, **(
{} if bwd is None
else {"vbwd_mps": bwd[_i]}
), **(
{} if mx is None
else {"vmax_mps": mx[_i]}
)
})


Expand Down Expand Up @@ -591,6 +620,6 @@ def profileCompute(
_t[0] = 0

if save is not None:
saveState(save, points, _t, _v, _a)
saveState(save, points, _t, _v, _a, bwd = bwd, mx = mx)

return _v, _a, _t
Loading

0 comments on commit b0fb3c3

Please sign in to comment.