Skip to main content

Comma body gymnasium API

Project description

bodyjim

comma body gymnasium environment API.

Winking comma body

Installation

To install bodyjim run the following command:

pip install bodyjim

Package requires comma body with comma three/threex running openpilot 0.9.6 or newer.

Usage

Just like other gymnasium environments, bodyjim is easy to use. Base BodyEnv accepts ip address of the body, list of cameras to stream (valid values: driver - driver camera, road - front camera, wideRoad - front wide angle camera) and list of cereal services to stream (list of services).

Environment's step method accepts action in x, y direction coordinates and retrieves next observation in form of a dict with latest camera frames and cereal messages (structure definitions) received so far. Additional info dictionary contains information about message creation timestamps and validity (which are None, if they haven't been received yet).

from bodyjim import BodyEnv

body_address = ... # body ip address, pass localhost if running locally on the body
env = BodyEnv(body_address, ["driver"], ["accelerometer", "gyroscope"], render_mode="human")
env.reset()

# action coordinates assuming the front is the screen-facing side
# x-axis: Forward (negative) / Backwards (positive)
# y-axis: Left (positive) / Right (negative)
action = (1.0, 0.0) # (x, y)
obs, reward, done, truncated, info = env.step(action)

# obs  = { "cameras": { "driver": np.ndarray }, "accelerometer": {...}, "gyroscope": {...} }
# info = { "times": <dict_of_ns_timestamps_for_each_service>, "valid": <dict_of_message_validity_for_each_service> }
driver_image = obs["camera"]["driver"] # nd.ndarray
accelerometer, accelerometer_t = obs["accelerometer"], info["times"]["accelerometer"]

By default body environment always returns reward = 0 and done = False. Subclasses can customize this behavior by overriding reward and is_done methods:

class CustomBodyEnv(BodyEnv):
  def reward(self, obs: Optional[ObsType], action: ActType, next_obs: ObsType) -> float:
    # obs - latest observations, action - most recently executed actions, next_obs - observations after executing such action
    ...

  def is_done(self, obs: Optional[ObsType], action: ActType, next_obs: ObsType) -> bool:
    # same as for reward
    ...

BodyEnv supports two rendering modes for visualization purposes:

  • rgb_array - returns image formed by horizontally stacking frames from each requested camera
  • human - displays pygame window with live view from cameras

Examples

Repository comes with few examples, showcasing how to use the library.

You can use the body-jim library either on the body itself or from a remote computer. These examples are meant to be ran remotely and require additional dependencies, which can be installed using:

pip install bodyjim[examples]

To control the body with wasd:

python3 examples/wasd.py body_ip_address [CAMERA...]

To perform "random walk":

python3 examples/random_walk.py body_ip_address [CAMERA...]

To try follow person mode, which uses YOLOv5 to detect and follow the tallest person in the frame:

python3 examples/follow_human.py body_ip_address

To have the body roam around using our GPT policy (GPU required):

python3 examples/roam.py body_ip_address

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bodyjim-1.0.3.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

bodyjim-1.0.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file bodyjim-1.0.3.tar.gz.

File metadata

  • Download URL: bodyjim-1.0.3.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for bodyjim-1.0.3.tar.gz
Algorithm Hash digest
SHA256 8299c067608276f945f0edfce0dca011c2477936fa6d0dd3a018b87e00a2f6b4
MD5 d090c5f2971e22712aae9388bd1dac4e
BLAKE2b-256 be61159de92956a03f84951aaf844b63b787060d37e073237c332e94ddfc27bc

See more details on using hashes here.

File details

Details for the file bodyjim-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: bodyjim-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for bodyjim-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bbef614ab54ebb468f96f6625909fa42059d8217fb2171f5c01f12a0124693e3
MD5 f7f93dd654192ec607fb683cc31ba844
BLAKE2b-256 daa2efc32fc2350fc17d6eea209ee86c7fffa312cf7590fac212f3138a8741f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page