A hobby is a very important thing for every person. No matter how busy you are, if you love something you will definitely find some time for for that. Most people love dancing and they dance every free time they can find. However, though their hobby is dancing, many out of those people are not very good at it, but what they have is the passion towards dancing. To be a pro at a field like dancing, you need lots and lots of practice. Some people go to classes to learn dancing and some follow video tutorials. But, no one might have thought of this: "What if there is someone to guide you to practice dances whenever you want?"
This is where "Train Me" jumps in. Train Me is a digital dancing coach that supports you to practice various types of dances. It monitors your position in the practicing area, and alerts if you are not in the correct position in a particular time. Using the Graphical User Interface of the "Train Me" system, you can add sound tracks and program the correct dancing positions for particular time intervals in the sound track. Then, it will monitor your position with the given position while playing back the sound track.
Introduction to WalabotWalabot is a 3D imaging sensor which allows you to track objects in 3D space. This provides a great platform to those who are interested in Radar, Lidar and for those who do not have much knowledge on them, to work with target detection and many more applications.
Walabot supports for PC, Raspberry pi and Android.
For this project, I'm using Walabot Pro, which contains 18 antennas. To get start with the Walabot device, download and install Walabot SDK. It will guide you to configuring the device and how to work with it.
Under target detection tab, you detect objects in front of the device. For "Train Me" I'm going to use this method. Now let's move on to the implementation.
ImplementationWALABOT supports many languages such as Python, C++, C# etc. But for this project I decided to use Java to develop the front end design while using Python for the Walabot programming part.
- Python
Python is a 4th generation programming language which helps to program easily even for people with less programming knowledge. Further, Walabot provides a python library to make it easy to work with the device and also there are many sample projects completed using python. In this project I'm using "SensorTargets.py" code file to track the position of the dancer.
- Java
To build the GUI, I used Java as many people are familiar with building applications with the NetBeans IDE. Walabot does not have libraries to work with Java. Therefore, I wanted to show, how Walabot works with Java while using the Python library.
InterfaceThe interface consists of 3 main parts.
- The top panel is used to add sound tracks and program positions.
- The right panel is used to configure parameters.
- The center panel indicates the positions. (Assume it as the top view of your dancing area)
Let's see how it works. ( Required files and libraries are attached at the end.)
Click on the "OPEN" button in the top panel and add a sound track. This should be in the ".wav" format. To program the positions set the "Mode" to "Program" and click on the "START" button. Click on the "PLAY" button to start playing the sound track. Pause the track by clicking on the "PAUSE" button and click any position you need as the place you want to be on that time on the center panel and click "SAVE". Continue this procedure for the whole track. All position markers are in the color green in programming mode.
Click "END" button to end programming the positions and select the "Play" mode. After ending the programming mode, all position markers will turn in to grey color. Click the "STOP" button to get the sound track to its initial position. Now "Train Me" is ready to monitor your movements.
Click on the "PLAY" button. The our software will get the readings from the Walabot and compare it with the programmed positions. Labels will turn into red to indicate the position you need to be at for the particular time. If you are not in the correct position or even inside the given tolerance area by the time, a beep sound will occur to alert you.
Working with NetBeansI have uploaded the NetBeans project folder at the end. Import the project file into NetBeans.
All top panel button functions are included in one method.
if (button == buttonOpen) { #Open file explorer to select the sound track
openFile();
buttonStop.setEnabled(true);
buttonPlay.setEnabled(true);
} else if (button == buttonStop) {
stopPlaying();
resetColor();
} else if (button == buttonPlay) { #Playback the selected sound track
if (!isPlaying) {
playBack();
} else {
if (!isPause) { #Pause the sound track and enable the
pausePlaying(); #coordinate saving mode
buttonSaveCoordinates.setEnabled(true);
} else {
resumePlaying();
}
}
} else if (button == buttonProgramStart) { #Enable the programming mode
if (!programStart) {
programStart = true;
button.setText("END");
buttonSaveCoordinates.setEnabled(true);
} else {
programStart = false; #End the programming mode
button.setText("START");
save();
map.clear();
}
Labels are used to mark the positions in the center panel. Label is placed with the mouse click.
if (clickCount < 15) {
if (!colorLabels.isEmpty()) {
jPanelView.setLayout(null);
colorLabels.get(clickCount).setVisible(true);
colorLabels.get(clickCount).setBackground(Color.GREEN);
colorLabels.get(clickCount).setLocation(xCoord - 5, yCoord - 5);
}
}
While playing the sound track after programming, the labels turn into red according to the programmed time. (Figure 1)
private void setView(String currentTime) {
if (map.containsKey(currentTime)) {
String[] coordinate = map.get(currentTime).split(",");
x = Integer.parseInt(coordinate[0]);
y = Integer.parseInt(coordinate[1]);
labelNumber = coordinate[2];
for (JLabel label : playLabels) {
if (label.getText().equals(labelNumber)) {
jPanelView.setLayout(null);
label.setLocation(x - 5, y - 5);
label.setBackground(Color.RED);
}
}
}
}
"C" label ( Figure 1 ) indicates our current position tracked by Walabot. While playing the sound track, a separate method is called to get the readings from the Walabot.
private void setMovement(){
String cords = pythonConnection.getCoordinates();
String[] pyCoordinates = cords.split(" ");
pyLabel.setLocation(Integer.parseInt(pyCoordinates[0]), Integer.parseInt(pyCoordinates[1])+250);
}
After getting the readings from Walabot, it will be compared with the programmed coordinates and trigger the alarm if you are not in the exact position.
To minimize the alarm triggering due to various reasons, I have added another parameter field for set the tolerance. After setting the position, the program will allow you to be in a circle with the radius of your tolerance value without triggering the alarm.
gapX = abs(x - pyLabel.getX());
gapY = abs(y - pyLabel.getY());
if (gapX > posTolerance || gapY > posTolerance) {
alert();
}
PythonInstall Walabot SDK on your machine before working with Python. Download SensorTargets from the sample walabot applications. This code file is to detect targets in front of the Walabot. You can also use Walabot SDK to see this graphically.
Though Walabot is a 3D imaging sensor, to detect targets in 2D plane, Walabot library contains a image slicing feature called "GetRawImageSlice( )". If you run the code, you can notice that the program prints coordinates of the detected targets in python shell.
I have modified the code according to requirements of "Train Me" and as well as to make it easy to connect it with the GUI. As the python file is called from java, the entire python code is separated in to a few methods.
The WalabotAPI file is loaded to the SensorTargets program from a specified path. But to minimize errors, I have included WalabotAPI file in the same directory.
if platform == 'win32':
modulePath = join('WalabotAPI.py')
elif platform.startswith('linux'):
modulePath = join('/usr', 'share', 'walabot', 'python', 'WalabotAPI.py')
If you try to run SensorTargets from java, it gives an error while loading the WalabotAPI library. You can find the modified library which supports for java, at the end.
When running the program, it will save received coordinates of the detected target, in a text file.
if targets:
for i, target in enumerate(targets):
tempz = round(target.zPosCm,0) #Coordinates are rounded to 0 decimal points
tempy = round(target.xPosCm,0)
f = open("output.txt","w")
f.write("%d %d" % (tempz,tempy))
f.close()
break
With the break function, the loop prints only one target.
Combining TogetherA third party library is needed to execute Python files from Java. Here, I'm using "Jython" for this purpose. First you have to download Jython and install. Then Go to the project explorer panel and right click on the libraries. Select "Add Jar/Folder" and navigate to the jython installed location and select jython.jar.
When running the GUI, the 2 buttons at the right panel are to communicate with python. By clicking "Set" button after setting all parameters, it will save all the values in a text file.
try( PrintWriter out = new PrintWriter( "Data.txt" ) ){ //Create the text file
String rmin = jTextField1.getText();
String rmax = jTextField2.getText();
String rres = jTextField3.getText();
String tmin = jTextField6.getText(); //Get values from text fields
String tmax = jTextField5.getText();
String tres = jTextField4.getText();
String pmin = jTextField7.getText();
String pmax = jTextField8.getText();
String pres = jTextField9.getText();
String thrs = jTextField10.getText();
String mti = "";
if(jCheckBox1.isSelected()) {mti = "True";}
else {mti = "False";}
out.println(rmin);
out.println(rmax);
out.println(rres);
out.println(tmin);
out.println(tmax); //Write values to the text file
out.println(tres);
out.println(pmin);
out.println(pmax);
out.println(pres);
out.println(thrs);
out.println(mti);
By clicking "Connect Walabot", it will call to a method which runs the python file.
public void callPython() {
PythonConnection test = new PythonConnection();
test.execfile("SensorApp.py");//give the python file name here
PyInstance hello = test.createClass("readTarget", "None");
PyObject s = hello.invoke("run");
}
After connecting it will start to save the coordinates in the text file.
TestingBefore testing this, you need to select a free area. Then place your Walabot where it can track you easily. Here, I'm using the Walabot box as a stand by sticking the metal plate which comes with the package.
The device is mounted at 1m height with no obstacles near by. Now we have to set the parameter values to increase the accuracy of target detection. If you are not familiar with parameter values setup, use Target Detection application on Walabot SDK and calibrate it to detect target within your dancing area.
Select a music track and program the positions as shown in the previous video. If it's hard to select positions by looking at the screen, you can pause the track and go to the exact position in the room and observe the position of the "C" marker.
As shown in the video, after configuring the parameter values, "Train Me" detects your position with minimum errors. According to my observations the maximum error I got is about 30cm. You can set the tolerance value to avoid unnecessary alarm triggering.
I hope this will be a very useful software to all who love dancing and happy to make a useful software to our day to day lives.
Your ideas and suggestions are welcome. Enjoy and keep practicing.
Cheers!!!
Comments