Skip to content

Commit 1f2a998

Browse files
authored
Merge pull request #24 from ropod-project/develop
New release version 0.2.0
2 parents 035a38f + 469caa0 commit 1f2a998

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1059
-2411
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ before_install:
1111

1212
script:
1313
- docker-compose up -d robot
14-
- docker-compose up -d task_allocator
14+
- docker-compose up -d ccu
1515
- docker-compose up --exit-code-from task_allocation_test
1616
after_script:
1717
- docker stop $(docker ps -aq)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ python3 robot.py ropod_001
8383
Run in another terminal
8484

8585
```
86-
python3 task_allocator.py
86+
python3 ccu.py
8787
```
8888

8989
Go to `/tests` and run test in another terminal

config/config.yaml

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
version: 2
22
ccu_store:
3-
db_name: ropod_ccu_store
3+
db_name: ccu_store
44
port: 27017
55
robot_store:
6-
db_name: ropod_store
6+
db_name: robot_store
77
port: 27017
8-
resources:
9-
fleet:
10-
- ropod_001
11-
- ropod_002
12-
- ropod_003
8+
resource_manager:
9+
resources:
10+
fleet:
11+
- ropod_001
12+
- ropod_002
13+
- ropod_003
14+
plugins:
15+
- auctioneer
1316

1417
plugins:
15-
task_allocation:
16-
# Assuming we can have different types of tasks,
17-
# specify from where to import the Task and TaskStatus classes
18-
task_type:
19-
class: 'mrs.structs.task'
20-
allocation_method: tessi
21-
robot_proxies: true
18+
mrta:
19+
allocation_method: mrta-srea
2220
stp_solver: srea
23-
auctioneer:
24-
round_time: 15 # seconds
25-
alternative_timeslots: True
26-
dispatcher:
27-
freeze_window: 300 # seconds
21+
robot_proxies: true
22+
freeze_window: 3 # minutes
23+
auctioneer:
24+
round_time: 15 # seconds
25+
alternative_timeslots: True
26+
dispatcher:
27+
re-allocate: True
2828

2929
robot_proxy:
3030
bidder:
@@ -48,8 +48,6 @@ robot_proxy:
4848
message_types: # Types of messages the node will listen to. Messages not listed will be ignored
4949
- TASK-ANNOUNCEMENT
5050
- ALLOCATION
51-
- TIMETABLE
52-
- DELETE-TASK
5351
debug_msgs: false
5452
acknowledge: false
5553
publish:
@@ -70,10 +68,6 @@ robot_proxy:
7068
component: 'bidder.task_announcement_cb'
7169
- msg_type: 'ALLOCATION'
7270
component: 'bidder.allocation_cb'
73-
- msg_type: 'TIMETABLE'
74-
component: '.timetable_cb'
75-
- msg_type: 'DELETE-TASK'
76-
component: '.delete_task_cb'
7771

7872
api:
7973
version: 0.1.0
@@ -92,7 +86,7 @@ api:
9286
- TASK-PROGRESS
9387
- BID
9488
- FINISH-ROUND
95-
- ALLOCATE-TASK
89+
- START-TEST
9690
acknowledge: false
9791
debug_messages:
9892
- 'TASK-REQUEST'
@@ -106,31 +100,12 @@ api:
106100
groups: ['TASK-ALLOCATION']
107101
method: shout
108102
callbacks:
109-
- msg_type: 'ALLOCATE-TASK'
110-
component: 'auctioneer.allocate_task_cb'
103+
- msg_type: 'START-TEST'
104+
component: '.start_test_cb'
111105
- msg_type: 'BID'
112106
component: 'auctioneer.bid_cb'
113107
- msg_type: 'FINISH-ROUND'
114108
component: 'auctioneer.finish_round_cb'
115-
rest:
116-
server:
117-
ip: 127.0.0.1
118-
port: 8081
119-
routes:
120-
- path: '/number'
121-
resource:
122-
module: 'fleet_management.api.rest.resources'
123-
class: 'RandomGenerator'
124-
ros:
125-
publishers:
126-
- topic: '/fms/task'
127-
msg_type: Task
128-
msg_module: ropod_ros_msgs.msg
129-
subscribers:
130-
- topic: '/fms/task_request'
131-
msg_type: TaskRequest
132-
msg_module: ropod_ros_msgs.msg
133-
callback: task_cb
134109

135110
logger:
136111
version: 1

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ services:
1010
tty: true
1111
stdin_open: true
1212

13-
task_allocator:
14-
container_name: task-allocator
13+
ccu:
14+
container_name: ccu
1515
image: ropod-mrs
1616
working_dir: /mrta/mrs/
17-
command: ["python3", "task_allocator.py"]
17+
command: ["python3", "ccu.py"]
1818
network_mode: "host"
1919
tty: true
2020
stdin_open: true
@@ -30,6 +30,6 @@ services:
3030
stdin_open: true
3131
depends_on:
3232
- robot
33-
- task_allocator
33+
- ccu
3434

