Wii Devices and the Hummingbird
There is no limit to the number of different robots you can make with your Hummingbird, but you can expand the possibilities even more by incorporating other devices. In this tutorial, you will learn how to use the Hummingbird with a Wii balance board and a Wiimote. Then you will be able to control a robot by waving the Wiimote or moving on the balance board!
For this project, you will be using an app called iiConnect2Scratch that was written by Steve Holmes (www.creativecomputerlab.com). You will need to use ScratchX in the Chrome web browser for this project. At this time, the iiConnect2Scratch app only works in Windows.
First, make sure that Chrome browser is installed on your computer. Then follow the instructions here for using Hummingbird in ScratchX; although the tutorial is for Chromebooks, the Chrome connection app works in Windows as well. Make sure that your Hummingbird is working in ScratchX before you move on to the next step.
Next, it is time to get your Wiimote and/or Wii balance board working in Scratch. Follow the directions in the iiConnect2Scratch User Guide to pair the Wii device with your computer. This can be tricky, so it may take you a couple of tries. Note: The user guide references Scratch 2.0, but you will be using ScratchX.
Download the iiConnect2Scratch installer from the iiConnect2Scratch website. Install this program, and then open it. You will see an icon appear at the bottom of your screen, but nothing else will happen when you open the program. This program needs to run in the background for you to be able to connect to the Wiimote and the balance board from ScratchX.
Download the iiConnect2Scratch extension file. Save this .js file to your desktop (or somewhere else where you can find it).
Open ScratchX from the Hummingbird Chrome app. Next, you need to load the iiConnect2Scratch extension. This is a little tricky. To do this, hold down the Function (Fn) key and right-click on the Load Experimental Extension button.
You should see the following window. Select the iiConnect2Scratch.js file and click Open. An Extensions window (or two) may pop up. Click OK in these windows.
Now, below the Hummingbird blocks, you will see blocks for the Wiimote and the Wii balance board!
The blocks you will need to use the balance board are shown below. The connect to wii block should be placed at the top of your program. This block connects ScratchX to the balance board. The balance board contains four force sensors, one in each corner. You can use the other four balance board blocks (topLeft, topRight, bottomLeft, and bottomRight) to find the values of these sensors.
Start by looking at the values of the force sensors. Declare a variable for each sensor and use a loop to continually set the values of the variables equal to the values of the sensors. An example program is shown below. Watch the values of these variables change as you shift your weight on the balance board.
You can use these variable directly to control a Hummingbird robot, but this tutorial will use the center of pressure instead. You can think about the center of pressure as the point on the balance board where your weight is concentrated. If you shift your body to the left, the center of pressure will move to the left. If you shift to the right, the center of pressure will move to the right. The weight of the user affects the force measurements, but by using the center of pressure, we can make a sprite or a Hummingbird robot move based on the user’s movement without worrying about their weight.
To calculate the center of pressure (COP), think about the balance board as having a coordinate system. We will call the coordinates of the center of pressure (COPx, COPy). You can calculate these coordinates using the formulas below. These formulas are from the work of Bartlett, Ting, and Bingham.
When you are standing on the balance board, the values of COPx and COPy will be between -1 and 1 (they may have other values when the board is empty). You can scale these values to control the position of a sprite on the screen. You should try this to make sure that the center of pressure is being calculated correctly. By placing the block below inside your loop, you should be able to make a sprite move around the screen as you shift your weight on the balance board. Note that there is no default sprite in ScratchX - you will need to add one to your project.
You can also scale the values of COPx and COPy to control Hummingbird components. For this project, we used the blocks below to control the speed and direction of the gear motors using the center of pressure.
The gear motors were connected to a four-bar linkage with an attached marker to create a drawing robot. Changing the motor speeds changes the pattern drawn by the marker. By using the balance board, we can draw by leaning in different directions! Sample code is provided in BalanceBoardDrawDemo.sbx.
Note: If you get NaN for COPx and COPy (0 for all the balance board blocks), this means that the computer has lost the bluetooth connection to the balance board. Go to the bluetooth settings and remove the balance board; then pair it to the computer again. For more information on pairing a Wii device, see the iiConnect2Scratch User Guide.
Pictured below are the main blocks you can use with the Wiimote. There are also blocks for the nunchuck that can be attached to the Wiimote (more on those later).
The connect to wii block should be placed at the top of your program. This block connects ScratchX to the Wiimote. The Wiimote contains a number of buttons, as well as an accelerometer. The button on block is equal to 1 when a given button is pressed, and 0 otherwise. For example, the program below will light an LED while the left button on the Wiimote is pressed. If you want to start a script when a button is pressed, you can use the when button pressed on block.
You can use the accel on block to get the value (from -1 to 1) of each of the three axes of the Wiimote accelerometer. Create three variables named accelX, accelY, and accelZ. Then use the script below to set these variables equal to the accelerometer values. As you move the accelerometer in different directions, look at how the variables change. What type of movement causes a change in each variable?
To control Hummingbird outputs using the accelerometer, the accelerometer values must be multiplied by a scaling factor. For example, a scaling factor of 100 can be used to control a tri-color LED with the accelerometer. In this example, the tri-color LED will be off when all three accelerometer values are negative.
If you have a nunchuck for your Wiimote, you can also use the three nunchuck blocks. The nunchuck contains two buttons, an accelerometer, and a joystick. The nunchuck button pressed on and the nunchuck accel on blocks work the same as the corresponding blocks for the main Wiimote. The joystick has two axes, x and y. The nunchuck joystick on block measures the position of the joystick (from approximately -0.5 to 0.5) along both of these axes.
One fun application is to use the Wiimote to control a Hummingbird rover. This is shown in the video above, and sample code is given in WiimoteHummingbirdRover.sbx. The rover is controlled using the accelerometer of the Wiimmote.
The key decision block is shown below. The y-axis of the Wiimote moves the rover forward and backward, while the x-axis turns the rover. If the absolute value of the y-acceleration is bigger than the absolute value of the x-acceleration, the robot moves forward or back. Otherwise, the robot turns in place. Once this decision is made, the speed of the movement is obtained by scaling the value of the accelerometer.
The many input options on the Wiimote also make it a good choice for controlling a simple robot arm. This is shown in the video above, and sample code is given in WiimoteArmDemo.sbx. Our sample robot arm is shown below. It contains three servos. Servos 1 and 2 move the arm around, and servo 3 opens and closes the gripper. This arm only moves around on a horizontal surface. The Hummingbird servos are not strong enough to lift the gripper off the surface.
When the B button of the Wiimote is pressed, the x-axis of the Wiimote accelerometer controls servo 1. When the Z button on the nunchuck is pressed, the x-axis of the joystick controls servo 2. The buttons are incorporated into the control scheme to prevent accidental movement of the arm. Mathematical expressions are used to map the inputs from the Wiimote and nunchuck to angles for the servo motors.
The gripper is controlled by two buttons on the Wiimote. Button 1 closes the gripper, and button 2 opens it.
Note: If the accelerometer or joystick values stop changing, this means that the computer has lost the bluetooth connection to the Wiimote. Go to the bluetooth settings and remove the Wiimote; then pair it to the computer again. For more information on pairing a Wii device, see the iiConnect2Scratch User Guide.
These are just a few examples of how you can use the Wiimote and the Wii balance board to control Hummingbird robots. Come up with your own idea, and be sure to tell us about it!