Skip to content

Commit

Permalink
Merge pull request #49 from inverted-ai/master
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
AlirezaMorsali committed Oct 21, 2022
2 parents 850d1f8 + 7f884de commit aab7805
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/Colab-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install invertedai==0.0.3rc2\n",
"!pip install invertedai==0.0.3rc4\n",
"from IPython.display import display, Image, clear_output\n",
"import matplotlib.pyplot as plt\n",
"import imageio\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/Drive-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install invertedai==0.0.3rc2\n",
"!pip install invertedai==0.0.3rc4\n",
"%matplotlib widget\n",
"from IPython.display import clear_output\n",
"from invertedai import Jupyter_Render\n",
Expand Down
13 changes: 13 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Examples

We have a few examples that demonstrate the behavior of the API without running a local simulator.
To run the examples locally, first build the virtual environment.
```commandline
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```
Then, once you obtain an API key, you can run the examples.
```commandline
python Demo_Drive.py --api_key $IAI_API_KEY
```
1 change: 1 addition & 0 deletions examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
invertedai
jupyterlab==3.4.4
opencv-python==4.6.0.66
ipympl==0.9.2
Expand Down
25 changes: 19 additions & 6 deletions invertedai/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import List, Tuple, Literal
from typing import List, Tuple
from enum import Enum

import invertedai as iai
Expand All @@ -10,21 +10,25 @@
float, float
] # lat/lon of the origin point use to project the OSM map to UTM


@dataclass
class RecurrentState:
"""
Recurrent state used in :func:`iai.drive`.
It should not be modified, but rather passed along as received.
"""

packed: List[float] #: Internal representation of the recurrent state.


@dataclass
class Point:
"""
2D coordinates of a point in a given location.
Each location comes with a canonical coordinate system, where
the distance units are meters.
"""

x: float
y: float

Expand All @@ -36,6 +40,7 @@ class LocationMap:
with the UTM projector using the origin provided here.
This projection defines the canonical coordinate frame of the map.
"""

def __init__(self, encoded_map: str, origin: Origin):
self._encoded_map = encoded_map
self._origin = origin
Expand All @@ -62,6 +67,7 @@ class Image:
Images sent through the API in their encoded format.
Decoding the images requires additional dependencies on top of what invertedai uses.
"""

def __init__(self, encoded_image: List[int]):
self._encoded_image = encoded_image

Expand All @@ -70,7 +76,9 @@ def decode(self):
import numpy as np
import cv2
except ImportError as e:
iai.logger.error("Decoding images requires numpy and cv2, which were not found.")
iai.logger.error(
"Decoding images requires numpy and cv2, which were not found."
)
raise e
array = np.array(self._encoded_image, dtype=np.uint8)
image = cv2.imdecode(array, cv2.IMREAD_COLOR)
Expand All @@ -83,8 +91,8 @@ def decode_and_save(self, path):
"""
image = self.decode()
import cv2
cv2.imwrite(path, image)

cv2.imwrite(path, image)


class TrafficLightState(Enum):
Expand All @@ -95,6 +103,7 @@ class TrafficLightState(Enum):
--------
StaticMapActor
"""

none = "0" #: The light is off and will be ignored.
green = "1"
yellow = "2"
Expand All @@ -111,6 +120,7 @@ class AgentAttributes:
--------
AgentState
"""

length: float #: Longitudinal extent of the agent, in meters.
width: float #: Lateral extent of the agent, in meters.
rear_axis_offset: float #: Distance from the agent's center to its rear axis in meters. Determines motion constraints.
Expand All @@ -128,6 +138,7 @@ class AgentState:
--------
AgentAttributes
"""

center: Point #: The center point of the agent's bounding box.
orientation: float #: The direction the agent is facing, in radians with 0 pointing along x and pi/2 pointing along y.
speed: float #: In meters per second, negative if the agent is reversing.
Expand All @@ -146,6 +157,7 @@ class InfractionIndicators:
"""
Infractions committed by a given agent, as returned from :func:`iai.drive`.
"""

collisions: bool #: True if the agent's bounding box overlaps with another agent's bounding box.
offroad: bool #: True if the agent is outside the designated driveable area specified by the map.
wrong_way: bool #: True if the cross product of the agent's and its lanelet's directions is negative.
Expand All @@ -162,8 +174,9 @@ class StaticMapActor:
--------
TrafficLightState
"""

track_id: TrafficLightId #: ID as used in :func:`iai.initialize` and :func:`iai.drive`.
agent_type: Literal["traffic-light"] #: Not currently used, there may be more traffic signals in the future.
agent_type: str #: Not currently used, there may be more traffic signals in the future.
center: Point #: The center of the stop line.
orientation: float #: Natural direction of traffic going through the stop line, in radians like in :class:`AgentState`.
length: float #: Size of the stop line, in meters, along its `orientation`.
Expand All @@ -172,6 +185,6 @@ class StaticMapActor:
@classmethod
def fromdict(cls, d):
d = d.copy()
d['center'] = Point(d['x'], d['y'])
del d['center']
d["center"] = Point(d["x"], d["y"])
del d["center"]
return cls(**d)
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "invertedai"
version = "0.0.3rc2"
version = "0.0.3rc4"
description = "Client SDK for InvertedAI"
authors = ["Inverted AI <info@inverted.ai>"]
readme = "README.md"
Expand All @@ -13,7 +13,7 @@ packages = [
python = ">=3.7,<3.11"
requests = "^2.28.1"

#[tool.poetry.group.dev.dependencies]
[tool.poetry.group.dev.dependencies]
numpy = "^1.17.0"
matplotlib = "^3.5"
ipython = "^7.34"
Expand All @@ -22,7 +22,7 @@ carla = "^0.9.13"
jupyterlab = "^3.3"
twine = "^4.0.1"

#[tool.poetry.group.docs.dependencies]
[tool.poetry.group.docs.dependencies]
Sphinx = "^5.2.3"
myst-parser = "^0.18.1"
furo = "^2022.9.29"
Expand Down

0 comments on commit aab7805

Please sign in to comment.