Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft easy adding walls issue: #77 #78

Merged
merged 12 commits into from
Apr 26, 2022
82 changes: 82 additions & 0 deletions docs/source/adding_to_envs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Adding elements to the environment
===================================

Walls
-----

To add a wall use:

.. code:: python

env.add_walls(dim, poses_2d)


dim: numpy.ndarray or list
| (optional) dim, short for dimensions if given dim must
| be of length 3 corresponding to [width, length, height].

| poses_2d: [np.ndarray, ...] or [list, ...]
| (optional) if given poses_2d must be a list with lists or numpy arrays of length 3
| correspond to [x_position, y_position, orientation] which refers to walls centers of mass.
| The height of the center of mass will be adjusted such that the bottom of the wall
| aligns with the ground plane. multiple walls can be placed
| by having multiple pose_2d in poses_2d.

Shapes
-------

To add a shape use:

.. code:: python

env.add_shapes(shape_type, dim, mass, poses_2d, place_height)


| shape_type: str
| (required) the 4 options available are:
| "GEOM_SPHERE", "GEOM_BOX", "GEOM_CYLINDER", "GEOM_CAPSULE".

| dim: numpy array of list
| (optional), if dimensions is specified the length dependents on the shape_type:
| GEOM_SPHERE, dim=[radius],
| GEOM_BOX, dim=[width, length, height],
| GEOM_CYLINDER, dim=[radius, length],
| GEOM_CAPSULE, dim=[radius, length],

| mass: int or float
| (optional) mass refers to the objects mass, which in uniformly distributed.

| poses_2d: [np.ndarray, ...] or [list, ...]
| (optional) if specified poses_2d must be a list containing lists or numpy arrays of length 3
| correspond to [x_position, y_position, orientation] indicates the shapes center of mass.
| multiple walls can be placed by having multiple pose_2d in poses_2d.

| place_height: int or float
| (optional) if specified it refers to the z_position of the center of mass
| if not specified, the shape will be placed such that the shapes bottom
| aligns with the ground plane.

URDF files
---------------
todo


Sensors
--------

A robot can be given a lidar or obstacle sensor by creating a sensor
object and passing it to the environment:

.. code:: python

sensor = ObstacleSensor()
env.add_sensor(sensor)

The observations from the sensor are returned by the ``env.step(action)`` call.
The structure of the observation varies depending on the sensor and its arguments
for more info see the Sensor class and subclasses located at urdfenvs/sensors/


Goals
------
todo..
30 changes: 30 additions & 0 deletions docs/source/dependencies.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Dependencies
============

Scenes
-------
todo...


Robot control with the keyboard
-------------------------------

Control robot actuators with keyboard keys. This is done by:

- Setting up a parent en child process with a pipe connection inbetween
- Setup and start main process with parent\_connection as argument
- Setup Responder object with child\_connection as argument
- Start Responder with parent process as argument

In the main loop an request for action should be made followed by
waiting for a response as such:

.. code:: python

parent_conn.send({"request_action": True})
keyboard_data = parent_conn.recv()
action = keyboard_data["action"]

Additionally custom key bindings and a default action can and passed as arguement
to the responder. An example can be found in `urdfenvs/examples/keyboard_input.py
<https://github.com/maxspahn/gym_envs_urdf/blob/master/examples/keyboard_input.py>`_.
84 changes: 46 additions & 38 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
Getting started
Generic URDF robots
===================

In this package, generic urdf robots and a panda gym environment are
available. The goal is to make this environment as easy as possible to
deploy. Although, we used the OpenAI-Gym framing, these environments are
not necessarly restricted to Reinforcement-Learning but rather to local
motion planning in general.

.. |img1| image:: img/pointRobot.gif
.. |img2| image:: img/pointRobotKeyboardInput.gif
.. |img3| image:: img/boxerRobot.gif
.. |img4| image:: img/tiagoKeyboardInput.gif
.. |img5| image:: img/panda.gif
.. |img6| image:: img/albert.gif


+--------+--------+--------+
| |img1| | |img2| | |img3| |
+--------+--------+--------+
+--------+--------+--------+
| |img4| | |img5| | |img6| |
+--------+--------+--------+

Getting started
===============

This is the guide to quickle get going with urdf gym environments.

Pre-requisites
----------------
--------------

- Python >3.6, <3.10
- pip3
Expand All @@ -14,7 +38,7 @@ Pre-requisites
Installation
------------

You first have to downlad the repository
You first have to download the repository

.. code:: bash

Expand Down Expand Up @@ -46,53 +70,37 @@ The virtual environment is entered by

Inside the virtual environment you can access all the examples.

Examples
-----------

Run example
^^^^^^^^^^^
Installing dependencies
-----------------------

