Skip to content
This repository was archived by the owner on May 21, 2018. It is now read-only.

Commit

Permalink
Merge pull request #303 from hansonrobotics/performance_events
Browse files Browse the repository at this point in the history
Speech as performance event, added parameters for matching speech
  • Loading branch information
vytasrgl authored Oct 25, 2016
2 parents e4c240d + f9434be commit 97991eb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/performances/scripts/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self):
# Shared subscribers for nodes
rospy.Subscriber('/' + self.robot_name + '/speech_events', String,
lambda msg: self.notify('speech_events', msg))
rospy.Subscriber('/' + self.robot_name + '/speech', ChatMessage, self.speech_callback)
# Shared subscribers for nodes
rospy.Subscriber('/hand_events', String, self.hand_callback)

Expand Down Expand Up @@ -341,5 +342,9 @@ def hand_callback(self, msg):
self.notify(msg.data, msg)


def speech_callback(self, msg):
self.notify('SPEECH', msg.utterance)


if __name__ == '__main__':
Runner()
50 changes: 33 additions & 17 deletions src/performances/src/performances/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ def __init__(self, data, runner):
self.timer = False
if 'on_event' not in self.data.keys():
self.data['on_event'] = False
if 'event_param' not in self.data.keys():
self.data['event_param'] = False

def start_performance(self, msg=None):
def start_performance(self):
if self.subscriber:
self.runner.unregister(self.data['topic'].strip(), self.subscriber)
self.subscriber = None
Expand All @@ -286,29 +288,43 @@ def start_performance(self, msg=None):
if not response.success:
self.runner.resume()

def start(self, run_time):
self.runner.pause()
def event_callback(self, msg=None):
if self.data['event_param']:
# Check if any comma separated
params = str(self.data['event_param']).lower().split(',')
matched = False
for p in params:
try:
str(msg or '').lower().index(p.strip())
matched = True
continue
except ValueError:
matched = matched or False
if not matched:
return False
if self.data['on_event']:
self.start_performance()
else:
self.resume()

def resume(msg=None):
if self.subscriber:
self.runner.unregister(self.data['topic'].strip(), self.subscriber)
self.subscriber = None
if not self.finished:
self.runner.resume()
if self.timer:
self.timer.cancel()
def resume(self):
if self.subscriber:
self.runner.unregister(self.data['topic'].strip(), self.subscriber)
self.subscriber = None
if not self.finished:
self.runner.resume()
if self.timer:
self.timer.cancel()

def start(self, run_time):
self.runner.pause()
if 'topic' in self.data:
topic = self.data['topic'].strip()
if self.data['on_event']:
self.subscriber = self.runner.register(topic, self.start_performance)
else:
self.subscriber = self.runner.register(topic, resume)

self.subscriber = self.runner.register(topic, self.event_callback)
try:
timeout = float(self.data['timeout'])
if timeout > 0.1:
self.timer = Timer(timeout, resume)
self.timer = Timer(timeout, self.resume)
self.timer.start()
except (ValueError, KeyError) as e:
logger.error(e)
Expand Down
4 changes: 2 additions & 2 deletions src/webui/client/modules/performances/entities/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ define(['application', 'backbone', 'lib/api', 'jquery', 'supermodel'],
defaultValues: {speed: 1, interval: 1}
},
pause: {
label: 'Pause',
properties: ['topic', 'timeout', 'on_event'],
label: 'Break',
properties: ['topic', 'timeout', 'on_event', 'event_param'],
defaultValues: {duration: 0.2}
},
settings: {
Expand Down
6 changes: 6 additions & 0 deletions src/webui/client/modules/performances/views/node_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities
langSelect: 'select.app-lang-select',
attentionRegionList: '.app-attention-region-list',
topicInput: '.app-node-topic',
eventParamInput: '.app-node-event-param',
btreeModeSelect: 'select.app-btree-mode-select',
speechEventSelect: 'select.app-speech-event-select',
hrAngleSlider: '.app-hr-angle-slider',
Expand All @@ -33,6 +34,7 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities
'change @ui.textInput': 'setTextDuration',
'change @ui.langSelect': 'setLanguage',
'change @ui.topicInput': 'setTopic',
'change @ui.eventParamInput': 'setEventParam',
'change @ui.listenResponseInputs': 'updateChatResponses',
'click @ui.listenAddResponseButton': 'addListenResponse',
'click @ui.removeListenResponseButton': 'removeListenResponse',
Expand All @@ -46,6 +48,7 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities
},
modelChanged: function () {
this.ui.topicInput.val(this.model.get('topic'));
this.ui.eventParamInput.val(this.model.get('event_param'));
},
onAttach: function () {
this.initFields();
Expand Down Expand Up @@ -304,6 +307,9 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities
setTopic: function () {
this.model.set('topic', this.ui.topicInput.val());
},
setEventParam: function () {
this.model.set('event_param', this.ui.eventParamInput.val());
},
enableAttentionRegionSelect: function () {
var self = this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
<div class="app-attention-region-list"></div>

<div class="form-group" data-node-property="topic">
<label>Wait for topic</label>
<label>Wait for Event</label>
<input type="text" class="app-node-topic form-control" title="Topic name"/>
</div>

<div class="form-group" data-node-property="event_param">
<label>Event Match Parameter</label>
<input type="text" class="app-node-event-param form-control" title="Event Parameter"/>
</div>

<div class="form-group" data-node-property="btree_mode">
<label title="Mode">Mode</label>
<select class="app-btree-mode-select">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define(['backbone', 'lib/api', './node_config'], function (Backbone, api, NodeCo

Promise.all([desc_schema, node_schema]).then(function (data) {
var properties = {};
for (let prop of data) {
for (var prop in data) {
properties = _.extend(properties, prop);
}
options.success && options.success({
Expand Down

0 comments on commit 97991eb

Please sign in to comment.