vkf_follower Module

Following trajectories: the position and attitude of a frame from one or more trajectories at the current time, as OpenFrames' TrajectoryFollower.

With several trajectories, the one followed at time t is the one whose time range contains t, or the closest one. If t is outside all of them, FOLLOW_LOOP wraps it into their combined time range and FOLLOW_LIMIT holds the ends. Positions are interpolated linearly, attitudes by slerp.

The time is either the global simulation time plus an offset (set_offset_time, the default with offset 0) or a fixed time (set_time). The trajectories are not owned: they must stay alive while followed.

state_at gives the followed state at any time without changing the follower (for frames' poses at points' own times: vkf_frames' world_matrix_at); update is state_at at the simulation time. Every change to what is followed and how stamps the follower (motion_stamp, from next_motion_stamp's clock), so that drawings depending on its motion know to redraw.


Uses

  • module~~vkf_follower~~UsesGraph module~vkf_follower vkf_follower module~vkf_math vkf_math module~vkf_follower->module~vkf_math module~vkf_trajectory vkf_trajectory module~vkf_follower->module~vkf_trajectory iso_fortran_env iso_fortran_env module~vkf_math->iso_fortran_env module~vkf_trajectory->module~vkf_math iso_c_binding iso_c_binding module~vkf_trajectory->iso_c_binding module~vkf_trajectory->iso_fortran_env

Used by

  • module~~vkf_follower~~UsedByGraph module~vkf_follower vkf_follower module~vkf_frames vkf_frames module~vkf_frames->module~vkf_follower module~vkframes vkframes module~vkframes->module~vkf_follower module~vkframes->module~vkf_frames module~vkf_artists vkf_artists module~vkframes->module~vkf_artists module~vkf_handles vkf_handles module~vkframes->module~vkf_handles module~vkf_hud vkf_hud module~vkframes->module~vkf_hud module~vkf_line_segments vkf_line_segments module~vkframes->module~vkf_line_segments module~vkf_model vkf_model module~vkframes->module~vkf_model module~vkf_shadow vkf_shadow module~vkframes->module~vkf_shadow module~vkf_shapes vkf_shapes module~vkframes->module~vkf_shapes module~vkf_sphere vkf_sphere module~vkframes->module~vkf_sphere module~vkf_terrain vkf_terrain module~vkframes->module~vkf_terrain module~vkf_view vkf_view module~vkframes->module~vkf_view module~vkf_window vkf_window module~vkframes->module~vkf_window module~vkf_artists->module~vkf_frames module~vkf_handles->module~vkf_frames module~vkf_handles->module~vkf_artists module~vkf_hud->module~vkf_frames module~vkf_line_segments->module~vkf_frames module~vkf_model->module~vkf_frames module~vkf_shadow->module~vkf_frames module~vkf_shadow->module~vkf_sphere module~vkf_shadow->module~vkf_terrain module~vkf_shapes->module~vkf_frames module~vkf_shapes->module~vkf_artists module~vkf_sphere->module~vkf_frames module~vkf_terrain->module~vkf_frames module~vkf_view->module~vkf_frames module~vkf_window->module~vkf_frames module~vkf_window->module~vkf_handles module~vkf_window->module~vkf_hud module~vkf_window->module~vkf_view

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: FOLLOW_ATTITUDE = 2

follow the attitude

integer, public, parameter :: FOLLOW_LIMIT = 1

hold the first/last point outside the time range

integer, public, parameter :: FOLLOW_LOOP = 0

