Visualization

# @FileName : Visualizer.py # @Time : 2024-08-03 15:09:53 # @Author : yk # @Email : yangkui1127@gmail.com # @Description: : Visualizer for pybullet

class Visualization.Visualizer.Visualizer(client, visualizer_cfg)[source]

A class for visualizing objects and scenes in PyBullet.

client

The PyBullet client object.

Type:

object

client_id

The client id returned by the PyBullet client.

Type:

int

set_camera_pose(camera_cfg)[source]

Sets the debug visualizer camera pose.

Parameters:

camera_cfg (object) – Configuration for the camera pose.

capture_screen(filename=None)[source]

Continuously captures the screens of PyBullet GUI and saves the images to files.

Parameters:

filename (str, optional) – The filename to save the captured image. Defaults to None.

draw_axes(length=1.0, lineWidth=2.0, textSize=1.0)[source]

Draws the x, y, and z axes in the PyBullet environment with text labels.

Parameters:
  • length (float) – Length of the axes.

  • lineWidth (float) – Width of the axes lines.

  • textSize (float) – Size of the text labels.

start_record(fileName)[source]

Starts recording a video of the PyBullet simulation.

Parameters:

fileName (str) – The filename for the video file.

end_record()[source]

Stops recording the video.

draw_line(start_pos, target_pos, color=[1, 0, 0], width=3.0)[source]

Draws a line on the screen from the specified start position to the target position.

Parameters:
  • start_pos (tuple) – The starting position of the line as a tuple of (x, y, z) coordinates.

  • target_pos (tuple) – The ending position of the line as a tuple of (x, y, z) coordinates.

  • color (list, optional) – A list representing the RGB values of the line’s color. Default is red [1, 0, 0].

  • width (float, optional) – The width of the line. Default is 3.0.

remove_all_line()[source]

Removes all user debug items (lines) from the PyBullet environment.

draw_aabb(object)[source]

Draws an Axis-Aligned Bounding Box (AABB) around the specified object in the simulation.

Parameters:

object (Union[int, str]) – The unique identifier of the object or its name.

Draws an Axis-Aligned Bounding Box (AABB) around the specified link in the simulation.

Parameters:
  • object (Union[int, str]) – The unique identifier of the object or its name.

  • link_id (int, optional) – The index of the link for which the AABB is to be drawn. Defaults to -1, which means the entire object.

draw_object_pose(object, length=0.25, lineWidth=2.0, textSize=1.0)[source]

Draws the pose of an object in the PyBullet environment.

Parameters:
  • object (Union[int, str]) – The unique identifier of the object or its name.

  • length (float, optional) – The length of the pose axes. Default is 0.25.

  • lineWidth (float, optional) – The width of the pose axes lines. Default is 2.0.

  • textSize (float, optional) – The size of the text labels. Default is 1.0.

draw_pose(pose, length=0.25, lineWidth=2.0, textSize=1.0)[source]

Draws the pose of an object in the PyBullet environment.

Parameters:
  • object (Union[int, str]) – The unique identifier of the object or its name.

  • length (float, optional) – The length of the pose axes. Default is 0.25.

  • lineWidth (float, optional) – The width of the pose axes lines. Default is 2.0.

  • textSize (float, optional) – The size of the text labels. Default is 1.0.

Draws the pose of a specific link of an object in the PyBullet environment.

Parameters:
  • object (Union[int, str]) – The unique identifier of the object or its name.

  • link_id (int) – The index of the link for which the pose is to be drawn.

  • length (float, optional) – The length of the pose axes. Default is 0.25.

  • lineWidth (float, optional) – The width of the pose axes lines. Default is 2.0.

  • textSize (float, optional) – The size of the text labels. Default is 1.0.

change_robot_color(base_id, arm_id, light_color=True)[source]

Sets the color of the robot.

Parameters:
  • base_id (int) – The unique identifier of the robot base.

  • arm_id (int) – The unique identifier of the robot arm.

  • light_color (bool, optional) – Flag to set the robot to light colors. Default is True.

set_object_color(object_id, color)[source]

