Educational materials

View   r4  >  r3  >  r2  >  r1
WiiLabMatlabGettingStartedTutorial 4 - 31 Jul 2008 - Main.JordanBrindza
Line: 1 to 1
 
META TOPICPARENT name="MATLABCode"

WiiLAB Example Code - Getting Started With WiiLAB and MATLAB

Line: 6 to 6
 
Changed:
<
<
This page goes over the SkeletonCode file and what is included in it. There are also two programs that use the SkeletonCode file to create simple programs that use the Wiimote.
  • The first is a program to plot a set of acceleration data retrieved from the Wiimote, found here?
  • The second shows how to use the Wiimote's acceleration to move a graphics object around the screen, found here
>
>
This page goes over the SkeletonCode file and what is included in it. There is also a program that uses the SkeletonCode file to create simple program that shows how to use the Wiimote's acceleration to move a graphics object around the screen, found here
 


WiiLabMatlabGettingStartedTutorial 3 - 22 Jul 2008 - Main.JessicaSzweda
Line: 1 to 1
 
META TOPICPARENT name="MATLABCode"

WiiLAB Example Code - Getting Started With WiiLAB and MATLAB

Changed:
<
<
This tutorial shows you how to use WiiLAB and the Wiimote in a MATLAB program. You have to first install the WiiLAB libraries on your computer, a tutorial on how to do that is found here. It would also be beneficial to go over the most common WiiLAB functions and their uses which can be found here.
>
>
This tutorial shows you how to use WiiLAB and the Wiimote in a MATLAB program. You have to first install the WiiLAB libraries on your computer; a tutorial on how to do that is found here. It would also be beneficial to go over the most common WiiLAB functions and their uses, which can be found here.
 

This page goes over the SkeletonCode file and what is included in it. There are also two programs that use the SkeletonCode file to create simple programs that use the Wiimote.

Changed:
<
<
  • The first is a program to plot a set of acceleration data retrieved from the Wiimote found here?
  • The second shows how to use the Wiimote's acceleration to move an graphics object around the screen found here
>
>
  • The first is a program to plot a set of acceleration data retrieved from the Wiimote, found here?
  • The second shows how to use the Wiimote's acceleration to move a graphics object around the screen, found here
 

Line: 18 to 18
 

  1. The first thing you should do in every program is to add the paths that contain any custom functions you are using. In our case we need to add the path for the WiimoteFunctions and the graphics functions that we will be using (EG111-H for UND students).
Changed:
<
<
    • The actual path will depend on your personal computer. Below is the commands assuming you used the installer we provided:
      % Add the paths for the Wiimote and Graphics Functions
>
>
    • The actual path will depend on your personal computer. Below are the commands assuming you used the installer we provided:
      % Add the paths for the Wiimote and Graphics Functions
 % These paths are assuming you are using the installer for WiiLAB? that was % provided. If you did not then change the paths to the location of the % WiimoteFunctions? and EG111-H folders on your computer
Line: 26 to 26
 addpath C:\'Program Files'\Wiimote\WiiLAB_Matlab\EG111-H
  1. The next thing that you need to do in every program that uses WiiLAB and the Wiimote is to connect the Wiimote.
Changed:
<
<
    • This is done by simply calling the initializeWiimote global function. This will connect to the Wiimote and initialize the MATLAB object that will communicate with the Wiimote.
    • Almost every program that uses the Wiimote will also be using some sort of graphics functions. This is also a good point in the program to initialize the graphics window you are going to be using. For those using the EG111 graphics functions then the initializeWindow(0) command will create the graphics window.
  1. After the initializeWiimote method is called it is always a good idea to make sure that the Wiimote was connected successfully. The initializeWiimote function will write a command line message indicating whether or not it was able to connect to the Wiimote, however this does not allow our program to automatically check if the Wiimote was connected. The isWiimoteConnected function was added for this purpose. The function will return a number greater than zero if the Wiimote was successfully connected and a number less than or equal to zero if it was not.
    • The following snippet of code demonstrates how to use the isWiimoteConnected function to check if the Wiimote was successfully connected:
>
>
    • This is done by simply calling the initializeWiimote global function. This will connect to the Wiimote and initialize the MATLAB object that will communicate with the Wiimote.
    • Almost every program that uses the Wiimote will also be using some sort of graphics functions. This is also a good point in the program to initialize the graphics window you are going to be using. For those using the EG111 graphics functions then the initializeWindow(0) command will create the graphics window.
  1. After the initializeWiimote method is called it is always a good idea to make sure that the Wiimote was connected successfully. The initializeWiimote function will write a command line message indicating whether or not it was able to connect to the Wiimote, but this does not allow our program to automatically check if the Wiimote was connected. The isWiimoteConnected function was added for this purpose. The function will return a number greater than zero if the Wiimote was successfully connected and a number less than or equal to zero if it was not.
    • The following snippet of code demonstrates how to use the isWiimoteConnected function to check if the Wiimote was successfully connected:
 if( isWiimoteConnected() > 0 ) disp('The Wiimote is Connected!'); else
