Skip to content

Step by step instructions for creating a skill

Miguel Vieira edited this page Sep 19, 2021 · 8 revisions

This guide shows how to easily create a new skill with Skill-Up. For this machine-skills can be implemented as simple Java classes and only need to be supplemented by a few annotations. Before a new skill is created a module is necessary, because the skill is attached to a module (machine) and is registered to this module. You can find the instructions for this at Step by step instruction for creating a module

Create new maven project

Open Eclipse and go to File -> New -> Other. The following window opens, in which you select maven project:

In the new window check the box for simple project. Choose a workspace location (default or other) and if desired a working set.

Now a groupId and artifactId are required. The groupId uniquely identifies your project across all projects. A groupId should follow Java's package name rules. The artifactId is the name of the jar without version. Name and description are optional. Your maven project is created!

Necessary extensions of the POM file

In the package explorer the last entry in the new maven project should be the pom file. At first the file should look like this:

To create a skill, the following dependency is necessary. This dependency allows to use annotations, which are necessary to recognize the skill as such and thus make it usable. Also, the packaging must be added. Defined as a bundle, this bundle can be added to the others in the OSGi framework. More on this later.

In order to create a maven project and a bundle, the following plugins are required.

Create a skill

In Package Explorer under the new maven project, right-click on src/main/java -> New -> Package. Add a name for the package.

Right-click on the new package -> New -> Class. Add a name for the class that represents the skill.

Now the actual skill can be created. The created class Skill must be provided with an annotation @Skill, so that the skill is also recognized as such by Skill-Up and is provided for execution. If the annotation is not found yet refresh (F5) or maven -> update project (Alt+F5). SkillIri, moduleIri and type are necessary. ModuleIri must match the IRI of the module the skill is attached to (if not already created see Step by step instruction for creating a module). The type stands for the technology over which the skill can be applied and has to be a class which extends the class SkillType. Currently there are extending classes OpcUaSkillType and RestSkillType. These two technologies are supported so far. CapabilityIri and description are optional.

@Skill(skillIri = "https://my-example-skill.com/#AddSkill", capabilityIri = "https://my-example-capability.com/#CapAA", moduleIri = "https://my-example-module.com/#ExampleModule", type = OpcUaSkillType.class, description = "This is an example skill.")
public class AddSkill {

Skills have methods that execute their actual ability. For this they need parameters and outputs. The parameters influence the result of such a method, while the outputs are the result of the method. Parameters and outputs are fields and must be marked with corresponding annotations.

@SkillParameter(isRequired = true, option = { "4", "3", "2" })
private int a;

@SkillParameter(isRequired = true)
private int b;

@SkillOutput(isRequired = true)
private int result;

Finally, the actual methods are defined. A method can be assigned to a state, so that triggering the corresponding transition causes the method of the state to be executed. The possible states and transitions can be found here: ISA88-StateMachine. For example, in the Execute state, the two numbers a and b are added.

@Starting
public void starting() {
	System.out.println("Starting with a = " + a + " and b = " + b);
}

@Execute
public void execute() {
	result = a + b;
}

@Completing
public void completing() {
	System.out.println("Completing, result = " + result);
}

Build skill

Now the skill is as good as finished. Click on Run -> Run Configurations -> Right Click on Maven Build -> New Configuration and fill it in as shown in the picture. It is important that the project of the new skill is selected in the base directory. Then click on apply and run. With this the skill is ready.

Use of skill

In package explorer, a jar file should have been created in your skill project under the target folder. This file can now be placed in the apache felix folder in the include folder.

To use the skill, further preparations must be made...

As soon as the startFelix.bat is started, this skill is also registered and provided or if felix is already running, the skill is also provided. As already mentioned, the appropriate module must be available for this, which is also located in this folder.