Revision d7c8e3b7
client/java/pom.xml | ||
---|---|---|
1 | 1 |
|
2 | 2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
3 |
<modelVersion>4.0.0</modelVersion>
|
|
4 |
<groupId>de.citec.csra</groupId>
|
|
5 |
<artifactId>hlrc-client</artifactId>
|
|
6 |
<version>0.2</version>
|
|
7 |
<packaging>jar</packaging>
|
|
8 |
<name>High Level Robot Control java client</name>
|
|
9 |
<url>http://maven.apache.org</url>
|
|
10 |
<build>
|
|
11 |
<plugins>
|
|
12 |
<plugin>
|
|
13 |
<groupId>org.apache.maven.plugins</groupId>
|
|
14 |
<artifactId>maven-compiler-plugin</artifactId>
|
|
15 |
<version>3.1</version>
|
|
16 |
<configuration>
|
|
17 |
<source>1.7</source>
|
|
18 |
<target>1.7</target>
|
|
19 |
<showDeprecation>true</showDeprecation>
|
|
20 |
</configuration>
|
|
21 |
</plugin>
|
|
22 |
<plugin>
|
|
23 |
<groupId>org.codehaus.mojo</groupId>
|
|
24 |
<artifactId>appassembler-maven-plugin</artifactId>
|
|
25 |
<version>1.8</version>
|
|
26 |
<configuration>
|
|
27 |
<programs>
|
|
28 |
<program>
|
|
29 |
<mainClass>de.uni-bielefeld.cit-ec.opensource.hlrc.main.Cmd</mainClass>
|
|
30 |
<id>hlrc-client</id>
|
|
3 |
<modelVersion>4.0.0</modelVersion>
|
|
4 |
<groupId>de.cit_ec.opensource.hlrc</groupId>
|
|
5 |
<artifactId>hlrc-client</artifactId>
|
|
6 |
<version>0.2</version>
|
|
7 |
<packaging>jar</packaging>
|
|
8 |
<name>High Level Robot Control java client</name>
|
|
9 |
<url>http://maven.apache.org</url>
|
|
10 |
<build>
|
|
11 |
<plugins>
|
|
12 |
<plugin>
|
|
13 |
<groupId>org.apache.maven.plugins</groupId>
|
|
14 |
<artifactId>maven-compiler-plugin</artifactId>
|
|
15 |
<version>3.1</version>
|
|
16 |
<configuration>
|
|
17 |
<source>1.7</source>
|
|
18 |
<target>1.7</target>
|
|
19 |
<showDeprecation>true</showDeprecation>
|
|
20 |
</configuration>
|
|
21 |
</plugin>
|
|
22 |
<plugin>
|
|
23 |
<groupId>org.codehaus.mojo</groupId>
|
|
24 |
<artifactId>appassembler-maven-plugin</artifactId>
|
|
25 |
<version>1.8</version>
|
|
26 |
<configuration>
|
|
27 |
<programs>
|
|
28 |
<program>
|
|
29 |
<mainClass>de.cit_ec.opensource.hlrc.main.Cmd</mainClass>
|
|
30 |
<id>hlrc-client</id>
|
|
31 | 31 |
|
32 |
</program> |
|
33 |
</programs> |
|
34 |
<!-- <assembleDirectory>${project.build.directory}/dist</assembleDirectory> |
|
35 |
<repositoryName>lib</repositoryName> |
|
36 |
<repositoryLayout>flat</repositoryLayout>--> |
|
37 |
</configuration> |
|
38 |
<executions> |
|
39 |
<execution> |
|
40 |
<id>assemble</id> |
|
41 |
<goals> |
|
42 |
<goal>assemble</goal> |
|
43 |
</goals> |
|
44 |
</execution> |
|
45 |
</executions> |
|
46 |
</plugin> |
|
47 |
</plugins> |
|
48 |
</build> |
|
49 |
<licenses> |
|
50 |
<license> |
|
51 |
<name>GPLv3</name> |
|
52 |
<url>http://www.gnu.org/licenses/gpl.html</url> |
|
53 |
</license> |
|
54 |
</licenses> |
|
55 |
<organization> |
|
56 |
<name>Citec, Bielefeld University</name> |
|
57 |
<url>http://www.cit-ec.de/</url> |
|
58 |
</organization> |
|
59 |
<developers> |
|
60 |
<developer> |
|
61 |
<id>flier</id> |
|
62 |
<name>Florian Lier</name> |
|
63 |
<email>flier@techfak.uni-bielefeld.de</email> |
|
64 |
<url>https://www.cit-ec.de/de/users/flier</url> |
|
65 |
<roles> |
|
66 |
<role>architect</role> |
|
67 |
<role>developer</role> |
|
68 |
</roles> |
|
69 |
<timezone>+1</timezone> |
|
70 |
</developer> |
|
71 |
</developers> |
|
72 |
<properties> |
|
73 |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
74 |
</properties> |
|
75 |
<dependencies> |
|
76 |
<dependency> |
|
77 |
<groupId>org.slf4j</groupId> |
|
78 |
<artifactId>slf4j-api</artifactId> |
|
79 |
<version>1.7.7</version> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.slf4j</groupId> |
|
83 |
<artifactId>slf4j-simple</artifactId> |
|
84 |
<version>1.7.7</version> |
|
85 |
</dependency> |
|
86 |
<dependency> |
|
87 |
<groupId>junit</groupId> |
|
88 |
<artifactId>junit</artifactId> |
|
89 |
<version>4.11</version> |
|
90 |
<scope>test</scope> |
|
91 |
</dependency> |
|
92 |
<dependency> |
|
93 |
<groupId>rsb</groupId> |
|
94 |
<artifactId>rsb</artifactId> |
|
95 |
<version>[0.15.0,)</version> |
|
96 |
</dependency> |
|
97 |
<dependency> |
|
98 |
<groupId>rsb</groupId> |
|
99 |
<artifactId>rst</artifactId> |
|
100 |
<version>[0.15.0,)</version> |
|
101 |
</dependency> |
|
102 |
<dependency> |
|
103 |
<groupId>commons-cli</groupId> |
|
104 |
<artifactId>commons-cli</artifactId> |
|
105 |
<version>1.2</version> |
|
106 |
</dependency> |
|
107 |
<dependency> |
|
108 |
<groupId>commons-lang</groupId> |
|
109 |
<artifactId>commons-lang</artifactId> |
|
110 |
<version>2.6</version> |
|
111 |
</dependency> |
|
112 |
</dependencies> |
|
113 |
<distributionManagement> |
|
114 |
<repository> |
|
115 |
<id>citec</id> |
|
116 |
<name>CITEC Maven Repository Server</name> |
|
117 |
<url>https://repo.cit-ec.uni-bielefeld.de/content/repositories/releases/</url> |
|
118 |
<layout>default</layout> |
|
119 |
</repository> |
|
120 |
</distributionManagement> |
|
32 |
</program> |
|
33 |
</programs> |
|
34 |
<!-- <assembleDirectory>${project.build.directory}/dist</assembleDirectory> |
|
35 |
<repositoryName>lib</repositoryName> |
|
36 |
<repositoryLayout>flat</repositoryLayout>--> |
|
37 |
</configuration> |
|
38 |
<executions> |
|
39 |
<execution> |
|
40 |
<id>assemble</id> |
|
41 |
<goals> |
|
42 |
<goal>assemble</goal> |
|
43 |
</goals> |
|
44 |
</execution> |
|
45 |
</executions> |
|
46 |
</plugin> |
|
47 |
</plugins> |
|
48 |
</build> |
|
49 |
<licenses> |
|
50 |
<license> |
|
51 |
<name>GPLv3</name> |
|
52 |
<url>http://www.gnu.org/licenses/gpl.html</url> |
|
53 |
</license> |
|
54 |
</licenses> |
|
55 |
<organization> |
|
56 |
<name>Citec, Bielefeld University</name> |
|
57 |
<url>http://www.cit-ec.de/</url> |
|
58 |
</organization> |
|
59 |
<developers> |
|
60 |
<developer> |
|
61 |
<id>flier</id> |
|
62 |
<name>Florian Lier</name> |
|
63 |
<email>flier@techfak.uni-bielefeld.de</email> |
|
64 |
<url>https://www.cit-ec.de/de/users/flier</url> |
|
65 |
<roles> |
|
66 |
<role>architect</role> |
|
67 |
<role>developer</role> |
|
68 |
</roles> |
|
69 |
<timezone>+1</timezone> |
|
70 |
</developer> |
|
71 |
</developers> |
|
72 |
<properties> |
|
73 |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
74 |
</properties> |
|
75 |
<dependencies> |
|
76 |
<dependency> |
|
77 |
<groupId>org.slf4j</groupId> |
|
78 |
<artifactId>slf4j-api</artifactId> |
|
79 |
<version>1.7.7</version> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.slf4j</groupId> |
|
83 |
<artifactId>slf4j-simple</artifactId> |
|
84 |
<version>1.7.7</version> |
|
85 |
</dependency> |
|
86 |
<dependency> |
|
87 |
<groupId>junit</groupId> |
|
88 |
<artifactId>junit</artifactId> |
|
89 |
<version>4.11</version> |
|
90 |
<scope>test</scope> |
|
91 |
</dependency> |
|
92 |
<dependency> |
|
93 |
<groupId>rsb</groupId> |
|
94 |
<artifactId>rsb</artifactId> |
|
95 |
<version>[0.15.0,)</version> |
|
96 |
</dependency> |
|
97 |
<dependency> |
|
98 |
<groupId>rsb</groupId> |
|
99 |
<artifactId>rst</artifactId> |
|
100 |
<version>[0.15.0,)</version> |
|
101 |
</dependency> |
|
102 |
<dependency> |
|
103 |
<groupId>commons-cli</groupId> |
|
104 |
<artifactId>commons-cli</artifactId> |
|
105 |
<version>1.2</version> |
|
106 |
</dependency> |
|
107 |
<dependency> |
|
108 |
<groupId>commons-lang</groupId> |
|
109 |
<artifactId>commons-lang</artifactId> |
|
110 |
<version>2.6</version> |
|
111 |
</dependency> |
|
112 |
</dependencies> |
|
113 |
<repositories> |
|
114 |
<repository> |
|
115 |
<id>citec-releases</id> |
|
116 |
<name>CITEC Maven Repository Server</name> |
|
117 |
<url>https://mvn.cit-ec.de/nexus/content/repositories/releases/</url> |
|
118 |
<layout>default</layout> |
|
119 |
<releases> |
|
120 |
<enabled>true</enabled> |
|
121 |
</releases> |
|
122 |
</repository> |
|
123 |
</repositories> |
|
121 | 124 |
</project> |
client/java/src/main/java/de/cit_ec/opensource/hlrc/client/Emotions.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
* @author flier@techfak.uni-bielefeld.de |
|
4 |
* |
|
5 |
*/ |
|
6 |
|
|
7 |
package de.cit_ec.opensource.hlrc.client; |
|
8 |
|
|
9 |
public enum Emotions { |
|
10 |
NEUTRAL, |
|
11 |
HAPPY, |
|
12 |
SAD, |
|
13 |
ANGRY, |
|
14 |
SURPRISED, |
|
15 |
FEAR |
|
16 |
} |
client/java/src/main/java/de/cit_ec/opensource/hlrc/client/HeadAnimations.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
* @author flier@techfak.uni-bielefeld.de |
|
4 |
* |
|
5 |
*/ |
|
6 |
|
|
7 |
// TODO: Rename/refactor this package to somthing more self explantory |
|
8 |
|
|
9 |
package de.cit_ec.opensource.hlrc.client; |
|
10 |
|
|
11 |
public enum HeadAnimations { |
|
12 |
IDLE, |
|
13 |
HEAD_NOD, |
|
14 |
HEAD_SHAKE, |
|
15 |
EYEBLINK_L, |
|
16 |
EYEBLINK_R, |
|
17 |
EYEBLINK_BOTH, |
|
18 |
EYEBROWS_RAISE, |
|
19 |
EYEBROWS_LOWER |
|
20 |
} |
client/java/src/main/java/de/cit_ec/opensource/hlrc/client/MiddlewareRSB.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
* @author flier@techfak.uni-bielefeld.de |
|
4 |
* |
|
5 |
*/ |
|
6 |
package de.cit_ec.opensource.hlrc.client; |
|
7 |
|
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.Map; |
|
11 |
import java.util.concurrent.ExecutionException; |
|
12 |
import java.util.concurrent.TimeoutException; |
|
13 |
import java.util.logging.Level; |
|
14 |
import java.util.logging.Logger; |
|
15 |
|
|
16 |
import javax.sound.sampled.AudioFormat; |
|
17 |
import javax.sound.sampled.AudioFormat.Encoding; |
|
18 |
|
|
19 |
import rsb.RSBException; |
|
20 |
import rsb.converter.DefaultConverterRepository; |
|
21 |
import rsb.converter.ProtocolBufferConverter; |
|
22 |
import rsb.patterns.RemoteServer; |
|
23 |
|
|
24 |
import rst.audition.SoundChunkType.SoundChunk; |
|
25 |
import rst.audition.UtteranceType.Utterance; |
|
26 |
import rst.animation.HeadAnimationType.HeadAnimation; |
|
27 |
import rst.animation.EmotionExpressionType.EmotionExpression; |
|
28 |
import rst.animation.BinocularHeadGazeType.BinocularHeadGaze; |
|
29 |
|
|
30 |
import com.google.protobuf.ByteString; |
|
31 |
|
|
32 |
// Create _abstract_ middleware class and function _interface_ for |
|
33 |
// future integration of additional Middleware implementations... |
|
34 |
import rsb.Factory; |
|
35 |
import rsb.Informer; |
|
36 |
import rst.animation.EmotionExpressionType.EmotionExpression.Emotion; |
|
37 |
import rst.animation.HeadAnimationType.HeadAnimation.Animation; |
|
38 |
import rst.audition.PhonemeCollectionType.PhonemeCollection; |
|
39 |
import rst.audition.PhonemeType.Phoneme; |
|
40 |
import rst.geometry.SphericalDirectionFloatType.SphericalDirectionFloat; |
|
41 |
|
|
42 |
public class MiddlewareRSB { |
|
43 |
|
|
44 |
final RemoteServer server; |
|
45 |
final String robotname; |
|
46 |
static Map<Emotions, Emotion> emo_map; |
|
47 |
static Map<HeadAnimations, Animation> han_map; |
|
48 |
|
|
49 |
public class RSBInformer { |
|
50 |
|
|
51 |
final Factory factory; |
|
52 |
final Informer<Object> informer; |
|
53 |
|
|
54 |
public RSBInformer(String scope) throws Throwable { |
|
55 |
|
|
56 |
// Get a factory instance to create RSB objects. |
|
57 |
factory = Factory.getInstance(); |
|
58 |
|
|
59 |
// Create an informer on scope "/exmaple/informer". |
|
60 |
informer = factory.createInformer(scope); |
|
61 |
|
|
62 |
// Activate the informer to be ready for work |
|
63 |
informer.activate(); |
|
64 |
|
|
65 |
} |
|
66 |
|
|
67 |
public void pushMsg() { |
|
68 |
try { |
|
69 |
// Send and event using a method that accepts the data and |
|
70 |
// automatically creates an appropriate event internally. |
|
71 |
this.informer.publish("TODO"); |
|
72 |
} catch (RSBException ex) { |
|
73 |
Logger.getLogger(MiddlewareRSB.class.getName()).log(Level.SEVERE, null, ex); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
public void closeInf() throws InterruptedException { |
|
78 |
try { |
|
79 |
// As there is no explicit removal model in java, always manually |
|
80 |
// deactivate the informer if it is not needed anymore |
|
81 |
this.informer.deactivate(); |
|
82 |
} catch (RSBException ex) { |
|
83 |
Logger.getLogger(MiddlewareRSB.class.getName()).log(Level.SEVERE, null, ex); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
@SuppressWarnings("unchecked") |
|
90 |
public MiddlewareRSB(String robotname) { |
|
91 |
|
|
92 |
this.robotname = robotname; |
|
93 |
|
|
94 |
server = Factory.getInstance().createRemoteServer(this.robotname + "/set/"); |
|
95 |
System.out.println("--> Robot: Talking to " + this.robotname); |
|
96 |
try { |
|
97 |
server.activate(); |
|
98 |
} catch (RSBException ex) { |
|
99 |
Logger.getLogger(MiddlewareRSB.class.getName()).log(Level.SEVERE, null, ex); |
|
100 |
} |
|
101 |
|
|
102 |
{ |
|
103 |
final ProtocolBufferConverter<EmotionExpression> converter = new ProtocolBufferConverter<>(EmotionExpression.getDefaultInstance()); |
|
104 |
DefaultConverterRepository.getDefaultConverterRepository().addConverter(converter); |
|
105 |
} |
|
106 |
{ |
|
107 |
final ProtocolBufferConverter<BinocularHeadGaze> converter = new ProtocolBufferConverter<>(BinocularHeadGaze.getDefaultInstance()); |
|
108 |
DefaultConverterRepository.getDefaultConverterRepository().addConverter(converter); |
|
109 |
} |
|
110 |
{ |
|
111 |
final ProtocolBufferConverter<HeadAnimation> converter = new ProtocolBufferConverter<>(HeadAnimation.getDefaultInstance()); |
|
112 |
DefaultConverterRepository.getDefaultConverterRepository().addConverter(converter); |
|
113 |
} |
|
114 |
{ |
|
115 |
final ProtocolBufferConverter<Utterance> converter = new ProtocolBufferConverter<>(Utterance.getDefaultInstance()); |
|
116 |
DefaultConverterRepository.getDefaultConverterRepository().addConverter(converter); |
|
117 |
} |
|
118 |
{ |
|
119 |
final ProtocolBufferConverter<SoundChunk> converter = new ProtocolBufferConverter<>(SoundChunk.getDefaultInstance()); |
|
120 |
DefaultConverterRepository.getDefaultConverterRepository().addConverter(converter); |
|
121 |
} |
|
122 |
{ |
|
123 |
final ProtocolBufferConverter<Phoneme> converter = new ProtocolBufferConverter<>(Phoneme.getDefaultInstance()); |
|
124 |
DefaultConverterRepository.getDefaultConverterRepository().addConverter(converter); |
|
125 |
} |
|
126 |
|
|
127 |
emo_map = new HashMap(); |
|
128 |
emo_map.put(Emotions.SAD, Emotion.SAD); |
|
129 |
emo_map.put(Emotions.ANGRY, Emotion.ANGRY); |
|
130 |
emo_map.put(Emotions.FEAR, Emotion.FEAR); |
|
131 |
emo_map.put(Emotions.NEUTRAL, Emotion.NEUTRAL); |
|
132 |
emo_map.put(Emotions.SURPRISED, Emotion.SURPRISED); |
|
133 |
emo_map.put(Emotions.HAPPY, Emotion.HAPPY); |
|
134 |
|
|
135 |
han_map = new HashMap(); |
|
136 |
han_map.put(HeadAnimations.HEAD_NOD, Animation.HEAD_NOD); |
|
137 |
han_map.put(HeadAnimations.HEAD_SHAKE, Animation.HEAD_SHAKE); |
|
138 |
han_map.put(HeadAnimations.IDLE, Animation.IDLE); |
|
139 |
han_map.put(HeadAnimations.EYEBLINK_R, Animation.EYEBLINK_RIGHT); |
|
140 |
han_map.put(HeadAnimations.EYEBLINK_L, Animation.EYEBLINK_LEFT); |
|
141 |
han_map.put(HeadAnimations.EYEBLINK_BOTH, Animation.EYEBLINK_BOTH); |
|
142 |
han_map.put(HeadAnimations.EYEBROWS_LOWER, Animation.EYEBROWS_LOWER); |
|
143 |
han_map.put(HeadAnimations.EYEBROWS_RAISE, Animation.EYEBROWS_RAISE); |
|
144 |
} |
|
145 |
|
|
146 |
private SoundChunk compileSoundChunk(AudioFormat audio, byte[] data) { |
|
147 |
SoundChunk.Builder sc = SoundChunk.newBuilder(); |
|
148 |
ByteString bs = ByteString.copyFrom(data); |
|
149 |
boolean isbig = audio.isBigEndian(); |
|
150 |
sc.setChannels(audio.getChannels()); |
|
151 |
sc.setData(bs); |
|
152 |
sc.setRate((int) audio.getSampleRate()); |
|
153 |
|
|
154 |
if (isbig) { |
|
155 |
sc.setEndianness(SoundChunk.EndianNess.ENDIAN_BIG); |
|
156 |
} else { |
|
157 |
sc.setEndianness(SoundChunk.EndianNess.ENDIAN_LITTLE); |
|
158 |
} |
|
159 |
|
|
160 |
sc.setSampleCount(data.length / audio.getFrameSize()); |
|
161 |
Encoding enc = audio.getEncoding(); |
|
162 |
|
|
163 |
if (enc.equals(Encoding.PCM_SIGNED)) { |
|
164 |
int size = audio.getSampleSizeInBits(); |
|
165 |
if (size == 8) { |
|
166 |
sc.setSampleType(SoundChunk.SampleType.SAMPLE_S8); |
|
167 |
} else if (size == 16) { |
|
168 |
sc.setSampleType(SoundChunk.SampleType.SAMPLE_S16); |
|
169 |
} else if (size == 24) { |
|
170 |
sc.setSampleType(SoundChunk.SampleType.SAMPLE_S24); |
|
171 |
} else { |
|
172 |
System.err.println("Audio Sample Size Not Valid"); |
|
173 |
} |
|
174 |
} else if (enc.equals(Encoding.PCM_UNSIGNED)) { |
|