Robot API
A simulated robot loaded from a URDF or MJCF file.
Provides structured access to all joints and links by name, along with base-link state properties, RL-compatible state/action interfaces, and reset functionality.
Do not instantiate directly — use the :meth:load class method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body_id
|
int
|
PyBullet body ID. |
required |
sim
|
'Simulation'
|
The parent :class: |
required |
name
|
str
|
Human-readable robot name. |
'Robot'
|
initial_position
|
tuple[float, float, float]
|
Initial base position. |
(0.0, 0.0, 0.0)
|
initial_orientation
|
tuple[float, float, float, float]
|
Initial base orientation (quaternion). |
(0.0, 0.0, 0.0, 1.0)
|
Example::
robot = Robot.load("car.urdf", sim=sim, position=(0, 0, 0.5))
robot.joints["steering"].set_position(0.3)
robot.links["chassis"].mass = 10.0
Source code in bulletlab/robot/robot.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
base_angular_velocity: tuple[float, float, float]
property
World-frame angular velocity (wx, wy, wz) in rad/s.
Example::
wx, wy, wz = robot.base_angular_velocity
base_orientation: tuple[float, float, float, float]
property
World-frame base orientation as quaternion (x, y, z, w).
Example::
q = robot.base_orientation
base_position: tuple[float, float, float]
property
World-frame base position (x, y, z) in meters.
Example::
x, y, z = robot.base_position
base_velocity: tuple[float, float, float]
property
World-frame linear velocity (vx, vy, vz) in m/s.
Example::
speed = robot.base_velocity[0]
body_id: int
property
PyBullet body ID (internal identifier). Prefer using named properties.
controllable_joints: list[Joint]
property
List of all non-fixed joints (those that can be actuated).
joints: dict[str, Joint]
property
Dictionary of all joints indexed by name.
Example::
robot.joints["wheel_left"].velocity = 10
links: dict[str, Link]
property
Dictionary of all links indexed by name.
Example::
robot.links["chassis"].mass = 5.0
name: str
property
writable
Human-readable robot name.
num_controllable_joints: int
property
Number of non-fixed, actuatable joints.
num_joints: int
property
Total number of joints (including fixed joints).
pitch: float
property
Base pitch angle in radians (rotation around Y axis).
roll: float
property
Base roll angle in radians (rotation around X axis).
Example::
print(f"Roll: {math.degrees(robot.roll):.1f}°")
speed: float
property
Scalar speed (magnitude of base linear velocity) in m/s.
Example::
print(f"Speed: {robot.speed:.2f} m/s")
yaw: float
property
Base yaw angle in radians (rotation around Z axis).
apply_action(action: np.ndarray) -> None
Apply a NumPy action array to all controllable joints.
The action array must have the same length as the number of controllable joints. Each value is interpreted as a target velocity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
ndarray
|
1D NumPy array of target velocities for each controllable joint. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example::
action = np.array([10.0, 10.0, -5.0])
robot.apply_action(action)
Source code in bulletlab/robot/robot.py
apply_torques(torques: np.ndarray) -> None
Apply torque control to all controllable joints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
torques
|
ndarray
|
1D NumPy array of torques for each controllable joint (N·m). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example::
robot.apply_torques(np.array([5.0, -5.0, 0.0]))
Source code in bulletlab/robot/robot.py
get_state() -> np.ndarray
Return the full observable state as a flat NumPy array.
State vector layout::
[base_x, base_y, base_z, # base position (3)
base_qx, base_qy, base_qz, base_qw, # base orientation quaternion (4)
base_vx, base_vy, base_vz, # base linear velocity (3)
base_wx, base_wy, base_wz, # base angular velocity (3)
joint_pos_0, ..., # controllable joint positions (N)
joint_vel_0, ...] # controllable joint velocities (N)
Returns:
| Type | Description |
|---|---|
ndarray
|
1D NumPy float64 array of shape |
ndarray
|
number of controllable joints. |
Example::
state = robot.get_state()
action = my_policy(state)
Source code in bulletlab/robot/robot.py
load(path: str | Path, sim: 'Simulation', position: tuple[float, float, float] = (0.0, 0.0, 0.0), orientation: tuple[float, float, float, float] = (0.0, 0.0, 0.0, 1.0), name: str | None = None, fixed_base: bool = False, scale: float = 1.0, flags: int = 0) -> 'Robot'
classmethod
Load a robot from a URDF or MJCF file.
Automatically discovers all joints and links and exposes them by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the URDF/MJCF file. Can be an absolute path or a filename resolvable from the pybullet_data search path. |
required |
sim
|
'Simulation'
|
The :class: |
required |
position
|
tuple[float, float, float]
|
Initial base position |
(0.0, 0.0, 0.0)
|
orientation
|
tuple[float, float, float, float]
|
Initial base orientation as a quaternion |
(0.0, 0.0, 0.0, 1.0)
|
name
|
str | None
|
Human-readable robot name. Defaults to the filename stem. |
None
|
fixed_base
|
bool
|
If |
False
|
scale
|
float
|
Global scale factor for the loaded model. |
1.0
|
flags
|
int
|
Additional PyBullet load flags. |
0
|
Returns:
| Type | Description |
|---|---|
'Robot'
|
A new :class: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the URDF/MJCF file cannot be found. |
RuntimeError
|
If PyBullet fails to load the model. |
Example::
robot = Robot.load("kuka_iiwa/model.urdf", sim=sim, position=(0, 0, 0))
Source code in bulletlab/robot/robot.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
reset(position: tuple[float, float, float] | None = None, orientation: tuple[float, float, float, float] | None = None) -> None
Reset the robot to its initial (or specified) pose.
Also resets all joint positions and velocities to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
tuple[float, float, float] | None
|
Target base position. Defaults to initial load position. |
None
|
orientation
|
tuple[float, float, float, float] | None
|
Target base orientation. Defaults to initial load orientation. |
None
|
Example::
robot.reset()
robot.reset(position=(0, 0, 1), orientation=(0, 0, 0, 1))