-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
707b50b
commit 4f6792c
Showing
12 changed files
with
162 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ TODOs.md | |
examples/debug.py | ||
examples/test.py | ||
|
||
build_vscode/ | ||
|
||
# NumPy saves and videos | ||
results/ | ||
tmp/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .trajectory_factory import TrajectoryFactory | ||
from .trajectory_factory import TrajectoryFactory | ||
from .waypoint import Waypoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .waypoint import Waypoint | ||
from typing import List | ||
|
||
class DiscretizedTrajectory: | ||
waypoints: List[Waypoint] | ||
|
||
def __init__(self) -> None: | ||
pass | ||
|
||
def __len__(self) -> int: | ||
""" | ||
Must be implemented by child class. | ||
""" | ||
raise NotImplementedError("Must be implemented by child class.") | ||
|
||
def __getitem__(self, idx: int) -> Waypoint: | ||
""" | ||
Must be implemented by child class. | ||
""" | ||
raise NotImplementedError("Must be implemented by child class.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from .discretized_trajectory import DiscretizedTrajectory | ||
from .waypoint import Waypoint | ||
from .traj_gen_cpp_wrapper import calculate_trajectory | ||
|
||
from typing import List | ||
import numpy as np | ||
|
||
def calc_target_durations(waypoints: List[Waypoint]) -> np.ndarray: | ||
wps = iter(waypoints) | ||
cur_time = next(wps).timestamp | ||
assert(cur_time == 0) | ||
durations = [] | ||
for wp in wps: | ||
durations.append(wp.timestamp - cur_time) | ||
cur_time = wp.timestamp | ||
|
||
return np.array(durations) | ||
|
||
def convert_to_np_waypoints(waypoints: List[Waypoint]) -> np.ndarray: | ||
t_waypoints_np = np.zeros((3, len(waypoints)), dtype=np.float64) | ||
|
||
for idx, wp in enumerate(waypoints): | ||
t_waypoints_np[:,idx] = wp.coordinate | ||
|
||
return t_waypoints_np | ||
|
||
class PolynomialDiscretizedTrajectory(DiscretizedTrajectory): | ||
waypoints: np.ndarray | ||
timestamps: np.ndarray | ||
|
||
def __init__(self, t_waypoints: List[Waypoint], n_points_discretization_level: int) -> None: | ||
|
||
# target waypoints with durations | ||
t_waypoints_np = convert_to_np_waypoints(t_waypoints) | ||
t_durations_np = calc_target_durations(t_waypoints) | ||
|
||
# call cpp backbone | ||
self.waypoints, self.timestamps = calculate_trajectory( | ||
t_waypoints_np, | ||
t_durations_np, | ||
n_points_discretization_level | ||
) | ||
|
||
# assert n_points | ||
assert(self.waypoints.shape[1] == n_points_discretization_level) | ||
assert(self.waypoints.shape[1] == len(self.timestamps)) | ||
|
||
def __len__(self) -> int: | ||
return len(self.timestamps) | ||
|
||
def __getitem__(self, idx: int) -> Waypoint: | ||
wp = Waypoint( | ||
self.waypoints[:, idx], | ||
self.timestamps[idx] | ||
) | ||
return wp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from trajectory_cpp import calc_trajectory | ||
import numpy as np | ||
from typing import Tuple | ||
|
||
def calculate_trajectory( | ||
t_waypoints: np.ndarray, | ||
t_durations: np.ndarray, | ||
n_discretization_level: int | ||
) -> Tuple[np.ndarray, np.ndarray]: | ||
r_waypoints = np.zeros((3, n_discretization_level), dtype=np.float64) | ||
r_timestamps = np.zeros(n_discretization_level, dtype=np.float64) | ||
calc_trajectory( | ||
t_waypoints, | ||
t_durations, | ||
r_waypoints, | ||
r_timestamps | ||
) | ||
return r_waypoints, r_timestamps | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .waypoint import Waypoint | ||
|
||
class Trajectory: | ||
|
||
def __init__(self) -> None: | ||
pass | ||
|
||
def get_waypoint(self, time: float) -> Waypoint: | ||
""" | ||
Needs to be implemented by subclass. time \in [0,1] | ||
""" | ||
raise NotImplementedError() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
from .trajectories import Trajectory, SquareLinearTrajectory | ||
from .trajectory import Trajectory | ||
from .square_linear_trajectory import SquareLinearTrajectory | ||
from .polynomial_discretized_trajectory import PolynomialDiscretizedTrajectory | ||
from .waypoint import Waypoint | ||
from typing import List | ||
|
||
class TrajectoryFactory: | ||
""" | ||
Wrapper class for instantiating target trajectories. | ||
""" | ||
|
||
@classmethod | ||
def get_linear_square_trajectory(cls, square_scale: float=1, time_scale: float=1) -> Trajectory: | ||
def get_linear_square_trajectory(cls, square_scale: float=1, time_scale: float=1) -> SquareLinearTrajectory: | ||
return SquareLinearTrajectory( | ||
square_scale, time_scale | ||
) | ||
|
||
@classmethod | ||
def get_pol_discretized_trajectory(cls, t_waypoints: List[Waypoint], n_points_discretization_level: int) -> PolynomialDiscretizedTrajectory: | ||
return PolynomialDiscretizedTrajectory( | ||
t_waypoints, | ||
n_points_discretization_level | ||
) | ||
|
Submodule trajectory_generation
updated
6 files
+1 −1 | .gitignore | |
+1 −1 | CMakeLists.txt | |
+5 −5 | setup.py | |
+0 −153 | src/example1_node.cpp | |
+3 −3 | src/pywrap.cpp | |
+4 −4 | test.py |