Sets the color of an object.

Parameters:
  • object_id (int) – The unique identifier of the object.

  • color (str) – The color to set for the object.

Sets the color of a specific link of an object.

Parameters:
  • object_id (int) – The unique identifier of the object.

  • link_id (int) – The index of the link to change the color.

  • color (str) – The color to set for the link.

Sets the colors of multiple links of an object.

Parameters:
  • object_id (int) – The unique identifier of the object.

  • link_ids (list[int]) – A list of link indexes to change the colors.

  • colors (list[str]) – A list of colors to set for the links.

# @FileName : Camera.py # @Time : 2024-08-03 15:09:34 # @Author : yk # @Email : yangkui1127@gmail.com # @Description: : Camera

class Visualization.Camera.Camera(cfg, base_id, arm_place_height)[source]

Robotic Camera.

This class handles the camera functionalities for a robotic system, including capturing RGB and depth images.

sim_get_focal_length()[source]

get camera focal length

sim_get_camera_pose()[source]

get camera pose

sim_update()[source]

Updates the camera view and projection matrices, captures images, and returns the captured data.

Returns:

Width, height, RGB image, depth image, and segmentation mask.

Return type:

tuple

sim_get_rgb_image(enable_show=False, enable_save=False, filename=None)[source]

Captures an RGB image from the camera.

Parameters:
  • enable_show (bool, optional) – Whether to display the captured image. Defaults to False.

  • enable_save (bool, optional) – Whether to save the captured image. Defaults to False.

Returns:

Captured RGB image.

Return type:

np.ndarray

sim_get_depth_image(enable_show=False, enable_save=False, filename=None)[source]

Captures a depth image from the camera.

Parameters:
  • enable_show (bool, optional) – Whether to display the captured image. Defaults to False.

  • enable_save (bool, optional) – Whether to save the captured image. Defaults to False.

Returns:

Captured depth image.

Return type:

np.ndarray

sim_rotate_around_y(vector, angle)[source]

vector rotate around y axis

Parameters:
  • vector (np.array) – vector

  • () (angle) – rotate angle

Returns:

rotated vector

sim_visualize_3d_points()[source]

visualize 3D point cloud.

sim_get_3d_points(filter_dist=[0, 1])[source]

Convert depth image to 3D point cloud.

Returns:

3D point cloud.

Return type:

np.ndarray

sim_trans_to_world(pose)[source]

Convert grasp pose from camera to world coord system

Parameters:

pose (Pose) – pose in camera coord system

Returns:

pose in world system

Return type:

Pose

# @FileName : pyBulletSimRecorder.py # @Time : 2024-08-03 15:09:24 # @Author : yk # @Email : yangkui1127@gmail.com # @Description: : A recorder in pybullet sim and the result can be import into blender scene

class Visualization.blender_render.pyBulletSimRecorder.PyBulletRecorder[source]

A class for recording PyBullet simulations.

class LinkTracker(type, name, body_id, link_id, link_origin, mesh_path, mesh_scale)[source]

Tracks the state of a link in the simulation.

transform(position, orientation)[source]

Transforms a local pose to a global pose.

Parameters:
  • position (list) – The position of the link.

  • orientation (list) – The orientation of the link.

Returns:

The transformed position and orientation.

Return type:

tuple

get_keyframe()[source]

Gets the global pose of the link.

Returns:

The position and orientation of the link.

Return type:

dict

register_object(body_id, urdf_path, global_scaling)[source]

Registers an object in the simulation for tracking.

Parameters:
  • body_id (int) – The ID of the body to be registered.

  • urdf_path (str) – The path to the URDF file of the object.

  • global_scaling (float) – The global scaling factor for the object.

add_keyframe()[source]

Adds a keyframe of the current simulation state.

reset()[source]

Resets the recorded simulation states.

get_formatted_output()[source]

Gets the formatted output of the recorded simulation states.

Returns:

Formatted output of the recorded simulation states.

Return type:

dict

save(path)[source]

Saves the recorded simulation states to a file.

Parameters:

path (str) – The path to save the recorded simulation states.