-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
51 lines (41 loc) · 1.64 KB
/
jarvis.py
File metadata and controls
51 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import xmlrpclib
import soar_interface
import soar_interface.soar_state_server
from soar_interface.soar_agent import update
import json
import argparse
from log_config import logging
### read in the config file
CONFIG_FILE = "config.json"
with open(CONFIG_FILE) as config_file:
try:
config = json.load(config_file)
except ValueError, e:
logging.fatal("[soar_client] :: Invalid json at %s; error = %s" % (CONFIG_FILE, e))
sys.exit()
def create_connection_with_tracker():
'''
Connect to the ARA serve that generates a stream of perceptual events.
The hostname and port can be specified in ./config.json
:return: xmlrpclib.ServerProxy
'''
url = 'http://{}:{}'.format(config['Servers']['input_host'], config['Servers']['input_port'])
server = xmlrpclib.ServerProxy(url)
logging.info("[soar_client] :: Created a connection to the tracker server at: {}".format(url))
return server
def create_and_run_myserver(soar_agent):
soar_server = soar_interface.soar_state_server.soar_state_server(soar_agent, port=config['Servers']['output_port'])
soar_server.run_in_background()
def create_and_start_coach(tracker_server):
coach = soar_interface.soar_agent.soar_agent(config, 'soar-coach', tracker_server)
logging.info("[soar_client] :: Created ARA Soar coach")
coach.register_output_callback(update, coach)
logging.info("[soar_client] :: Started coaching agent")
coach.start()
coach.stop()
return coach
if __name__ == '__main__':
tracker_server = create_connection_with_tracker()
coach = create_and_start_coach(tracker_server)
create_and_run_myserver(coach)