Line: 37 to 37
 end
    • It is recommended that you make this check after connecting to the Wiimote to make sure it was successful before continuing to the rest of the program.
Changed:
<
<
  1. Now that the Wiimote is successfully connected we start the actual program. Using the Wiimote with WiiLAB will require you to poll the Wiimote information.
    • Polling programing technique of continuously checking the status of Wiimote after a set amount of time. In our case it will be on the millisecond time scale.
      • It is not essential to have a complete understanding of how polling works in order to use WiiLAB. The polling logic is included included in the skeleton code. If you would like to learn more about polling the Wikipedia page contains a good explanation and can be found here.
>
>
  1. Now that the Wiimote is successfully connected, we start the actual program. Using the Wiimote with WiiLAB will require you to poll the Wiimote information.
    • Polling programming technique of continuously checking the status of Wiimote after a set amount of time. In our case it will be on the millisecond time scale.
      • It is not essential to have a complete understanding of how polling works in order to use WiiLAB. The polling logic is included in the skeleton code. If you would like to learn more about polling, the Wikipedia page contains a good explanation and can be found here.
 
    • The simplest way to implement this in MATLAB is to use a while loop as shown below. This while loop will run until 'HOME' is pressed on the Wiimote, all the while retrieving and displaying the current acceleration values from the Wiimote.
      % Used for polling the Wiimote data
      % This loop will run until 'HOME' on the Wiimote is Pressed
Line: 58 to 58
 end % while
    • The main logic of any program using WiiLAB will be contained inside a while loop similar to this one.
Changed:
<
<
  1. Finally, the very last thing that you should do is disconnect the Wiimote. To do this simply call the disconnectWiimote function.
    • This will disconnect the Wiimote from your program allowing another program to connect to it. It is always good practice to disconnect the Wiimote when your program is finished with it.
>
>
  1. Finally, the very last thing that you should do is disconnect the Wiimote. To do this simply call the disconnectWiimote function.
    • This will disconnect the Wiimote from your program, allowing another program to connect to it. It is always good practice to disconnect the Wiimote when your program is finished with it.
 


Line: 98 to 98
 % YOUR CODE HERE % Any graphics objects that will be used throughout your program should go % here.
Changed:
<
<
% For example, if you are creating an program that will use the Wiimote
>
>
% For example, if you are creating a program that will use the Wiimote
 % to move a circle around the screen, you should create the circle here.

WiiLabMatlabGettingStartedTutorial 2 - 21 Jul 2008 - Main.JordanBrindza
Line: 1 to 1
 
META TOPICPARENT name="MATLABCode"

WiiLAB Example Code - Getting Started With WiiLAB and MATLAB


WiiLabMatlabGettingStartedTutorial 1 - 21 Jul 2008 - Main.JordanBrindza
Line: 1 to 1
Added:
>
>
META TOPICPARENT name="MATLABCode"

WiiLAB Example Code - Getting Started With WiiLAB and MATLAB

This tutorial shows you how to use WiiLAB and the Wiimote in a MATLAB program. You have to first install the WiiLAB libraries on your computer, a tutorial on how to do that is found here. It would also be beneficial to go over the most common WiiLAB functions and their uses which can be found here.


This page goes over the SkeletonCode file and what is included in it. There are also two programs that use the SkeletonCode file to create simple programs that use the Wiimote.

  • The first is a program to plot a set of acceleration data retrieved from the Wiimote found here?
  • The second shows how to use the Wiimote's acceleration to move an graphics object around the screen found here



SkeletonCode

