classdef fixedwingFlightTrajectory < uav.internal.mission.trajectory.UserInterface
    %fixedwingFlightTrajectory Generate UAV motion vectors along trajectory
    %
    %   fixedwingFlightTrajectory generates a trajectory based on specified
    %   waypoints, velocities and time of arrivals using waypointTrajectory
    %   as interpolant.
    %
    %   T = fixedwingFlightTrajectory(WPTS,VELS,TOAS) generates a reference
    %   trajectory T using waypoints WPTS, velocities VELS and time of
    %   arrivals TOAS. WPTS is a NX3 matrix, each row contains one waypoint
    %   that the trajectory will pass through. VELS is a NX3 matrix, each
    %   row contains the desired velocity at given waypoint. TOAS is a NX1
    %   vector contain time of arrivals at each waypoint. WPTS and VELS are
    %   expressed in Local NED frame.
    %
    %   fixedwingFlightTrajectory properties:
    %       Waypoints             - Positions (m) in local NED frame 
    %       Velocities            - Velocities (m/s) in local NED frame
    %       TimeOfArrival         - Time (s) at each waypoint
    %       StartTime             - Start time (s) of the trajectory
    %       EndTime               - End time (s) of the trajectory
    %
    %   fixedwingFlightTrajectory methods:
    %      query                 - Get UAV motion vectors at given timestamps.
    %      show                  - Visualize UAV trajectory
    %      copy                  - Copy flight trajectory
    %
    %   Example:
    %
    %      % Create mission
    %      mission = uavMission(PlanFile="flight.plan");
    %
    %      % Create parser
    %      parser = fixedwingMissionParser;
    %
    %      % Generate flight trajectory
    %      traj = parse(parser, mission);
    %
    %      % Visualize
    %      figure()
    %      show(mission);
    %      hold on;
    %      show(traj);
    %
    %   See also uavMission, fixedwingMissionParser

    %   Copyright 2022 The MathWorks, Inc.

    %#codegen

    properties (Dependent, SetAccess = private)
        %StartTime Start time (s) of the trajectory
        StartTime

        %EndTime End time (s) of the trajectory
        EndTime

        %Waypoints Positions (m) in local NED frame 
        Waypoints

        %Velocities Velocities (m/s) in local NED frame
        Velocities

        %TimeOfArrival Time (s) at each waypoint
        TimeOfArrival
    end

    methods
        function obj = fixedwingFlightTrajectory(waypoints, velocities, timeOfArrival)
            %fixedwingFlightTrajectory Constructor

            validateattributes(waypoints, "numeric", {'2d', 'ncols', 3}, "fixedwingFlightTrajectory", "waypoints");
            validateattributes(velocities, "numeric", {'2d', 'ncols', 3}, "fixedwingFlightTrajectory", "velocities");
            validateattributes(timeOfArrival, "numeric", {'vector', 'increasing', 'finite'}, "fixedwingFlightTrajectory", "timeOfArrivals");
            obj.TrajectoryData = uav.internal.mission.trajectory.FixedWingWaypointTrajectory(...
                double(waypoints), double(velocities), double(timeOfArrival));
        end

        function out = get.StartTime(obj)
            %getter for StartTime
            out = obj.TrajectoryData.StartTime;
        end

        function out = get.EndTime(obj)
            %getter for EndTime
            out = obj.TrajectoryData.EndTime;
        end
        
        function out = get.Waypoints(obj)
            %getter for Waypoints
            out = obj.TrajectoryData.Trajectory.Waypoints;
        end

        function out = get.Velocities(obj)
            %getter for Velocities
            out = obj.TrajectoryData.Trajectory.Velocities;
        end

        function out = get.TimeOfArrival(obj)
            %getter for Waypoints
            out = obj.TrajectoryData.Trajectory.TimeOfArrival;
        end

        function cobj = copy(obj)
            %copy Copy flight trajectory

            cobj = fixedwingFlightTrajectory(obj.Waypoints, obj.Velocities, obj.TimeOfArrival);
        end

    end

    methods (Access = {?fixedwingFlightTrajectory, ?fixedwingMissionParser})

        function loadData(obj, traj)
            %loadData load data from TRAJ
            %   loadData(OBJ, TRAJ) loads data from TRAJ, which is a
            %   uav.internal.mission.trajectory.FixedWingWaypointTrajectory
            %   object
            obj.TrajectoryData = traj;
        end
    end
end

