Control Pioneer 3dx with MATLAB

Posted 2013.08.21 00:55

1. ARIA를 받고 설치한다. 

 http://robots.mobilerobots.com/wiki/ARIA 


2. MATLAB-ARAI를 받고 설치한다. 

 https://github.com/reed-adept/aria-matlab 

Interfaces that provide a handful of essential features of ARIA in Matlab or Simulink. After retrieving this repository, move and rename the resulting directory to a subdirectory of the Aria installation location: /usr/local/Aria/matlab on Linux or C:\Program Files\MobileRobots\Aria\matlab on Windows. ARIA Simple Interface for Matlab -------------------------------- A collection of C files (in mex-src) defines MEX interfaces for some of the functions in ariac. Requirements: * ARIA 2.7.5.2 <http://robots.mobilerobots.com/wiki/ARIA> * Visual C++ 2010 <http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express> * Matlab 2012b (32bit) (other versions may work but are untested) * Windows 7 (Linux, using G++ 4.x, or other versions of Windows, may work, but is untested.) Build: 1. This directory should be a subdirectory of ARIA named "matlab" (see above). 2. Build ariac in Release mode using Visual Studio 2010 by opening ariac-vc2010.sln, choosing Release (in win32) mode, and building the ariac-dll project. 3. Open Matlab and navigate to this matlab directory. 4. Add this matlab directory to the Matlab path by right-clicking on it in the Matlab file browser and selecting "Add To Path" then "This Folder". 5. Run makemex.m in Matlab to compile the Mex interfaces. It will also copy AriaVC10.dll into the matlab directory. -> If you have not yet configure mex for compilation, it will prompt you to do so. Choose Microsoft Visual C++ 10.0. If you have already configured mex, but for a different compiler, run mex -setup in the command window. If Matlab does not automatically locate Visual C++ 10.0 when locating installed compilers, run mex -setup again, and enter N when promted to locate installed compilers, then choose Microsoft Visual C++ from the list. (Note: Make sure that the path is correct; if the path does not exist, you may need to manually enter the actual path as installed on your system.)


3. 위에서 하란대로 하면 된다. 


4. 주의!! 

 - 자신이 64비트 환경이라 할지라도 VS2010에서 32비트로 컴파일하고, 매트랩 역시 32비트 매트랩으로 mex 컴파일해서 사용해야 한다! 


5. 변경된 makemex

echo on


funcs = {

    'aria_init',  

    'arrobot_connect', 

    'arrobot_disconnect', 

    'arloginfo', 

    'arrobot_setvel', 

    'arrobot_setrotvel', 

    'arrobot_getx', 

    'arrobot_gety', 

    'arrobot_getth', 

    'arrobot_stop',

    'arrobot_length',

    'arrobot_width',

    'arrobot_radius',

    'arrobot_getsonarrange',

    'arrobot_getnumsonar',

    'arrobot_getdigin',

    'arrobot_setlatvel',

    'arrobot_getbatteryvoltage',

    'arrobot_getvel',

    'arrobot_getrotvel',

    'arrobot_getlatvel',

    'arrobot_setdeltaheading',

    'arrobot_resetpos',

 'arrobot_isstalled',

 'arrobot_isleftstalled',

  'arrobot_isrightstalled',

    'arrobot_setwheelvels',

    'arrobot_move'

}


% Unload old mex functions etc.  Note, if you add a new mex function above that

% does not match these patterns, add it to this list or a pattern that

% matches it.

clear aria_* arloginfo arrobot_*


 

% Set filenames and options depending on current platform

def = ''

switch computer

    case 'PCWIN'

ariainstdir = 'C:/Program Files/MobileRobots/Aria'

        ariaclink = '-L. -lariac_vc10_i386'

        arialink = '-L../lib -L../bin -lAriaVC10'

        def = '-DWIN32 -win32'

        ariadll = '../bin/AriaVC10.dll'

disp 'You are on Windows 32 bit. Will attempt to use AriaVC10.dll and ariac_vc10_i386.lib, built in Release configuration for win32 platform with Visual C++ 2010.'

    case 'PCWIN64'

ariainstdir = 'C:/Program Files/MobileRobots/Aria'

        ariaclink = '-L. -lariac_vc10_x64'

        def = '-DWIN32'

        arialink = '-L../lib64 -L../bin64 -lAriaVC10'

        ariadll = '../bin64/AriaVC10.dll'

disp 'You are on Windows 64 bit. Will attempt to use AriaVC10.dll and ariac_vc10_x64.lib, built in Release configuration for x64 platform with Visual C++ 2010.'

    case 'GLNX86'

ariainstdir = '/usr/local/Aria'

        ariaclink = '-L. -lariac'

        arialink = '-L../lib -lAria'

        ariadll = '../lib/libAria.so'

disp 'You are on Linux 32 bit. Will attempt to use libAria.so and libariac.so.'

    case 'GLNXA64'

ariainstdir = '/usr/local/Aria'

        ariaclink = '-L. -lariac'

        arialink = '-L../lib -lAria'

        ariadll = '../lib/libAria.so'

disp 'You are on Linux 64 bit. Will attempt to use libAria.so and libariac.so.'

case 'MACI64'

   disp 'Sorry, not set up for Mac yet. You will need to get ARIA and ariac built on Mac, then edit makemex.m to set the appropriate mex compilation flags under the MACI64 computer type case instead of displaying this message..'

        return

    otherwise

        disp 'error, unrecognized system type. (what kind of computer and OS are you on?)'

        computer

return

end


% Put a copy of the ARIA runtime library into the current directory

%disp 'Copying ARIA DLL into current directory so Matlab can easily find it...'

%eval(['copyfile ' ariadll ' .'])


% Compile all the mex functions listed above:

%%

% for i = 1:length(funcs)

%   cmd = sprintf('mex -g -v %s -DMATLAB -I. %s %s mex-src/%s.c', def, ariaclink, arialink, funcs{i});

%   cmd

%   eval(cmd)

% end


%% 

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/aria_init.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_connect.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_disconnect.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_setvel.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_setrotvel.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_stop.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_getsonarrange.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_getnumsonar.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arloginfo.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_getx.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_gety.c

mex -g -v -DWIN32 -win32 -DMATLAB -I. -L. -lariac_vc10_i386 -L../lib -L../bin -lAriaVC10 mex-src/arrobot_getth.c

disp('done');


6. 변경된 example.m

clc;

clear all;

close all;


%%

arrobot_disconnect

clear all


%% initialize with default arguments: (connect to robot connected to this

% computer via COM1 serial port)

aria_init 


% initialize aria to connect to a remote computer (e.g. a robot with a wifi

% interface instead of onboard computer, or a simulator running on another

% computer):

% aria_init -rh 10.0.151.11


% connect to the robot:

arrobot_connect

disp('connected? ');


%% 


% nr_sonar = arrobot_getnumsonar;

nr_sonar = 7;

sonar_data = zeros(nr_sonar, 1);


figure();

while 1

    for i = 1:nr_sonar

        sonar_data(i) = arrobot_getsonarrange(i);

    end

    clf;

    plot(sonar_data); drawnow;

    pause(.5);

end


%% make the robot drive in a small circle:

arrobot_setvel(100); arrobot_setrotvel(35);

disp 'use arrobot_stop to stop'


%%

arrobot_stop


%% 

x = arrobot_getx;

y = arrobot_getx;

fprintf('x: %.1f y: %.1f \n', x, y);


%% Disconnect! 

arrobot_disconnect 



저작자 표시 비영리 동일 조건 변경 허락
신고
« PREV : 1 : ··· : 24 : 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : ··· : 65 : NEXT »