Getting Started with WiiLAB

  1. The first thing you should do in every program is to add the paths that contain any custom functions you are using. In our case we need to add the path for the WiimoteFunctions and the graphics functions that we will be using (EG111-H for UND students).
    • The actual path will depend on your personal computer. Below is the commands assuming you used the installer we provided:
      % Add the paths for the Wiimote and Graphics Functions
      % These paths are assuming you are using the installer for WiiLAB that was
      % provided. If you did not then change the paths to the location of the
      % WiimoteFunctions and EG111-H folders on your computer
      addpath C:\'Program Files'\Wiimote\WiiLAB_Matlab\WiimoteFunctions
      addpath C:\'Program Files'\Wiimote\WiiLAB_Matlab\EG111-H
      
  2. The next thing that you need to do in every program that uses WiiLAB and the Wiimote is to connect the Wiimote.
    • This is done by simply calling the initializeWiimote global function. This will connect to the Wiimote and initialize the MATLAB object that will communicate with the Wiimote.
    • Almost every program that uses the Wiimote will also be using some sort of graphics functions. This is also a good point in the program to initialize the graphics window you are going to be using. For those using the EG111 graphics functions then the initializeWindow(0) command will create the graphics window.
  3. After the initializeWiimote method is called it is always a good idea to make sure that the Wiimote was connected successfully. The initializeWiimote function will write a command line message indicating whether or not it was able to connect to the Wiimote, however this does not allow our program to automatically check if the Wiimote was connected. The isWiimoteConnected function was added for this purpose. The function will return a number greater than zero if the Wiimote was successfully connected and a number less than or equal to zero if it was not.
    • The following snippet of code demonstrates how to use the isWiimoteConnected function to check if the Wiimote was successfully connected:
      if( isWiimoteConnected() > 0 )
          disp('The Wiimote is Connected!');
      else
          disp('The Wiimote is not Connected');
      end
      
    • It is recommended that you make this check after connecting to the Wiimote to make sure it was successful before continuing to the rest of the program.
  4. Now that the Wiimote is successfully connected we start the actual program. Using the Wiimote with WiiLAB will require you to poll the Wiimote information.
    • Polling programing technique of continuously checking the status of Wiimote after a set amount of time. In our case it will be on the millisecond time scale.
      • It is not essential to have a complete understanding of how polling works in order to use WiiLAB. The polling logic is included included in the skeleton code. If you would like to learn more about polling the Wikipedia page contains a good explanation and can be found here.
    • The simplest way to implement this in MATLAB is to use a while loop as shown below. This while loop will run until 'HOME' is pressed on the Wiimote, all the while retrieving and displaying the current acceleration values from the Wiimote.
      % Used for polling the Wiimote data
      % This loop will run until 'HOME' on the Wiimote is Pressed
      while(~isButtonPressed('HOME'))
              
          [x y z] = getWiimoteAccel();
      
          disp(['x = ' num2str(x)]);
          disp(['y = ' num2str(y)]);
          disp(['z = ' num2str(z)]);
      
          % Pause - This is a required step. If it is not included you will
          % experience unexpected behavior.
          pause(.001);                
          
      end % while    
      
    • The main logic of any program using WiiLAB will be contained inside a while loop similar to this one.
  5. Finally, the very last thing that you should do is disconnect the Wiimote. To do this simply call the disconnectWiimote function.
    • This will disconnect the Wiimote from your program allowing another program to connect to it. It is always good practice to disconnect the Wiimote when your program is finished with it.




Below is the complete version of the default program that you should start with. The .m file is also attached at the bottom of the page.

%------------------------------------------------------------------------
%  Getting Started Program Demo
%  
%  This program is designed to give a new user the skeleton code to allow
%  them to easily and quickly begin using WiiLAB. The program contains all
%  the vital code that is needed to connect to and use the Wiimote along
%  with reserved sections for the user to add their code.
%
%  Jordan Brindza, University of Notre Dame
%------------------------------------------------------------------------

% Add the paths for the Wiimote and Graphics Functions
% These paths are assuming you are using the installer for WiiLAB that was
% provided. If you did not then change the paths to the location of the
% WiimoteFunctions and EG111-H folders on your computer
addpath C:\'Program Files'\Wiimote\WiiLAB_Matlab\WiimoteFunctions
addpath C:\'Program Files'\Wiimote\WiiLAB_Matlab\EG111-H


% Connect to the Wiimote
initializeWiimote();

% Create the graphics Window (optional but recommended)
initializeWindow(0);


% -------------------------------------------------------------


% YOUR CODE HERE
% Any graphics objects that will be used throughout your program should go
% here.
% For example, if you are creating an program that will use the Wiimote 
% to move a circle around the screen, you should create the circle here.


% -------------------------------------------------------------


% Check to make sure the Wiimote is connected
if( isWiimoteConnected() > 0 )
    
    
    % Main program loop
    % Used for polling the Wiimote data
    % This loop will run until 'HOME' on the Wiimote is Pressed
    while(~isButtonPressed('HOME'))
        
        
        % -------------------------------------------------------------    
    
    
    
        
        % YOUR CODE HERE
        % The main portion of your program will go here. 
        
    
    
        % -------------------------------------------------------------
    
    
        % Redraw - This is for the graphics functions to make sure they are
        % displaying the most recent changes
        redraw();
        
        % Pause - This is a required step. If it is not included you will
        % experience unexpected behavior.
        pause(.001);                
    
    end % while    
    
else
    
    % The Wiimote was not successfully connected
    message = [ 'There was a problem with connecting to the Wiimote. ' ...
                'Please make sure the Wiimote is properly connected ' ...
                'to the computer and rerun the program.' ];
                
    % This will write the message to the command line        
    disp(message);
    
    % This will create a message box with the message
    uiwait(msgbox(message, 'Connection Problem', 'error'));   
    
end % if


% Disconnect the Wiimote
disconnectWiimote();

-- JordanBrindza - 21 Jul 2008

META FILEATTACHMENT attachment="SkeletonCode.m" attr="" comment="" date="1216654599" name="SkeletonCode.m" path="SkeletonCode.m" size="2480" stream="SkeletonCode.m" tmpFilename="/usr/tmp/CGItemp26835" user="JordanBrindza" version="1"

Revision 4r4 - 31 Jul 2008 - 16:08:28 - JordanBrindza
Revision 3r3 - 22 Jul 2008 - 18:55:11 - JessicaSzweda
Revision 2r2 - 21 Jul 2008 - 20:37:00 - JordanBrindza
Revision 1r1 - 21 Jul 2008 - 15:43:35 - JordanBrindza
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Syndicate this site RSSATOM