Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bindings to EvalMotionDerivatives method. #66

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions maliput-sys/src/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ std::unique_ptr<LaneEnd> Lane_GetDefaultBranch(const Lane& lane, bool start) {
return default_branch ? std::make_unique<LaneEnd>(*default_branch) : nullptr;
}

std::unique_ptr<LanePosition> Lane_EvalMotionDerivatives(const Lane& lane, const LanePosition& lane_position, rust::f64 sigma_v, rust::f64 rho_v, rust::f64 eta_v) {
return std::make_unique<LanePosition>(lane.EvalMotionDerivatives(lane_position, IsoLaneVelocity{sigma_v, rho_v, eta_v}));
}

std::unique_ptr<RoadPosition> RoadPosition_new(const Lane* lane, const LanePosition& pos) {
return std::make_unique<RoadPosition>(lane, pos);
}
Expand Down
7 changes: 7 additions & 0 deletions maliput-sys/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ pub mod ffi {
fn Lane_GetConfluentBranches(lane: &Lane, start: bool) -> *const LaneEndSet;
fn Lane_GetOngoingBranches(lane: &Lane, start: bool) -> *const LaneEndSet;
fn Lane_GetDefaultBranch(lane: &Lane, start: bool) -> UniquePtr<LaneEnd>;
fn Lane_EvalMotionDerivatives(
lane: &Lane,
lane_position: &LanePosition,
sigma_v: f64,
rho_v: f64,
eta_v: f64,
) -> UniquePtr<LanePosition>;

// Segment bindings definitions
type Segment;
Expand Down
38 changes: 38 additions & 0 deletions maliput/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ impl HBounds {
}
}

/// Isometric velocity vector in a `Lane`-frame.
///
/// sigma_v, rho_v, and eta_v are the components of velocity in a
/// (sigma, rho, eta) coordinate system. (sigma, rho, eta) have the same
/// orientation as the (s, r, h) at any given point in space, however they
/// form an isometric system with a Cartesian distance metric. Hence,
/// IsoLaneVelocity represents a "real" physical velocity vector (albeit
/// with an orientation relative to the road surface).
#[derive(Default, Copy, Clone, Debug, PartialEq)]
pub struct IsoLaneVelocity {
pub sigma_v: f64,
pub rho_v: f64,
pub eta_v: f64,
}

impl IsoLaneVelocity {
/// Create a new `IsoLaneVelocity` with the given `sigma_v`, `rho_v`, and `eta_v` components.
pub fn new(sigma_v: f64, rho_v: f64, eta_v: f64) -> IsoLaneVelocity {
IsoLaneVelocity { sigma_v, rho_v, eta_v }
}
}

/// A maliput::api::Lane
/// Wrapper around C++ implementation `maliput::api::Lane`.
pub struct Lane<'a> {
Expand Down Expand Up @@ -628,6 +650,22 @@ impl<'a> Lane<'a> {
let bounds = maliput_sys::api::ffi::Lane_elevation_bounds(self.lane, s, r);
HBounds::new(bounds.min(), bounds.max())
}
/// Computes derivatives of [LanePosition] given a velocity vector `velocity`.
/// `velocity` is a isometric velocity vector oriented in the `Lane`-frame
/// at `position`.
///
/// Returns `Lane`-frame derivatives packed into a [LanePosition] struct.
pub fn eval_motion_derivatives(&self, lane_position: &LanePosition, velocity: &IsoLaneVelocity) -> LanePosition {
LanePosition {
lp: maliput_sys::api::ffi::Lane_EvalMotionDerivatives(
self.lane,
lane_position.lp.as_ref().expect(""),
velocity.sigma_v,
velocity.rho_v,
velocity.eta_v,
),
}
}
/// Returns the lane's BranchPoint for the specified end.
pub fn get_branch_point(&self, end: &LaneEnd) -> BranchPoint {
assert! {
Expand Down
5 changes: 5 additions & 0 deletions maliput/tests/lane_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ fn lane_api() {
default_branch.is_none(),
branch_point.get_default_branch(&lane_end).is_none()
);

let velocity = maliput::api::IsoLaneVelocity::new(1., 0., 0.);
let expected_derivatives = maliput::api::LanePosition::new(1., 0., 0.);
let lane_frame_derivatives = lane.eval_motion_derivatives(&maliput::api::LanePosition::new(0., 0., 0.), &velocity);
assert_eq!(expected_derivatives, lane_frame_derivatives);
}

#[test]
Expand Down