follow modes (OpenFrames' FollowMode) wrap the time into the trajectories' time range

integer, public, parameter :: FOLLOW_POSITION = 1

what to follow (OpenFrames' FollowData), combined with ior follow the position

integer, private, save :: motion_clock = 0

The clock of motion stamps (next_motion_stamp).


Derived Types

type, public ::  TrajectoryFollower

Follows trajectories (see the module documentation).

Components

Type Visibility Attributes Name Initial
integer, private :: current = 0

index (in trajs) of the trajectory last followed

integer, private :: data_ = FOLLOW_POSITION+FOLLOW_ATTITUDE

what is followed (FOLLOW_* combined with ior)

logical, private :: default_data = .true.

(true: sources_ are the trajectories' positions)

logical, private :: follow_time = .true.

(true: simulation time + time_value; false: time_value)

real(kind=wp), private :: last_time_ = 0.0_wp

time (after looping) at the last update (s)

integer, private :: mode_ = FOLLOW_LOOP

FOLLOW_LOOP or FOLLOW_LIMIT

integer, private :: n = 0

number of followed trajectories

type(DataSource), private :: sources_(3)

where the followed position's x, y, z come from

integer, private :: stamp_ = 0

motion stamp of the last change of settings (next_motion_stamp)

real(kind=wp), private :: time_value = 0.0_wp

time offset or fixed time (s)

type(TrajectoryPointer), private, allocatable :: trajs(:)

(capacity): the followed trajectories

Type-Bound Procedures

procedure, public :: add_trajectory
procedure, public :: data_revision
procedure, public :: data_sources
procedure, public :: data_valid
procedure, public :: follow_data
procedure, public :: follow_mode
procedure, public :: is_following_time
procedure, public :: last_time
procedure, public :: last_trajectory
procedure, public :: motion_stamp
procedure, public :: num_trajectories
procedure, public :: remove_all
procedure, public :: remove_trajectory
procedure, public :: set_default_data
procedure, public :: set_follow_type
procedure, public :: set_offset_time
procedure, public :: set_time
procedure, public :: set_trajectory
procedure, public :: set_x_data
procedure, public :: set_y_data
procedure, public :: set_z_data
procedure, public :: state_at
procedure, public :: update
procedure, public :: using_default_data

type, private ::  TrajectoryPointer

A pointer to a followed trajectory (for an array of them).

Components

Type Visibility Attributes Name Initial
type(Trajectory), public, pointer :: p => null()

the trajectory (not owned)


Functions

private function chosen_trajectory(self, t) result(k)

The trajectory to follow at time t: the current one if it contains t, else the first that does, else the closest.

Arguments

Type IntentOptional Attributes Name
type(TrajectoryFollower), intent(in) :: self
real(kind=wp), intent(in) :: t

the time (s)

Return Value integer

private pure function data_revision(self)

The sum of the followed trajectories' revisions and generations: it grows with any change to their data (the set of trajectories itself changes the motion_stamp).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value integer

private pure function data_sources(self) result(s)

Where the followed position's x, y and z come from.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value type(DataSource), (3)

private pure function data_valid(self)

True if every followed trajectory has the data the position sources use.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value logical

private pure function follow_data(self)

What is followed: FOLLOW_POSITION and/or FOLLOW_ATTITUDE (combined with ior).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value integer

private pure function follow_mode(self)

How time outside the trajectories is handled: FOLLOW_LOOP or FOLLOW_LIMIT.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value integer

private pure function is_following_time(self)

True if following the simulation time plus an offset, false for a fixed time.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value logical

private pure function last_time(self)

The time (after looping) at the last update.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value real(kind=wp)

private function last_trajectory(self) result(traj)

The trajectory followed at the last update (null if none).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value type(Trajectory), pointer

private pure function motion_stamp(self)

The stamp of the last change of the follower's settings (the trajectories followed, what and how, the time); 0 if never changed.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value integer

public function next_motion_stamp() result(stamp)

A new motion stamp: larger than all before (a change of some frame's motion: its pose, its parents, what it follows and how).

Arguments

None

Return Value integer

private pure function num_trajectories(self)

Number of trajectories followed.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value integer

private function set_x_data(self, src) result(valid)

Where the x, y and z of the followed position come from (default: the trajectories' positions). Returns whether all followed trajectories have those data.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
type(DataSource), intent(in) :: src

where the x comes from

Return Value logical

private function set_y_data(self, src) result(valid)

Where the y of the followed position comes from (see set_x_data).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
type(DataSource), intent(in) :: src

where the y comes from

Return Value logical

private function set_z_data(self, src) result(valid)

Where the z of the followed position comes from (see set_x_data).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
type(DataSource), intent(in) :: src

where the z comes from

Return Value logical

private pure function using_default_data(self)

True if the followed position is the trajectories' positions (set_default_data).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self

Return Value logical

private function wrapped_time(self, t) result(tw)

For FOLLOW_LOOP, t wrapped into the combined time range of the trajectories.

Arguments

Type IntentOptional Attributes Name
type(TrajectoryFollower), intent(in) :: self
real(kind=wp), intent(in) :: t

the time (s)

Return Value real(kind=wp)


Subroutines

private subroutine add_trajectory(self, traj)

Also follow traj (no effect if it is already followed).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
type(Trajectory), intent(in), pointer :: traj

the trajectory to add (not owned; null: none)

private subroutine interpolate_attitude(traj, t, status, index, attitude, ok)

Slerp of the attitude at time t; the first/last attitude outside the time range. status and index: the trajectory's time_index for t.

Arguments

Type IntentOptional Attributes Name
type(Trajectory), intent(in) :: traj

the trajectory

real(kind=wp), intent(in) :: t

the time (s)

integer, intent(in) :: status

traj%time_index's result and index for t

integer, intent(in) :: index

traj%time_index's result and index for t

real(kind=wp), intent(inout) :: attitude(4)

quaternion [x, y, z, w]

logical, intent(out) :: ok

false if there is no attitude (attitude unchanged)

private subroutine interpolate_position(traj, sources, t, status, index, position, ok)

Linear interpolation of the position (from sources) at time t; the first/last point outside the time range. status and index: the trajectory's time_index for t.

Arguments

Type IntentOptional Attributes Name
type(Trajectory), intent(in) :: traj

the trajectory

type(DataSource), intent(in) :: sources(3)

where the position's x, y, z come from

real(kind=wp), intent(in) :: t

the time (s)

integer, intent(in) :: status

traj%time_index's result and index for t

integer, intent(in) :: index

traj%time_index's result and index for t

real(kind=wp), intent(inout) :: position(3)

the interpolated position

logical, intent(out) :: ok

false if there is no position (position unchanged)

private subroutine remove_all(self)

Stop following all trajectories.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self

private subroutine remove_trajectory(self, traj)

Stop following traj.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
type(Trajectory), intent(in), pointer :: traj

the trajectory to stop following

private subroutine set_default_data(self)

Use the trajectories' positions (per the first trajectory's DOF).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self

private subroutine set_follow_type(self, data, mode)

What to follow (FOLLOW_POSITION and/or FOLLOW_ATTITUDE, combined with ior) and how (FOLLOW_LOOP or FOLLOW_LIMIT).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
integer, intent(in) :: data

FOLLOW_POSITION and/or FOLLOW_ATTITUDE (ior)

integer, intent(in) :: mode

FOLLOW_LOOP or FOLLOW_LIMIT

private subroutine set_offset_time(self, offset)

Follow at the simulation time plus offset (the default, offset 0).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
real(kind=wp), intent(in) :: offset

added to the simulation time (s)

private subroutine set_time(self, t)

Follow at a fixed time (independent of the simulation time).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
real(kind=wp), intent(in) :: t

the time (s)

private subroutine set_trajectory(self, traj)

Follow only traj (none if it is not associated).

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
type(Trajectory), intent(in), pointer :: traj

the trajectory to follow (not owned; null: none)

private subroutine state_at(self, sim_time, position, attitude, has_position, has_attitude, time, chosen)

The position and attitude followed at simulation time sim_time, as update (the same time mapping, choice of trajectory and interpolation) but without changing the follower: for any time, e.g. a frame's pose at a trajectory point's own time.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(in) :: self
real(kind=wp), intent(in) :: sim_time

simulation time (s)

real(kind=wp), intent(inout) :: position(3)

the followed position (in the trajectories' frame; unchanged if none)

real(kind=wp), intent(inout) :: attitude(4)

the followed attitude (quaternion [x, y, z, w]; unchanged if none)

logical, intent(out) :: has_position

(true: position / attitude set)

logical, intent(out) :: has_attitude

(true: position / attitude set)

real(kind=wp), intent(out), optional :: time

the trajectories' time used (after the offset and looping)

integer, intent(out), optional :: chosen

the trajectory used (index in the followed ones)

private subroutine update(self, sim_time, position, attitude, has_position, has_attitude)

The position and attitude at simulation time sim_time. has_position and has_attitude say whether each could be computed (and is being followed); otherwise position / attitude are left unchanged.

Arguments

Type IntentOptional Attributes Name
class(TrajectoryFollower), intent(inout) :: self
real(kind=wp), intent(in) :: sim_time

simulation time (s)

real(kind=wp), intent(inout) :: position(3)

the followed position (in the trajectories' frame)

real(kind=wp), intent(inout) :: attitude(4)

the followed attitude (quaternion [x, y, z, w])

logical, intent(out) :: has_position

(true: position / attitude set)

logical, intent(out) :: has_attitude

(true: position / attitude set)