Skip to content

Commit

Permalink
Merge pull request #2 from anenriquez/master
Browse files Browse the repository at this point in the history
Fixing setup, dependencies, database per robot, refactoring
  • Loading branch information
argenos committed Aug 20, 2019
2 parents e2c2012 + 73e3a93 commit 035a38f
Show file tree
Hide file tree
Showing 33 changed files with 844 additions and 398 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_install:

script:
- docker-compose up -d robot
- docker-compose up -d task_allocator
- docker-compose up --exit-code-from task_allocation_test
after_script:
- docker stop $(docker ps -aq)
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ docker-compose build task_allocation_test

docker-compose up -d robot

docker-compose up -d task_allocator

docker-compose up task_allocation_test


Expand All @@ -60,8 +62,6 @@ Install the repositories

- [ropod_common](https://github.com/ropod-project/ropod_common)

- [mrta_datasets](https://github.com/anenriquez/mrta_datasets.git )


Get the requirements:
```
Expand All @@ -71,18 +71,24 @@ pip3 install -r requirements.txt
Add the task_allocation to your `PYTHONPATH` by running:

```
sudo pip3 install -e .
pip3 install --user -e .
```

Go to `/allocation` and run in a terminal
Go to `/mrs` and run in a terminal

```
python3 robot.py ropod_001
```

Run in another terminal

```
python3 task_allocator.py
```

Go to `/tests` and run test in another terminal
```
python3 task_allocator.py three_tasks.csv
python3 allocation_test.py
```

## References
Expand Down
76 changes: 61 additions & 15 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ version: 2
ccu_store:
db_name: ropod_ccu_store
port: 27017
robot_store:
db_name: ropod_store
port: 27017
resources:
fleet:
- ropod_001
Expand All @@ -10,19 +13,27 @@ resources:

plugins:
task_allocation:
bidding_rule:
robustness: srea
temporal: completion_time
# Assuming we can have different types of tasks,
# specify from where to import the Task and TaskStatus classes
task_type:
class: 'mrs.structs.task'
allocation_method: tessi
round_time: 15 # seconds
robot_proxies: true
auctioneer: fms_zyre_api # This is completely Zyre dependent
stp_solver: srea
auctioneer:
round_time: 15 # seconds
alternative_timeslots: True
task_type: generic_task
corrective_measure: re-allocate
dispatcher:
freeze_window: 300 # seconds

robot_proxy:
bidder:
bidding_rule:
robustness: srea # has to be the same as the stp_solver
temporal: completion_time
auctioneer_name: fms_zyre_api # This is completely Zyre dependent
schedule_monitor:
corrective_measure: re-allocate
api:
version: 0.1.0
middleware:
Expand All @@ -37,6 +48,9 @@ robot_proxy:
message_types: # Types of messages the node will listen to. Messages not listed will be ignored
- TASK-ANNOUNCEMENT
- ALLOCATION
- TIMETABLE
- DELETE-TASK
debug_msgs: false
acknowledge: false
publish:
task:
Expand All @@ -56,43 +70,73 @@ robot_proxy:
component: 'bidder.task_announcement_cb'
- msg_type: 'ALLOCATION'
component: 'bidder.allocation_cb'

- msg_type: 'TIMETABLE'
component: '.timetable_cb'
- msg_type: 'DELETE-TASK'
component: '.delete_task_cb'

api:
version: 0.1.0
middleware:
- zyre
#- rest
#- ros
zyre:
zyre_node:
node_name: fms_zyre_api
interface: null
groups:
- ROPOD
- TASK-ALLOCATION
message_types: # Types of messages the node will listen to. Messages not listed will be ignored
- TASK
- TASK-PROGRESS
- BID
- FINISH-ROUND
- ALLOCATE-TASK
acknowledge: false
debug_messages:
- 'TASK-REQUEST'
publish:
task-announcement:
msg_type: 'TASK-ANNOUNCEMENT'
groups: ['TASK-ALLOCATION']
method: shout
allocation:
msg_type: 'ALLOCATION'
groups: ['TASK-ALLOCATION']
method: shout
callbacks:
- msg_type: 'TASK'
component: '.task_cb'
- msg_type: 'ALLOCATE-TASK'
component: 'auctioneer.allocate_task_cb'
- msg_type: 'BID'
component: '.bid_cb'
component: 'auctioneer.bid_cb'
- msg_type: 'FINISH-ROUND'
component: '.finish_round_cb'
component: 'auctioneer.finish_round_cb'
rest:
server:
ip: 127.0.0.1
port: 8081
routes:
- path: '/number'
resource:
module: 'fleet_management.api.rest.resources'
class: 'RandomGenerator'
ros:
publishers:
- topic: '/fms/task'
msg_type: Task
msg_module: ropod_ros_msgs.msg
subscribers:
- topic: '/fms/task_request'
msg_type: TaskRequest
msg_module: ropod_ros_msgs.msg
callback: task_cb

logger:
version: 1
formatters:
default:
format: '[%(levelname)-5.5s] %(asctime)s [%(name)-25.25s] %(message)s'
format: '[%(levelname)-5.5s] %(asctime)s [%(name)-35.35s] %(message)s'
datefmt: '%Y-%m-%d %H:%M:%S'
handlers:
console:
Expand Down Expand Up @@ -128,6 +172,8 @@ logger:
handlers: [console]
fms:
level: DEBUG
mrs:
level: DEBUG
root:
level: DEBUG
handlers: [console, file]
handlers: [console, file]
18 changes: 0 additions & 18 deletions config/logging.yaml

This file was deleted.

12 changes: 11 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ services:
tty: true
stdin_open: true

task_allocator:
container_name: task-allocator
image: ropod-mrs
working_dir: /mrta/mrs/
command: ["python3", "task_allocator.py"]
network_mode: "host"
tty: true
stdin_open: true

task_allocation_test:
build: .
container_name: task-mrs-test
image: ropod-mrs
working_dir: /mrta/tests/
command: ["python3", "fms_integration_test.py"]
command: ["python3", "allocation_test.py"]
network_mode: "host"
tty: true
stdin_open: true
depends_on:
- robot
- task_allocator


2 changes: 1 addition & 1 deletion mrs/config/task_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(self):
ropod_task_cls = getattr(import_module('ropod.structs.task'), 'Task')
self.register_task_cls('ropod_task', ropod_task_cls)

generic_task_cls = getattr(import_module('dataset_lib.task'), 'Task')
generic_task_cls = getattr(import_module('mrs.structs.task'), 'Task')
self.register_task_cls('generic_task', generic_task_cls)

task_request_cls = getattr(import_module('ropod.structs.task'), 'TaskRequest')
Expand Down
87 changes: 87 additions & 0 deletions mrs/db_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from mrs.structs.timetable import Timetable


class DBInterface(object):
def __init__(self, store):
self.store = store

def add_task(self, task):
"""Saves the given task to a database as a new document under the "tasks" collection.
"""
collection = self.store.db['tasks']
dict_task = task.to_dict()
self.store.unique_insert(collection, dict_task, 'id', task.id)

def update_task(self, task):
""" Updates the given task under the "tasks" collection
"""
collection = self.store.db['tasks']
task_dict = task.to_dict()

found_dict = collection.find_one({'id': task_dict['id']})

if found_dict is None:
collection.insert(task_dict)
else:
collection.replace_one({'id': task.id}, task_dict)

def get_tasks(self):
""" Returns a dictionary with the tasks in the "tasks" collection
"""
collection = self.store.db['tasks']
tasks_dict = dict()
for task in collection.find():
tasks_dict[task['id']] = task
return tasks_dict

def remove_task(self, task_id):
""" Removes task with task_id from the collection "tasks"
"""
collection = self.store.db['tasks']
collection.delete_one({'id': task_id})

def update_task_status(self, task, status):
task.status.status = status
self.update_task(task)

def get_task(self, task_id):
"""Returns a task dictionary representing the task with the given id.
"""
collection = self.store.db['tasks']
task_dict = collection.find_one({'id': task_id})
return task_dict

def add_timetable(self, timetable):
"""
Saves the given timetable under the "timetables" collection
"""
collection = self.store.db['timetables']
robot_id = timetable.robot_id
timetable_dict = timetable.to_dict()

self.store.unique_insert(collection, timetable_dict, 'robot_id', robot_id)

def update_timetable(self, timetable):
""" Updates the given timetable under the "timetables" collection
"""
collection = self.store.db['timetables']
timetable_dict = timetable.to_dict()
robot_id = timetable.robot_id

found_dict = collection.find_one({'robot_id': robot_id})

if found_dict is None:
collection.insert(timetable_dict)
else:
collection.replace_one({'robot_id': robot_id}, timetable_dict)

def get_timetable(self, robot_id, stp):
collection = self.store.db['timetables']
timetable_dict = collection.find_one({'robot_id': robot_id})

if timetable_dict is None:
return
timetable = Timetable.from_dict(timetable_dict, stp)
return timetable

Loading

0 comments on commit 035a38f

Please sign in to comment.