7.1 Introduction
A pirouette is a familiar step in ballet. There are many types of pirouettes. We will focus on an en dehors (outside) pirouette from the fourth position. The dancer pliés (does a deep knee bend) and then straightens their legs, producing both an upward force to get on the tip of their pointe shoe and torque to turn about their axis of revolution.
In this chapter, we will classify pirouettes. The deep learning neural network will classify pirouettes by dancer. Four dancers will each do ten double pirouettes, and we will use them to train the deep learning network. The network can then be used to classify pirouettes.
This chapter will involve real-time data acquisition and deep learning. We will spend a considerable amount of time in this chapter creating software to interface with the hardware. While it is not deep learning, it is important to know how to get data from sensors for use in deep learning work. We give code snippets in this chapter. Only a few can be cut and pasted into the MATLAB command window. You’ll need to run the software in the downloadable library. Also remember, you will need the Instrument Control toolbox for this project.
Our subject dancers showing a pirouette are shown in Figure 7.1. We have three female dancers and one male dancer. Two of the women are wearing pointe shoes. The measurements will be accelerations, angular rates, and orientation. There isn’t any limit to the movements the dancers could do. We asked them all to do double pirouettes starting from the fourth position and returning to the fourth position. The fourth position is with one foot behind the other and separated by a quarter meter or so. This is in contrast to the fifth position where the feet are right against each other.
Each is shown at the beginning, middle, and end of the turn. All have slightly different positions, though all are doing very good pirouettes. There is no one “right” pirouette. If you were to watch the turns, you would not be able to see that they are that different. The goal is to develop a neural network that can classify pirouettes.
7.1.1 Inertial Measurement Unit
Our sensing means will be the LPMS-B2 IMU that has Bluetooth. The range is sufficient to work in a ballet studio.
LPMS-B2: 9-Axis Inertial Measurement Unit (IMU).
Parameter | Description |
Bluetooth | 2.1 + EDR / Low Energy (LE) 4.1 |
Communication distance | < 20 m |
Orientation range | Roll: ± 180∘; Pitch: ± 90∘; Yaw: ± 180∘ |
Resolution | < 0.01∘ |
Accuracy | < 0.5∘(static), < 2∘ RMS (dynamic) |
Accelerometer | 3 axes, ± 2∕ ± 4∕ ± 8∕ ± 16 g, 16 bits |
Gyroscope 3 axes | ± 125∕ ± 245∕ ± 500∕ ± 1000∕ ± 2000∘/s, 16 bits |
Data output format | 2 raw data / Euler angle / quaternion |
Data transmission rate up to | 2400Hz |
We will first work out the details of the data acquisition. We will then build a deep learning algorithm to train the system and later take data and classify the pirouette as being a pirouette done by a particular dancer. We’ll build up the data acquisition by first writing the MATLAB code to acquire the data. We will then create functions to display the data. We will then integrate it all into a GUI. Finally, we will create a deep learning classification system.
7.1.2 Physics
where ω is the angular rate and I is the inertia. T is our external torque. The external torque is due to a push off the floor and gravity. This is a vector equation. The vectors are T and ω. I is a 3×3 matrix.
Each component is a value about a particular axis. For example, Tx is the torque about the x-axis attached to the dancer. Figure 7.3 shows the system. We will only be concerned with rotation assuming all translational motion is damped. If the dancer’s center of mass is not above the box of their pointe shoe, they will experience an overturning torque.
This means a torque around the z-axis influences the angular rates about all three axes.
This is the perfect pirouette push-off because it only creates rotation about the vertical axis, which is what we want in a pirouette. To this, you need to add the forces needed to get on pointe with your center of mass over your pointe shoe tip.
While turning, the only significant external torque is due to friction between the pointe shoe tip and the floor. Friction resists both turning motion and translational motion. You don’t want a slight side force, perhaps due to a less than a great partner, to cause you to slide.
where rIMU is the vector from the dancer’s center of mass to the IMU.
There are six equations in total. The first is a vector equation with three components; the second two are scalar equations. The vector equation is three equations, and each scalar equation is just one equation. We can use these to create a simulation of a dancer. The second component models all z-axis internal rotation, including spotting.
7.2 Data Acquisition
7.2.1 Problem
We want to get data from the Bluetooth IMU.
7.2.2 Solution
We will use the MATLAB bluetooth function. We’ll create a function to read data from the IMU.
7.2.3 How It Works
We will write an interface for the Bluetooth device. First, make sure the IMU is charged. Connect it to your computer as shown in Figure 7.4. Push the button on the back. This turns it on and off. The status is indicated by the LED. The IMU comes with support software from the vendor, but you will not need any of their software as MATLAB does all the hard work for you.
This says it cannot recognize remote names or IDs. You may need a support package for your device in this case.
Reply data.
Byte | Content (hex) | Meaning |
0 | 3A | Packet Start |
1 | 01 | OpenMAT ID LSB (ID=1) |
2 | 00 | OpenMAT MSB |
3 | 09 | Command No. LSB (9d = GET_SENSOR_DATA) |
4 | 00 | Command No. MSB |
5 | 00 | Data Length LSB |
6 | 00 | Data Length MSB |
7–10 | xxxxxxxx | Timestamp |
11–14 | xxxxxxxx | Gyroscope data x-axis |
15–18 | xxxxxxxx | Gyroscope data y-axis |
19–22 | xxxxxxxx | Gyroscope data z-axis |
23–26 | xxxxxxxx | Accelerometer x-axis |
27–30 | xxxxxxxx | Accelerometer y-axis |
31–34 | xxxxxxxx | Accelerometer z-axis |
35–38 | xxxxxxxx | Magnetometer x-axis |
39–42 | xxxxxxxx | Magnetometer y-axis |
43–46 | xxxxxxxx | Magnetometer z-axis |
47–50 | xxxxxxxx | Orientation quaternion q0 |
51–54 | xxxxxxxx | Orientation quaternion q1 |
55–58 | xxxxxxxx | Orientation quaternion q2 |
59–62 | xxxxxxxx | Orientation quaternion q3 |
63 | xx | Check sum LSB |
64 | xx | Check sum MSB |
65 | 0D | Message end byte 1 |
66 | 0A | Message end byte 2 |
turn the IMU on and off. You might also have to restart MATLAB at times. This is because RemoteNames is empty, and this test is assuming it will not be. MATLAB then gets confused.
7.3 Orientation
7.3.1 Problem
We want to use quaternions to represent the orientation of our dancers in our deep learning system.
7.3.2 Solution
Implement basic quaternion operations. We need quaternion operations to process the quaternions from the IMU.
7.3.3 How It Works
times the argument . Since the sign is positive, the rotation must be a positive 90∘ rotation.
Note that the diagonal terms have the same form. The off-diagonal terms also all have the same form.
7.4 Dancer Simulation
7.4.1 Problem
We want to simulate a dancer for readers who don’t have access to the hardware.
7.4.2 Solution
We will write a right-hand side for the dancer based on the preceding equations and write a simulation with a control system.
7.4.3 How It Works
The remainder of the script plots the results and outputs the data, which would have come from the IMU, into a file.
We didn’t implement spotting (looking at the audience as much as possible during the turn) control. It would rotate the head so that it faces forward whenever the head was within 90 degrees or so of the front. We’d need to add a head angle for that purpose to the right-hand side, much like we added the z-axis angle.
7.5 Real-Time Plotting
7.5.1 Problem
We want to display data from the IMU in real time. This will allow us to monitor the pirouettes.
7.5.2 Solution
Use plot with drawnow to implement multiple figures of plots.
7.5.3 How It Works
7.6 Quaternion Display
7.6.1 Problem
We want to display the dancer’s orientation in real time.
7.6.2 Solution
Use patch to draw an OBJ model in a three-dimensional plot. The figure is easier to understand than the four quaternion elements. Our solution can handle three-axis rotation although typically we will only see single-axis rotation.
7.6.3 How It Works
We start with our Ballerina.obj file. It only has vertices and faces. A 3D drawing consists of a set of vertices. Each vertex is a point in space. The vertices are organized into faces. Each face is a triangle. Triangles are used for 3D drawings because they always form a plane. 3D processing hardware is designed to work with triangles, so this also gives the fastest results. The obj files for our software can only contain triangles. Each face can have only three vertices. Generally, obj files can have any size polynomials, that is, faces with more than three points. Most sources of obj files can provide tessellation services to convert polygons with more than three vertices into triangles. LoadOBJ.m will not draw models with anything other than triangular faces.
The rotation is slow because of the number of vertices. The figure is not articulated so the entire figure is rotated as a rigid body. We don’t employ texture maps. In any case, the purpose of this function is just to show orientation so it doesn’t matter.
7.7 Making the IMU Belt
7.7.1 Problem
We need to attach the IMU to our dancer.
7.7.2 Solution
We use the arm strap that is available from the manufacturer. We buy an elastic belt and make one that fits around the dancer’s waist.
7.7.3 How It Works
- 1.
LPMS-B2 Holder (available from Life Performance Research)
- 2.
Men’s No Show Elastic Stretch Belt Invisible Casual Web Belt Quick Release Flat Plastic Buckle (available from Amazon)
Remove the holder from the LPMS-B2 Holder. Cut the belt at the buckle and slide the holder onto the belt. Sew the belt at the buckle.
7.8 Testing the System
7.8.1 Problem
We want to test the data acquisition system. This will find any problems with the data acquisition process.
7.8.2 Solution
Have a dancer do changements, which are small jumps changing the foot position on landing.
7.8.3 How It Works
The dancer puts on the sensor belt, we push the calibrate button, then they do a series of changements. The dancer stands about 2 m from your computer to make acquisition easier. The dancer will do small jumps, known as changements. A changement is a small jump where the feet change positions starting from the fifth position. If the right foot is in the fifth position front at the start, it is in the back at the finish. Photos are shown in Figure 7.10.
If this happens, turn the device on and off. Restart MATLAB if that doesn’t work.
This is a MATLAB error and requires restarting MATLAB. It doesn’t happen very often. We ran the entire data collection with four dancers doing ten pirouettes each without ever experiencing the problem.
7.9 Classifying the Pirouette
7.9.1 Problem
We want to classify the pirouettes of our four dancers.
7.9.2 Solution
Create an LSTM that classifies pirouettes according to the dancer. The four labels are the dancers’ names.
7.9.3 How It Works
However, this should not impact the learning accuracy aside from slowing down the learning.
The training GUI is shown in Figure 7.13. It converges fairly well.
This result, > 80%, is pretty good considering the limited amount of data. Interestingly, the deep learning network could distinguish the dancers’ pirouettes. The data itself did not show any differences that were easy to identify to the human eye. Calibration could have been done better to make the data more consistent between dancers. It would have been interesting to collect data on multiple days. Other experiments would be to classify pirouettes done in pointe shoes and without. We might also have had the dancers do different types of turns to see if the network could still identify the dancer.
7.10 Data Acquisition GUI
7.10.1 Problem
Build a data acquisition GUI to display the real-time data and output it into training sets.
7.10.2 Solution
Integrate all the preceding recipes into a GUI.
7.10.3 How It Works
We aren’t going to use MATLAB’s GUIDE or app tools to build our GUI. We will hand-code it, which will give you a better idea of how a GUI works.
A callback is a function called by a uicontrol when the user interacts with the control. When you first open the GUI, it will look for the Bluetooth device. This can take a while.
Everything in DrawGUI has access to variables in DancerGUI. The GUI is shown in Figure 7.14. The 3D orientation display is in the upper-left corner. Real-time plots are on the right. Buttons are on the lower left, and the movie window is on the right.
- 1.
Turn the 3D on/off. The default model is big, so unless you add your model with fewer vertices, it should be set to off.
- 2.
The text box to its right is the name of the file. The GUI will add a number to the right of the name for each run.
- 3.
Save saves the current data to a file.
- 4.
Calibrate sets the default orientation and sets the gyro rates and accelerations to whatever it is reading when you hit the button. The dancer should be still when you hit calibrate. It will automatically compute the gravitational acceleration and subtract it during the test.
- 5.
Quit closes the GUI.
- 6.
Clear data clears out all the internal data storage.
- 7.
Start/Stop starts and stops the GUI.
The remaining three lines display the time, the angular rate vector, and the acceleration vector as numbers. This is the same data that is plotted.
is latex format. This will generate ωx in the plot labels.
We make it easier for the user to save files by reading the directory and adding a number to the end of the dancer filename that is one greater than the last filename number.
7.11 Hardware Sources
Hardware.
Component | Supplier | Part Number | Price |
IMU | LP-Research Inc. | LPMS-B2: 9-Axis Inertial Measurement Unit | $299.00 |
IMU Holder | LP-Research Inc. | LPMS-B2: Holder | $30.00 |
Belt | Amazon | Men’s Elastic Stretch Belt Invisible Casual Trousers Webbing Belt Plastic Buckle Black Fits 24” to 42” | $10.99 |