You find several python scripts in `examples/
<https://github.com/maxspahn/gym_envs_urdf/tree/master/examples>`_. You can
test those examples using the following (if you use poetry, make sure to enter the virtual
environment first with ``poetry shell``)
This package depends on casadi for dynamics generation and gym.
Dependencies should be installed through pip or poetry, see below.

.. code:: python
Using pip, you can use

python3 pointRobot.py

Replace pointRobot.py with the name of the script you want to run.
.. code:: bash

Use environments
^^^^^^^^^^^^^^^^
pip3 install '.[options]'

Using poetry

In the ``examples``, you will find individual examples for all implemented
robots. Environments can be created using the normal gym syntax.
Gym environments rely mostly on three functions
.. code:: bash

- ``gym.make(...)`` to create the environment,
- ``gym.reset(...)`` to reset the environment,
- ``gym.step(action)`` to step one time step in the environment.
poetry install -E <options>

For example, in `examples/pointRobot.py
<https://github.com/maxspahn/gym_envs_urdf/blob/master/examples/pointRobot.py>`_, you
can find the following syntax to ``make``, ``reset`` and ``step`` the environment.
Options are ``keyboard`` and ``scenes``.

.. code:: python

env = gym.make('pointRobotUrdf-vel-v0', dt=0.05, render=True)
ob = env.reset(pos=pos0, vel=vel0)
ob, reward, done, info = env.step(action)
Examples
-----------

The id-tag in the ``make`` command specifies the robot and the control type.
You can get a full list of all available environments using
You find several python scripts in `examples/
<https://github.com/maxspahn/gym_envs_urdf/tree/master/examples>`_. You can
test those examples using the following (if you use poetry, make sure to enter the virtual
environment first with ``poetry shell``)

.. code:: python

from gym import envs
print(envs.registry.all())


Go ahead and explore all the examples you can finde there.
python3 pointRobot.py

Replace pointRobot.py with the name of the script you want to run.
6 changes: 4 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Welcome to urdfEnvs's documentation!

getting_started
windows
introduction
developers
introduction_to_envs
adding_to_envs
developpers
dependencies
contributing
api

Expand Down
54 changes: 54 additions & 0 deletions docs/source/introduction_to_envs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Creating environments
^^^^^^^^^^^^^^^^^^^^^


Examples can be found in the `urdfenvs/examples<https://github.com/maxspahn/gym_envs_urdf/tree/master/examples>`_ folder
you will find individual examples for all implemented
robots. Environments can be created using the normal gym syntax.
Gym environments rely mostly on three functions

- ``gym.make(...)`` to create the environment,
- ``gym.reset(...)`` to reset the environment,
- ``gym.step(action)`` to step one time step in the environment.

For example, in `examples/pointRobot.py
<https://github.com/maxspahn/gym_envs_urdf/blob/master/examples/pointRobot.py>`_, you
can find the following syntax to ``make``, ``reset`` and ``step`` the environment.

.. code:: python

env = gym.make('pointRobotUrdf-vel-v0', dt=0.05, render=True)
ob = env.reset(pos=pos0, vel=vel0)
ob, reward, done, info = env.step(action)

The id-tag in the ``make`` command specifies the robot and the control type.
You can get a full list of all available environments using

.. code:: python

from gym import envs
print(envs.registry.all())

Go ahead and explore all the examples you can find there.

Switching
--------

Environments can be created using the normal gym syntax. For example the
below code line creates a toy robot with 3 links.
Actions are velocities to the individual joints.

.. code:: python

env = gym.make('nLink-urdf-reacher-vel-v0', n=3, dt=0.01, render=True)

A holonomic and a differential drive mobile manipulator are implemented:

.. code:: python

env = gym.make('albert-reacher-vel-v0', dt=0.01, render=True)
env = gym.make('mobile-reacher-tor-v0', dt=0.01, render=True)

For most robots, different control interfaces are available, velocity
control, acceleration control and torque control.

2 changes: 1 addition & 1 deletion examples/boxer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def main():
for e in range(n_episodes):
ob = env.reset(pos=pos0)
print(f"Initial observation : {ob}")
env.set_walls(limits=[[-4, -4], [4, 4]])
env.add_walls()
print("Starting episode")
for i in range(n_steps):
action = defaultAction
Expand Down
2 changes: 1 addition & 1 deletion examples/point_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
vel0 = np.array([1.0, 0.0, 0.0])
ob = env.reset(pos=pos0, vel=vel0)
print(f"Initial observation : {ob}")
env.set_walls(limits=[[-3, -2], [3, 2]])
env.add_walls()
if obstacles:
from examples.scene_objects.obstacles import (
sphereObst1,
Expand Down
Loading