Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

# Pull python packages from internal feed
COPY pip.conf /root/.pip/pip.conf

# Install SDK3 Python
COPY bonsai3-py ./bonsai3-py
COPY microsoft-bonsai-api/Python ./microsoft-bonsai-api
COPY sim-common ./sim-common
RUN pip3 install -U setuptools \
&& cd bonsai3-py \
&& cd microsoft-bonsai-api \
&& python3 setup.py develop \
&& cd ../sim-common \
&& python3 setup.py develop \
&& pip3 uninstall -y setuptools

Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
This project is a simulator for the Moab device. For more information, visit the micro-site at https://aka.ms/moab.

## Building Demo Dockerfile
Clone the [bonsai3-py](https://github.com/BonsaiAI/bonsai3-py) repo locally, and install it. Arrange this repo and bonsai3-py in the following directory structure:
```
./
./bonsai3-py
./samples/moabsim-py/
```
The following instructions are assuming you are using the bonsai-sdk repo to try out the sample. It will not work without it as it installs the dependencies from that repo.

From inside `./samples/moabsim-py/` build the image:
```sh
Expand Down
26 changes: 17 additions & 9 deletions moab_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
__author__ = "Mike Estee"
__copyright__ = "Copyright 2020, Microsoft Corp."

# pyright: strict
# pyright: strict, reportUnknownMemberType=false

import logging
import os
import sys
import json
from typing import Dict, Any

from jinja2 import Template
from pyrr import matrix33, vector

from bonsai3 import Schema, ServiceConfig, SimulatorInterface, SimulatorSession
from moab_model import MoabModel, clamp

from sim_common import SimulatorSession
from microsoft_bonsai_api.simulator.models import SimulatorInterface
from microsoft_bonsai_api.client import BonsaiClientConfig

log = logging.getLogger(__name__)


class MoabSim(SimulatorSession):
def __init__(self, config: ServiceConfig):
def __init__(self, config: BonsaiClientConfig):
super().__init__(config)
self.model = MoabModel()
self._episode_count = 0
Expand Down Expand Up @@ -77,12 +82,15 @@ def get_interface(self) -> SimulatorInterface:
ball_noise=self.model.ball_noise,
plate_noise=self.model.plate_noise,
)

interface = json.loads(interface_str)
return SimulatorInterface(
context=self.get_simulator_context(), json_interface=interface_str
name=interface["name"],
timeout=interface["timeout"],
simulator_context=self.get_simulator_context(),
description=interface["description"],
)

def get_state(self) -> Schema:
def get_state(self) -> Dict[str, Any]:
return self.model.state()

def _set_velocity_for_speed_and_direction(self, speed: float, direction: float):
Expand All @@ -105,7 +113,7 @@ def _set_velocity_for_speed_and_direction(self, speed: float, direction: float):
self.model.ball_vel.y = vel[1]
self.model.ball_vel.z = vel[2]

def episode_start(self, config: Schema) -> None:
def episode_start(self, config: Dict[str, Any]) -> None:
# return to known good state to avoid accidental episode-episode dependencies
self.model.reset()

Expand Down Expand Up @@ -173,7 +181,7 @@ def episode_start(self, config: Schema) -> None:
self.iteration_count = 0
self._episode_count += 1

def episode_step(self, action: Schema):
def episode_step(self, action: Dict[str, Any]):
# use new syntax or fall back to old parameter names
self.model.roll = action.get("input_roll", self.model.roll)
self.model.pitch = action.get("input_pitch", self.model.pitch)
Expand Down Expand Up @@ -204,7 +212,7 @@ def episode_finish(self, reason: str):
if __name__ == "__main__":
try:
# configuration for talking to server
config = ServiceConfig(argv=sys.argv)
config = BonsaiClientConfig(argv=sys.argv)
sim = MoabSim(config)
sim.model.reset()
while sim.run():
Expand Down