-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b73f88
commit ab9d7fb
Showing
23 changed files
with
784 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM python:3.7 | ||
WORKDIR /project | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM python:3.7 | ||
WORKDIR /project | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
** | ||
!*.py | ||
!requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.7 | ||
WORKDIR /project | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
|
||
|
||
COPY . . | ||
|
||
ENTRYPOINT ["python3", "dummy_simulator.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
repo=aidonode-dummy_simulator | ||
# repo=$(shell basename -s .git `git config --get remote.origin.url`) | ||
branch=$(shell git rev-parse --abbrev-ref HEAD) | ||
tag=duckietown/$(repo):$(branch) | ||
|
||
build: | ||
docker build -t $(tag) . | ||
|
||
build-no-cache: | ||
docker build -t $(tag) --no-cache . | ||
|
||
push: build | ||
docker push $(tag) | ||
|
||
test-data1-direct: | ||
./dummy_simulator.py < test_data/in1.json > test_data/out1.json | ||
|
||
test-data1-docker: | ||
docker run -i $(tag) < test_data/in1.json > test_data/out1.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env python3 | ||
from dataclasses import dataclass | ||
|
||
import numpy as np | ||
|
||
from aido_node_wrapper import wrap_direct, Context | ||
from aido_schemas import JPGImage, Duckiebot1Observations, Duckiebot1Commands | ||
from aido_schemas.protocol_simulator import SetMap, SpawnRobot, RobotName, StateDump, Step, RobotInterfaceDescription, \ | ||
RobotObservations, RobotState, protocol_simulator, SetRobotCommands, RobotPerformance, Metric, PerformanceMetrics | ||
|
||
|
||
# Specialize to our datatype | ||
@dataclass | ||
class MySetRobotCommands(SetRobotCommands): | ||
robot_name: RobotName | ||
t_effective: float | ||
commands: Duckiebot1Commands | ||
|
||
|
||
@dataclass | ||
class MyRobotObservations(RobotObservations): | ||
observations: Duckiebot1Observations | ||
|
||
|
||
class DummySimulator: | ||
""" A dummy simulator implementation. """ | ||
current_time: float | ||
robot_name: str | ||
|
||
def init(self, context: Context): | ||
context.log('init()') | ||
|
||
def on_received_seed(self, context, data: int): | ||
context.log(f'seed({data})') | ||
|
||
def on_received_clear(self, context): | ||
context.log(f'clear()') | ||
|
||
def on_received_set_map(self, context, data: SetMap): | ||
context.log(f'set_map({data})') | ||
# TODO: load map | ||
|
||
def on_received_spawn_robot(self, data: SpawnRobot): | ||
self.robot_name = data.robot_name | ||
# TODO: set pose of robot | ||
|
||
def on_received_get_robot_interface_description(self, context, data: RobotName): | ||
rid = RobotInterfaceDescription(robot_name=data, observations=Duckiebot1Observations, | ||
commands=Duckiebot1Commands) | ||
context.write('robot_interface_description', rid) | ||
|
||
def on_received_get_robot_performance(self, context, data: RobotName): | ||
context.log(f'get_robot_interface_description()') | ||
metrics = {} | ||
metrics['reward'] = Metric(higher_is_better=True, cumulative_value=self.current_time, | ||
description="Dummy reward equal to survival time.") | ||
pm = PerformanceMetrics(metrics) | ||
rid = RobotPerformance(robot_name=data, t_effective=self.current_time, performance=pm) | ||
context.write('robot_performance', rid) | ||
|
||
def on_received_start_episode(self, context): | ||
context.log(f'start_episode()') | ||
self.current_time = 0 | ||
|
||
def on_received_step(self, context, data: Step): | ||
context.log(f'step({data})') | ||
self.current_time = data.until | ||
|
||
def on_received_set_robot_commands(self, context, data: MySetRobotCommands): | ||
context.log(f'set_robot_commands({data})') | ||
|
||
def on_received_get_robot_observations(self, context, data: RobotName): | ||
context.log(f'get_robot_observation({data!r})') | ||
camera = get_random_image(shape=(200, 300)) | ||
obs = Duckiebot1Observations(camera) | ||
ro = MyRobotObservations(obs) | ||
context.write('robot_observations', ro, with_schema=True) | ||
|
||
def on_received_get_robot_state(self, context, data: RobotName): | ||
context.log(f'get_robot_state({data!r})') | ||
rs = RobotState(robot_name=data, t_effective=self.current_time, state=None) | ||
context.write('robot_state', rs) | ||
|
||
def on_received_dump_state(self, context): | ||
context.log(f'dump_state()') | ||
context.write('dump_state', StateDump(None)) | ||
|
||
|
||
def get_random_image(shape): | ||
H, W = shape | ||
values = (128 + np.random.randn(H, W, 3) * 60).astype('uint8') | ||
jpg_data = bgr2jpg(values) | ||
image = JPGImage(jpg_data) | ||
return image | ||
|
||
|
||
# noinspection PyUnresolvedReferences | ||
def bgr2jpg(image_cv) -> bytes: | ||
import cv2 | ||
compress = cv2.imencode('.jpg', image_cv)[1] | ||
jpg_data = np.array(compress).tostring() | ||
return jpg_data | ||
|
||
|
||
def main(): | ||
node = DummySimulator() | ||
protocol = protocol_simulator | ||
protocol.inputs['set_robot_commands'] = MySetRobotCommands | ||
protocol.outputs['robot_observations'] = MyRobotObservations | ||
wrap_direct(node=node, protocol=protocol) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-e git://github.com/duckietown/aido-protocols.git@v4-devel3#egg=aido-protocols | ||
-e git://github.com/AndreaCensi/zuper_utils.git@v4-devel#egg=zuper_utils | ||
|
||
numpy==1.16.2 | ||
|
||
|
||
opencv-python==4.0.0.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"compat": ["aido2"], "topic": "seed", "data": 12} | ||
{"compat": ["aido2"], "topic": "clear"} | ||
{"compat": ["aido2"], "topic": "set_map", "data": {"map_data": "TBD"}} | ||
{"compat": ["aido2"], "topic": "spawn_robot", "data": {"robot_name": "ego", "configuration": {"pose": null, "velocity": null }}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM python:3.7 | ||
WORKDIR /project | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
import logging | ||
|
||
from aido_nodes import logger as aido_nodes_logger | ||
|
||
logger = aido_nodes_logger.getChild('wrapper') | ||
|
||
logger_interaction = logger.getChild("interaction") | ||
|
||
logger_interaction.setLevel(logging.CRITICAL) | ||
|
||
from .wrapper import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
|
||
ENV_NAME = 'AIDONODE_NAME' | ||
ENV_DATA_IN = 'AIDONODE_DATA_IN' | ||
ENV_DATA_OUT = 'AIDONODE_DATA_OUT' | ||
ENV_META_IN = 'AIDONODE_META_IN' | ||
ENV_META_OUT = 'AIDONODE_META_OUT' | ||
ENV_TRANSLATE = 'AIDONODE_TRANSLATE' | ||
ENV_ENCODING = 'AIDONODE_ENCODING' | ||
ENV_ENCODING_JSON = 'json' | ||
ENV_ENCODING_CBOR = 'cbor' | ||
ENV_ENCODING_VALID = [ENV_ENCODING_JSON, ENV_ENCODING_CBOR] | ||
KNOWN = [ENV_DATA_IN, ENV_DATA_OUT, ENV_META_IN, ENV_META_OUT, ENV_NAME, ENV_TRANSLATE, ENV_ENCODING] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.