classdef robotstatus < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                  matlab.ui.Figure
        Label                     matlab.ui.control.Label
        RobotvisualisationButton  matlab.ui.control.Button
        UIAxes3                   matlab.ui.control.UIAxes
        UIAxes2                   matlab.ui.control.UIAxes
        UIAxes                    matlab.ui.control.UIAxes
    end

    properties (Access = public)
        exc % Description
    end

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app, edge)
            app.exc = edge;
        end

        % Button pushed function: RobotvisualisationButton
        function RobotvisualisationButtonPushed(app, event)
        if app.exc == 1
        position0 = [115 0 0 870;0 -13 0 0;0 0 -1 -685;0 0 0 1];
        position1 = [-0.0661 -0.7077 -0.7034 128.9;-0.9321 -0.2077 0.2966 213.9;0 0 -1 -1161;0 0 0 1];
        step = 100;
        elseif app.exc == 2
        position0 = [115 0 0 870;0 -13 0 0;0 0 -1 -685;0 0 0 1];
        position1 = [-0.0661 -0.7077 -0.7034 128.9;-0.9321 -0.2077 0.2966 213.9;0 0 -1 -1161;0 0 0 1];
        step = 200;
        elseif app.exc == 3
        position0 = [115 0 0 870;0 -13 0 0;0 0 -1 -685;0 0 0 1];
        position1 = [-0.0661 -0.7077 -0.7034 128.9;-0.9321 -0.2077 0.2966 213.9;0 0 -1 -1161;0 0 0 1];
        step = 300;
        end
        
        [q, qd, qdd] = robotkn(position0, position1, step);
        
        plot(app.UIAxes,q,'LineWidth',1);
        legend(app.UIAxes,'axin1','axin2','axin3','axin4','axin5','axin6')
        plot(app.UIAxes2,qd,'LineWidth',1);
        plot(app.UIAxes3,qdd,'LineWidth',1);
        
        robot=importrobot('body.urdf')
        filter_constant = 0.05;
        %showdetails(robot)
        show(robot)
        axis([-1.5,1.5,-1.5,1.5,0,1.5])
        
%         app.ExampleEditField.Value = app.exc;
        app.Label.Text = ['Excample: ' num2str(app.exc)];
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 430 480];
            app.UIFigure.Name = 'MATLAB App';

            % Create UIAxes
            app.UIAxes = uiaxes(app.UIFigure);
            title(app.UIAxes, 'Position')
            zlabel(app.UIAxes, 'Z')
            app.UIAxes.XTick = [];
            app.UIAxes.YTick = [];
            app.UIAxes.Position = [5 340 420 130];

            % Create UIAxes2
            app.UIAxes2 = uiaxes(app.UIFigure);
            title(app.UIAxes2, 'Speed')
            zlabel(app.UIAxes2, 'Z')
            app.UIAxes2.XTick = [];
            app.UIAxes2.YTick = [];
            app.UIAxes2.Position = [5 205 420 130];

            % Create UIAxes3
            app.UIAxes3 = uiaxes(app.UIFigure);
            title(app.UIAxes3, 'Acceleration ')
            zlabel(app.UIAxes3, 'Z')
            app.UIAxes3.XTick = [];
            app.UIAxes3.YTick = [];
            app.UIAxes3.Position = [5 70 420 130];

            % Create RobotvisualisationButton
            app.RobotvisualisationButton = uibutton(app.UIFigure, 'push');
            app.RobotvisualisationButton.ButtonPushedFcn = createCallbackFcn(app, @RobotvisualisationButtonPushed, true);
            app.RobotvisualisationButton.Position = [290 25 123 30];
            app.RobotvisualisationButton.Text = 'Robot visualisation';

            % Create Label
            app.Label = uilabel(app.UIFigure);
            app.Label.FontSize = 14;
            app.Label.Position = [27 33 201 22];

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = robotstatus(varargin)

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            % Execute the startup function
            runStartupFcn(app, @(app)startupFcn(app, varargin{:}))

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end