% Create CaoEngine object
cao = actxserver('CAO.CaoEngine');

% Get Workespaces object
ws = cao.Workspaces.Item(int32(0));

% Create Controller object
ctrl = ws.AddController('RC1', 'CaoProv.DENSO.NetwoRC', '', 'conn=eth:192.168.0.1');

% Create Robot Control
rob = ctrl.AddRobot('arm');

% Current Position
cur = rob.AddVariable('@HIGH_CURRENT_POSITION');

% Set Speed
rob.Speed(-1, 100);

% Move
rob.Move(1, '@E P(400, 0, 400, 180, 0, 180, 5)');

% Move & Watch
figure;
idx = 1;
time = zeros(0, 1);
pos = zeros(0, 3);
rob.Speed(-1, 10);
rob.Move(2, '@0 P(500, 0, 400, 180, 0, 180, 5)', 'Next');
while 1
    v = double(cur.Value);
    t = cur.Microsecond / 1e3;
    
    if idx == 1
        t0 = t;
    end
    t = t - t0;
    time(idx) = t;
    pos(idx, 1 : 3) = v(1 : 3);
    
    subplot(3, 1, 1);
    plot(time, pos(:, 1));
    axis([0 6 350 550]);
    xlabel('Time [sec]');
    ylabel('X [mm]');
    
    subplot(3, 1, 2);
    plot(time, pos(:, 2));
    axis([0 6 -1 1]);
    xlabel('Time [sec]');
    ylabel('Y [mm]');
    
    subplot(3, 1, 3);
    plot(time, pos(:, 3));
    axis([0 6 399 401]);
    xlabel('Time [sec]');
    ylabel('Z [mm]');
    
    if t > 6
        break;
    end
    
    idx = idx + 1;
    drawnow;
end