3535

mrs/ccu.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import logging
2+
import time
3+
4+
from fmlib.api import API
5+
from fleet_management.config.config import FMSBuilder
6+
from fmlib.db.mongo import Store
7+
from fmlib.db.queries import get_tasks_by_status
8+
from ropod.structs.task import TaskStatus as TaskStatusConst
9+
10+
from mrs.config.builder import MRTABuilder
11+
from mrs.utils.datasets import load_yaml
12+
13+
_component_modules = {'api': API,
14+
'ccu_store': Store,
15+
}
16+
17+
_config_order = ['api', 'ccu_store']
18+
19+
20+
class MRS(object):
21+
def __init__(self, config_file=None):
22+
23+
self.logger = logging.getLogger('mrs')
24+
config_params = load_yaml(config_file)
25+
26+
logger_config = config_params.get('logger')
27+
logging.config.dictConfig(logger_config)
28+
29+
fms_builder = FMSBuilder(component_modules=_component_modules,
30+
config_order=_config_order)
31+
fms_builder.configure(config_params)
32+
33+
self.api = fms_builder.get_component('api')
34+
self.ccu_store = fms_builder.get_component('ccu_store')
35+
36+
mrta_builder = MRTABuilder.configure(self.api, self.ccu_store, config_params)
37+
self.auctioneer = mrta_builder.get_component('auctioneer')
38+
self.dispatcher = mrta_builder.get_component('dispatcher')
39+
40+
self.api.register_callbacks(self)
41+
self.logger.info("Initialized MRS")
42+
43+
def start_test_cb(self, msg):
44+
self.logger.debug("Start test msg received")
45+
tasks = get_tasks_by_status(TaskStatusConst.UNALLOCATED)
46+
self.auctioneer.allocate(tasks)
47+
48+
def run(self):
49+
try:
50+
self.api.start()
51+
52+
while True:
53+
self.auctioneer.run()
54+
self.api.run()
55+
time.sleep(0.5)
56+
except (KeyboardInterrupt, SystemExit):
57+
self.api.shutdown()
58+
self.logger.info('FMS is shutting down')
59+
60+
def shutdown(self):
61+
self.api.shutdown()
62+
63+
64+
if __name__ == '__main__':
65+
config_file_path = '../config/config.yaml'
66+
fms = MRS(config_file_path)
67+
68+
fms.run()

mrs/config/builder.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from fleet_management.exceptions.config import InvalidConfig
2+
from mrs.task_allocation import auctioneer
3+
from mrs.task_execution import dispatcher
4+
import logging
5+
6+
7+
class MRTABuilder:
8+
def __init__(self):
9+
self._auctioneer = None
10+
self._dispatcher = None
11+
12+
def __call__(self, **kwargs):
13+
plugins = dict()
14+
for plugin, config in kwargs.items():
15+
if plugin == 'auctioneer':
16+
self.auctioneer(**kwargs)
17+
plugins.update(auctioneer=self._auctioneer)
18+
if plugin == 'dispatcher':
19+
self.dispatcher(**kwargs)
20+
plugins.update(dispatcher=self._dispatcher)
21+
22+
return plugins
23+
24+
def auctioneer(self, **kwargs):
25+
if not self._auctioneer:
26+
try:
27+
self._auctioneer = auctioneer.configure(**kwargs)
28+
except InvalidConfig:
29+
raise InvalidConfig('MRTA plugin requires an auctioneer configuration')
30+
return self._auctioneer
31+
32+
def dispatcher(self, **kwargs):
33+
if not self._dispatcher:
34+
try:
35+
self._dispatcher = dispatcher.configure(**kwargs)
36+
except InvalidConfig:
37+
raise InvalidConfig('MRTA plugin requires a dispatcher configuration')
38+
return self._dispatcher
39+
40+
def get_component(self, name):
41+
if name == 'auctioneer':
42+
return self._auctioneer
43+
elif name == 'dispatcher':
44+
return self.dispatcher
45+
46+
@classmethod
47+
def configure(cls, api, ccu_store, config_params):
48+
mrta_builder = cls()
49+
logging.info("Configuring MRTA...")
50+
mrta_config = config_params.get('plugins').get('mrta')
51+
if mrta_config is None:
52+
logging.debug("Found no mrta in the configuration file.")
53+
return None
54+
55+
mrta_builder(api=api, ccu_store=ccu_store, **mrta_config)
56+
return mrta_builder

mrs/config/task_factory.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

mrs/db/__init__.py

Whitespace-only changes.

mrs/db/models/__init__.py

Whitespace-only changes.

mrs/db/models/performance/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)