| |
| 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 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
|
> > |
- 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
|
| |
|
| |
- 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).
|
|
< < | |
> > | |
| | % 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\EG111-H
- 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.
- 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.
- 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 |
| | 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.
|
|
< < |
- 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.
|
> > |
- 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.
|
| | |
| | end % while
-
- The main logic of any program using WiiLAB will be contained inside a while loop similar to this one.
|
|
< < |
- 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.
|
> > |
- 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.
|
| |
|
| | % 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 |
> > | % 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. |