BaseEnv

BaseEnv and CameraEnv are the basic classes for environments in myGym. These environments do not contain any objects or robots, but maintain the essential methods that all custom environment share. The CameraEnv is meant for environments that utilize cameras and image rendering.

class myGym.envs.base_env.BaseEnv(gui_on=True, objects_dir_path='/home/megi/git/myGym/myGym/envs/', max_steps=1024, show_bounding_boxes_gui=False, changing_light_gui=False, shadows_on_gui=True)[source]

The base class for environments without rendering

Parameters:
param gui_on

(bool) Whether or not to use PyBullet built-in GUI

param objects_dir_path

(str) Path to directory with URDF files for objects

param max_steps

(int) The maximum number of actions per episode

param show_bounding_boxes_gui

(bool) Whether or not to show bounding boxes in GUI

param changing_light_gui

(bool) Whether or not to change light in GUI

param shadows_on_gui

(bool) Whether or not to show shadows in GUI

step(action)[source]

Apply action on the environment

Parameters:
param action

(object) An action provided by the agent

Returns:
return observation

(object)

return reward

(float)

return done

(bool):

return info

(dict):

seed(seed=None)[source]

Set the seed for this env’s random number generator(s)

hard_reset()[source]

Full reset of the simulation. Delete and load again all objects and reset physics.

reset(hard=False)[source]

Reset the state of the environment

get_texturizable_objects_uids()[source]

Get all objects in the environment, on which textures can be applied

Returns:
return texturizable_objects_uids

(list)

get_colorizable_objects_uids()[source]

Get all objects in the environment, which color can be changed

Returns:
return colorizable_objects_uids

(list)

class myGym.envs.base_env.CameraEnv(camera_resolution=[640, 480], shadows_on=True, render_on=True, renderer=131072, active_cameras=None, **kwargs)[source]

The class for environments with rendering

Parameters:
param camera_resolution

(list) The number of pixels in image (WxH)

param shadows_on

(bool) Whether or not to use shadows while rendering, only applies to ER_TINY_RENDERER

param render_on

(bool) Turn on rendering

param renderer

(int) self.p.ER_TINY_RENDERER (CPU) or self.p.ER_BULLET_HARDWARE_OPENGL (GPU)

param active_cameras

(list) Set 1 at a position(=camera number) to save images from this camera

set_light(light_direction=[1, 1, 1], light_color=[0.1, 0.1, 0.1], light_distance=1.0, light_ambient=1.0, light_diffuse=1.0, light_specular=1.0)[source]

Set light parameters for rendering, doesn’t affect PyBullet GUI. Appart from light_direction, all parameters only apply to ER_TINY_RENDERER.

Parameters:
param light_direction

(list) Specifies the world position of the light source

param light_color

(list) Directional light color in RGB in range 0..1

param light_distance

(float) Distance of the light along the normalized light_direction

param light_ambient

(float) Light ambient coefficient in range 0..1

param light_diffuse

(float) Light diffuse coefficient in range 0..1

param light_specular

(float) Light specular coefficient in range 0..1

get_render_parameters()[source]

Return environment parameters for rendering, initially is intended to use by cameras

Returns:
return render_parameters

(dict) Render parameters

add_camera(**kwargs)[source]

Add new camera to the environment

Parameters:
param position

(list) Eye position in Cartesian world coordinates

prarm target_position

(list) Position of the target point

param up_vector

(list) Up vector of the camera

param up_axis_index

(int) Either 1 for Y or 2 for Z axis up

param yaw

(float) Yaw angle in degrees left/right around up-axis

param pitch

(float) Pitch in degrees up/down

param roll

(float) Roll in degrees around forward vector

param distance

(float) Distance from eye to focus point

param field_of_view

(float) Field of view

param near_plane_distance

(float) Near plane distance

param far_plane_distance

(float) Far plane distance

render(mode='rgb_array', camera_id=None)[source]

Get image (image, depth, segmentation_mask) from camera or active cameras

Parameters:
param mode

(str) rgb_array to return RGB image

param camera_id

(int) Get image from specified camera

Returns:
return camera_data

(dict) Key: camera_id, Value: info from camera

project_point_to_camera_image(point, camera_id)[source]

Project 3D point in Cartesian world coordinates to 2D point in pixel space

Parameters:
param point

(list) 3D point in Cartesian world coordinates

param camera_id

(int) Index of camera to project on

Returns:
return 2d_point

(list) 2D coordinates of point on imageg

get_camera_opencv_matrix_values(camera_id)[source]

Compute values of OpenCV matrix

Parameters:
param camera_id

(int) Index of camera to get matrix from

Returns:
return values

(dict) fx, fy, cx, cy values