How to develop and register a Sota app in Java

We have summarized the flow of development and registration of Sota-kun application using Java. The source for the app created in this article can be found on GitHub.

Development environment

In this article, we have developed an application for Intel (R) Edison version Sota (developer version).

How to develop Sota app

In the official documentation, there are two ways to develop the Sota app:

-[Try using VstoneMagic](http://www.vstone.co.jp/sotamanual/index.php?VstoneMagic%E3%82%92%E4%BD%BF%E3%81%A3%E3%81 % A6% E3% 81% BF% E3% 82% 8B) -[Try programming with Java](http://www.vstone.co.jp/sotamanual/index.php?Java%E3%81%A7%E3%83%97%E3%83%AD%E3 % 82% B0% E3% 83% A9% E3% 83% 9F% E3% 83% B3% E3% 82% B0% E3% 82% 92% E3% 81% 97% E3% 81% A6% E3% 81 % BF% E3% 82% 8B)

VstoneMagic is a programming software for Sota that develops apps by connecting pre-prepared instruction blocks. As an advantage of VstoneMagic, how to register the application is written in the official document, and you can execute the application created from "Run application" just by operating Sota itself. However, there are restrictions on application development due to the specifications that connect instruction blocks. Therefore, in this article, we will develop an application in Java. The registration method of the application developed in Java is not written in the official document, so I will explain the method below.

Development environment preparation

First of all, [Try programming with Java](http://www.vstone.co.jp/sotamanual/index.php?Java%E3%81%A7%E3%83%97%E3%83%] AD% E3% 82% B0% E3% 83% A9% E3% 83% 9F% E3% 83% B3% E3% 82% B0% E3% 82% 92% E3% 81% 97% E3% 81% A6% Follow E3% 81% BF% E3% 82% 8B) to execute the sample program. In the following, we will explain assuming that you have Eclipse as the development environment and SotaSample as the sample program project.

Create a new project

From here, we will develop applications in Java. In this article, Sota will develop an app that recognizes what you say and returns it to you. It is the same as SpeechRecSample.java in SotaSample.

First, create a new project from "File"-> "New"-> "Java Project". The project name should be SotaRepeat. By the way, when managing with GitHub, I think that GitHub and Eclipse cooperation and summary --Qiita will be helpful.

After creating a new project, right-click on the src folder → "New" → "Package" to create a package. I named the package com.example.sotarepeat (I don't know how to name the package).

Java program implementation

Right-click on the package name → "New" → "Class" to create the main Java file SotaRepeat.java and implement it. The flow of the application is as follows.

  1. Use voice recognition to get what you say as a string
  2. Let Sota speak the string obtained using TextToSpeech
  3. Repeat steps 1 and 2 any number of times

The implemented SotaRepeat.java is listed below.

SotaRepeat.java


/* SotaRepeat.java
 *An application that returns the voice recognition result with TTS
 */

package com.example.sotarepeat;

import jp.vstone.RobotLib.CPlayWave;
import jp.vstone.RobotLib.CRobotMem;
import jp.vstone.RobotLib.CSotaMotion;
import jp.vstone.sotatalk.MotionAsSotaWish;
import jp.vstone.sotatalk.SpeechRecog;
import jp.vstone.sotatalk.SpeechRecog.RecogResult;
import jp.vstone.sotatalk.TextToSpeechSota;

public class SotaRepeat {
	static final String TAG = "SotaRepeat";
	static final int LOOP_NUM = 10;

	public static void main(String[] args) {
		//VSMD and communication socket / memory access class
		CRobotMem mem = new CRobotMem();
		//Motion control class for Sota
		CSotaMotion motion = new CSotaMotion(mem);
		SpeechRecog recog = new SpeechRecog(motion);
		MotionAsSotaWish wish = new MotionAsSotaWish(motion);

		if (mem.Connect()) {
			//Initialize VSMD to Sota spec
			motion.InitRobot_Sota();
			motion.ServoOn();

			for (int i=0; i<LOOP_NUM; i++) {
				//Voice recognition (supports voice up to 10 seconds)
				RecogResult result = recog.getRecognition(10000);
				if (result.recognized) {
					//TextToSpeech the recognition result
					wish.Say(result.getBasicResult(), MotionAsSotaWish.MOTION_TYPE_TALK);
					//CPlayWave.PlayWave(TextToSpeechSota.getTTSFile(result.getBasicResult()),true);

					if(result.getBasicResult().contains("end")){
						CPlayWave.PlayWave(TextToSpeechSota.getTTSFile("I'm done"),true);
						break;
					}
				}
				if (i == LOOP_NUM - 1) {
					CPlayWave.PlayWave(TextToSpeechSota.getTTSFile("I'm tired so I'm done"), true);
				}
			}
			motion.ServoOff();
		}
	}
}

If Eclipse gets angry that there is no such thing in the place to import jp.vstone.RobotLib.CPlayWave etc., right click on SotaRepeat → "Build Path" → "External Archive" From "Add", specify sotalib.jar in the lib folder in SotaSample.

Creating a jar file

Create a jar file to register the developed application in Sota. First, right-click on SotaRepeat → select "Export" → "JAR File". Make sure that SotaRepeat is checked on the "JAR Export" screen, specify the jar file to export to, and click "Next". Leave the default settings for "JAR Package Options" and click "Next". For "JAR Manifest Specifications", check "Save Manifest in Workspace" as shown in the screen below, and specify the manifest file name. Also, specify SotaRepeat as the main class. And "done".

jar_manifest_sample01.jpg

Next, edit the created MANIFEST.MF. If it is left as it is, the classpath is not described, so an error will occur when the application is executed. If you created a manifest file like the image above, you should see MANIFEST.MF look like this:

MANIFEST.MF


Manifest-Version: 1.0
Sealed: true
Main-Class: com.example.sotarepeat.SotaRepeat

Add the following description here.

Class-Path: . /home/vstone/lib/core-2.2.jar /home/vstone/lib/javase-2.2.jar /home/vstone/lib/jna-4.1.0.jar /home/vstone/lib/opencv-310.jar /home/vstone/lib/sotalib.jar /home/vstone/lib/SRClientHelper.jar /home/vstone/lib/gson-2.6.1.jar

It may be unnecessary because it is added to the classpath indiscriminately, but the miso is adding / home / vstone / lib / gson-2.6.1.jar. I didn't write it at first because it is not included in the lib folder of SotaSample, but when I ran it on the Sota console, I got an error saying that gson was needed, so I added it.

Use this manifest file to create a new jar file. Create a jar file in the same way as before, but in the "JAR manifest specification", check "Use existing manifest in workspace" as shown below. And "done". jar_manifest_sample02.jpg

Transfer jar file

Transfer the created jar file to Sota. For the flow from here, How to register your own jar in Sota --Qiita was very helpful. What is written is basically the same.

In my environment, I am connected to Sota via wireless LAN, so I will transfer using WinSCP. Create a SotaRepeat directory under / home / vstone / vstonemagic / app / jar in Sota, and put the created jar file in it.

Description of application setting file

The program to be executed from "Run App" of Sota is described in the configuration file / home / vstone / vstonemagic / app / jar / app.properties. Rewrite this configuration file as follows.

app.properties


length=1              #Number of apps
Debug=false
TimeZone=Asia/Tokyo

app1.title=SotaRepeat
app1.workingdir=SotaRepeat/
app1.jar=SotaRepeat.jar
app1.type=app
app1.trigger=
app1.triggeroption=

Make sure the value of length matches the number of apps. Also, if you develop a new app, add it as `ʻapp2.title = hogehoge``. Now that registration is complete, restart Sota. After restarting, you can run the developed app by pressing the button on the back and selecting "Setting mode" → "Run app".

Referenced articles

-GitHub and Eclipse cooperation and summary --Qiita -How to register your own jar in Sota-Qiita

Recommended Posts

How to develop and register a Sota app in Java
How to convert A to a and a to A using AND and OR in Java
How to display a web page in Java
How to test a private method in Java and partially mock that method
How to make an app with a plugin mechanism [C # and Java]
How to create a Java environment in just 3 seconds
How to create a data URI (base64) in Java
How to convert a file to a byte array in Java
How to ZIP a JAVA CSV file and manage it in a Byte array
How to make a Java container
[Forge] How to register your own Entity and Entity Render in 1.13.2
How to learn JAVA in 7 days
How to store a string from ArrayList to String in Java (Personal)
[Java] How to create a folder
What happened in "Java 8 to Java 11" and how to build an environment
How to call and use API in Java (Spring Boot)
How to deploy a kotlin (java) app on AWS fargate
How to use classes in Java?
How to name variables in Java
How to simulate uploading a post-object form to OSS in Java
Differences in how to handle strings between Java and Perl
How to make a Java array
How to concatenate strings in java
How to develop in a container with --privileged and / sbin / init passed in VSCode Remote Containers
How to implement a job that uses Java API in JobScheduler
How to create a new Gradle + Java + Jar project in Intellij 2016.03
How to automatically operate a screen created in Java on Windows
How to encrypt and decrypt with RSA public key in Java
How to make a Java calendar Summary
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to insert a video in Rails
How to do base conversion in Java
[Introduction to Java] How to write a Java program
[Java] How to output and write files!
Create a TODO app in Java 7 Create Header
How to implement coding conventions in Java
How to embed Janus Graph in Java
Try making a calculator app in Java
How to print a Java Word document
How to get the date in java
How to publish a library in jCenter
Java to C and C to Java in Android Studio
[Personal memo] How to interact with a random number generator in Java
The story of forgetting to close a file in Java and failing
How to develop from VScode in a remote destination environment or a remote destination container environment
How to record JFR (Java Flight Recorder) and output a dump file
How to pass a proxy when throwing REST over SSL in Java
How to get the absolute path of a directory running in Java
[Java] [For beginners] How to insert elements directly in a 2D array
How to create your own annotation in Java and get the value
[Java] How to use FileReader class and BufferedReader class
Two ways to start a thread in Java + @
[Java] How to get and output standard input
Code to escape a JSON string in Java
Try to create a bulletin board in Java
How to add sound in the app (swift)
How to get Class from Element in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java