function exampleHelperShowOpenLoopDynamics(truckParams)
%exampleHelperShowOpenLoopDynamics Helper function for displaying passive dynamics

% Copyright 2021 The MathWorks Inc. 

    figure
    % Integrate system with positive velocity for different initial interior angles
    uConst = [1 0]; % [velocity steerAngle];
    ax = subplot(2,1,1);
    qForward = integrateSystem(ax,uConst);
    title('Interior Angle vs Time, v > 0');
    xlabel('Time (s)');
    ylabel('Interior Angle (rad)');
    
    % Integrate system with negative velocity for different initial interior angles
    uConst(1) = -1;
    ax = subplot(2,1,2);
    qReverse = integrateSystem(ax,uConst);
    title('Interior Angle vs Time, v < 0');
    xlabel('Time (s)');
    ylabel('Interior Angle (rad)');
    
    f = figure;
    title('Open loop propagation')
    ax = axes(f);
    hold on;
    plot(qForward(:,1),qForward(:,2),'g');
    plot(qReverse(:,1),qReverse(:,2),'r');
    Q = [qForward(:,1:2);qReverse(:,1:2)];
    axis equal;
    exampleHelperPlotTruck(truckParams,qForward);
    exampleHelperPlotTruck(truckParams,qReverse);
    
    function q = integrateSystem(ax,uConst)
        hold(ax,'on');
        beta0 = linspace(-pi/4,pi/4,11);
        q0 = zeros(1,6); % [x2 y2 th2 beta vSign s]
        q = zeros(200,6);
        dt = 0.1;
        dqFcn = @(q0)exampleHelperStateDerivative(truckParams.L1,truckParams.L2,truckParams.M,q0,uConst);
        for i = 1:numel(beta0)
            q0(4) = beta0(i);
            q(1,:) = q0;
            for j = 1:200
                dq = dqFcn(q(j,:));
                q(j+1,:) = q(j,:)+dq*dt;
            end
            plot(ax,(0:200)*dt,q(:,4));
        end
        hold(ax,'off');
    end
end