Utilities¶
Configuration Parser¶
Unified Configuration Parser for FIGAROH
This module provides a unified configuration parsing system that supports: - Template inheritance and extension - Variant configurations - Variable expansion - Schema validation
ConfigurationError
¶
Bases: FigarohExampleError
Exception raised for configuration-related issues.
ConfigMetadata(schema_version='2.0', config_type='robot_configuration', source_file=None, variant=None, resolved_at=None)
dataclass
¶
Configuration metadata container.
UnifiedConfigParser(config_path, variant=None)
¶
Unified configuration parser supporting inheritance, templates, and validation.
Initialize parser with configuration file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Union[str, Path]
|
Path to configuration file |
required |
variant
|
Optional[str]
|
Optional variant name to use from configuration |
None
|
Source code in src/figaroh/utils/config_parser.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
parse()
¶
Parse configuration with inheritance and validation.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Complete configuration dictionary with metadata |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If parsing or validation fails |
Source code in src/figaroh/utils/config_parser.py
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 | |
create_task_config(robot, unified_config, task_name)
¶
Create task-specific configuration from unified config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot instance |
required | |
unified_config
|
Dict[str, Any]
|
Parsed unified configuration |
required |
task_name
|
str
|
Name of task to extract configuration for |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Task-specific configuration dictionary |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If task not found or invalid |
Source code in src/figaroh/utils/config_parser.py
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 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
parse_configuration(config_path, variant=None)
¶
Convenience function to parse a configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Union[str, Path]
|
Path to configuration file |
required |
variant
|
Optional[str]
|
Optional variant name to apply |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Parsed configuration dictionary |
Source code in src/figaroh/utils/config_parser.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
get_param_from_yaml(robot, config_data, task_type='auto', variant=None)
¶
Unified parameter parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot instance |
required | |
config_data
|
Union[Dict[str, Any], str, Path]
|
Configuration data (dict), or path to config file |
required |
task_type
|
str
|
Type of task configuration to extract ("calibration", "identification", "auto") |
'auto'
|
variant
|
Optional[str]
|
Optional variant to apply |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Task-specific parameter dictionary |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If parsing fails, the task is not found, or the data is a legacy flat config (removed in 1.0) |
Source code in src/figaroh/utils/config_parser.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
legacy_config_error(config_file=None)
¶
Build the error raised when a legacy flat config is loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Optional[Union[str, Path]]
|
Offending file, named in the message when given. |
None
|
Returns:
| Type | Description |
|---|---|
ConfigurationError
|
An error naming the migration CLI. The caller raises it. |
Source code in src/figaroh/utils/config_parser.py
658 659 660 661 662 663 664 665 666 667 668 669 670 | |
require_unified_config(config_file)
¶
Raise unless config_file is an existing unified-format config.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The file does not exist. |
ConfigurationError
|
The file is a legacy flat config (names the migration CLI). |
Source code in src/figaroh/utils/config_parser.py
673 674 675 676 677 678 679 680 681 682 683 684 | |
is_unified_config(config_file)
¶
Check if a configuration file is using the unified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Union[str, Path]
|
Path to configuration file |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if unified format, False if legacy format |
Source code in src/figaroh/utils/config_parser.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
Cubic Spline¶
Cubic Spline Trajectory Generation for Robotics Applications.
This module provides comprehensive tools for generating smooth, continuous trajectories using cubic splines for robotic systems. It supports constraint handling, waypoint generation, and trajectory validation with joint limits.
The module contains two main classes: - CubicSpline: Core trajectory generation with cubic splines - WaypointsGeneration: Automated waypoint generation for trajectory planning
Key Features
- C2 continuous cubic spline trajectories
- Joint position, velocity, and acceleration constraints
- Waypoint-based trajectory planning
- Collision and constraint checking
- Visualization capabilities
- Random and systematic waypoint generation
Dependencies
- ndcurves: Curve generation and manipulation
- numpy: Numerical computations
- matplotlib: Plotting and visualization
- pinocchio: Robot kinematics and dynamics
Examples:
Basic trajectory generation:
from figaroh.utils.cubic_spline import CubicSpline
# Initialize spline generator
spline = CubicSpline(robot, num_waypoints=5,
active_joints=['joint1', 'joint2'])
# Generate trajectory
time_points = np.array([[0], [1], [2], [3], [4]])
waypoints = np.random.rand(2, 5) # 2 joints, 5 waypoints
t, pos, vel, acc = spline.get_full_config(
freq=100, time_points=time_points, waypoints=waypoints
)
# Check constraints
spline.check_cfg_constraints(pos, vel)
Automated waypoint generation:
from figaroh.utils.cubic_spline import WaypointsGeneration
# Initialize waypoint generator
wp_gen = WaypointsGeneration(robot, num_waypoints=5,
active_joints=['joint1', 'joint2'])
# Generate waypoint pool
wp_gen.gen_rand_pool()
# Generate random waypoints
pos_wp, vel_wp, acc_wp = wp_gen.gen_rand_wp()
# Generate trajectory from waypoints
t, pos, vel, acc = wp_gen.get_full_config(
freq=100, time_points=time_points, waypoints=pos_wp
)
References
- Spline theory: "A Practical Guide to Splines" by Carl de Boor
- Robot trajectory planning: "Introduction to Robotics" by John Craig
- ndcurves library: https://github.com/humanoid-path-planner/ndcurves
CubicSpline(robot, num_waypoints, active_joints, soft_lim=0)
¶
Cubic spline trajectory generator for robotic systems.
This class generates smooth, C2-continuous trajectories using cubic splines for robotic systems. It supports both position-only and full kinematic constraint specification (position, velocity, acceleration) at waypoints.
The class handles active joint selection, joint limit constraints, and provides methods for trajectory validation and visualization.
Attributes:
| Name | Type | Description |
|---|---|---|
robot |
Robot model instance |
|
rmodel |
Robot kinematic model |
|
num_waypoints |
int
|
Number of waypoints in trajectory |
act_Jid |
List[int]
|
Active joint IDs |
act_Jname |
List[str]
|
Active joint names |
act_J |
List
|
Active joint objects |
act_idxq |
List[int]
|
Position indices for active joints |
act_idxv |
List[int]
|
Velocity indices for active joints |
dim_q |
Tuple[int, int]
|
Position vector dimensions |
dim_v |
Tuple[int, int]
|
Velocity vector dimensions |
upper_q, |
lower_q (np.ndarray
|
Position limits for active joints |
upper_dq, |
lower_dq (np.ndarray
|
Velocity limits for active joints |
upper_effort, |
lower_effort (np.ndarray
|
Effort limits for active joints |
Examples:
Basic usage:
# Initialize for 2 joints, 5 waypoints
spline = CubicSpline(robot, num_waypoints=5,
active_joints=['joint1', 'joint2'])
# Define waypoints and time stamps
waypoints = np.array([[0, 1, 2, 1, 0], # joint1 positions
[0, 0.5, 1, 0.5, 0]]) # joint2 positions
time_points = np.array([[0], [1], [2], [3], [4]])
# Generate trajectory at 100 Hz
t, pos, vel, acc = spline.get_full_config(
freq=100, time_points=time_points, waypoints=waypoints
)
# Validate constraints
is_violated = spline.check_cfg_constraints(pos, vel)
With velocity and acceleration constraints:
# Define waypoint constraints
vel_waypoints = np.zeros((2, 5)) # Zero velocity at waypoints
acc_waypoints = np.zeros((2, 5)) # Zero acceleration at waypoints
# Generate constrained trajectory
t, pos, vel, acc = spline.get_full_config(
freq=100, time_points=time_points, waypoints=waypoints,
vel_waypoints=vel_waypoints, acc_waypoints=acc_waypoints
)
# Visualize results
spline.plot_spline(t, pos, vel, acc)
Note
The class uses the ndcurves library for cubic spline generation. Joint limits are automatically extracted from the robot model and can be modified with soft limits for safety margins.
Initialize the cubic spline trajectory generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot model instance containing kinematic information |
required | |
num_waypoints
|
int
|
Number of waypoints for the trajectory |
required |
active_joints
|
list
|
List of joint names to include in trajectory |
required |
soft_lim
|
float
|
Soft limit reduction factor (0-1). Reduces joint limits by this fraction for safety. Defaults to 0. |
0
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If joint names are not found in robot model |
Examples:
# Basic initialization
spline = CubicSpline(robot, 5, ['joint1', 'joint2'])
# With 10% safety margin on joint limits
spline = CubicSpline(robot, 5, ['joint1', 'joint2'],
soft_lim=0.1)
Source code in src/figaroh/utils/cubic_spline.py
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 | |
get_active_config(freq, time_points, waypoints, vel_waypoints=None, acc_waypoints=None)
¶
Generate cubic splines on active joints
Source code in src/figaroh/utils/cubic_spline.py
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 | |
get_full_config(freq, time_points, waypoints, vel_waypoints=None, acc_waypoints=None)
¶
Generate complete robot configuration trajectory with cubic splines.
This method creates smooth trajectories for all robot joints by: 1. Generating cubic splines for active joints between waypoints 2. Filling inactive joints with zero values 3. Ensuring C2 continuity at waypoints
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
int
|
Sampling frequency for trajectory generation (Hz) |
required |
time_points
|
ndarray
|
Time stamps for waypoints, shape (num_waypoints, 1) |
required |
waypoints
|
ndarray
|
Position waypoints for active joints, shape (num_active_joints, num_waypoints) |
required |
vel_waypoints
|
ndarray
|
Velocity constraints at waypoints, same shape as waypoints. If provided, enforces specific velocities at waypoints. |
None
|
acc_waypoints
|
ndarray
|
Acceleration constraints at waypoints, same shape as waypoints. If provided, enforces specific accelerations at waypoints. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Four-element tuple containing: - t (np.ndarray): Time stamps, shape (N, 1) - q_full (np.ndarray): Position trajectory for all joints, shape (N, robot_nq) - dq_full (np.ndarray): Velocity trajectory for all joints, shape (N, robot_nv) - ddq_full (np.ndarray): Acceleration trajectory for all joints, shape (N, robot_nv) Where N = int(total_time * freq) + 1 |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If waypoint dimensions don't match active joints |
Examples:
Position-only trajectory:
time_pts = np.array([[0], [1], [2], [3]])
waypts = np.array([[0, 1, 2, 1], # joint1
[0, 0.5, 1, 0.5]]) # joint2
t, q, dq, ddq = spline.get_full_config(
freq=100, time_points=time_pts, waypoints=waypts
)
With velocity/acceleration constraints:
vel_waypts = np.zeros((2, 4)) # Zero velocity at waypoints
acc_waypts = np.zeros((2, 4)) # Zero acceleration at waypoints
t, q, dq, ddq = spline.get_full_config(
freq=100, time_points=time_pts, waypoints=waypts,
vel_waypoints=vel_waypts, acc_waypoints=acc_waypts
)
Note
The trajectory uses piecewise cubic curves connected at waypoints. When velocity and acceleration constraints are provided, the resulting trajectory enforces exact values at waypoints.
Source code in src/figaroh/utils/cubic_spline.py
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 | |
check_cfg_constraints(q, v=None, tau=None, soft_lim=0)
¶
Check joint constraints violation for trajectory configurations.
Validates whether the generated trajectory respects robot joint limits including position, velocity, and effort constraints. Provides detailed violation reporting for debugging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
ndarray
|
Position trajectory to check, shape (N, robot_nq) |
required |
v
|
ndarray
|
Velocity trajectory to check, shape (N, robot_nv). If None, velocity checks are skipped. |
None
|
tau
|
ndarray
|
Effort trajectory to check, shape (N, robot_nv). If None, effort checks are skipped. |
None
|
soft_lim
|
float
|
Additional safety margin factor (0-1). Adds this fraction of joint range as safety buffer. Defaults to 0. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if any constraint is violated, False if all constraints are satisfied |
Examples:
Basic position check:
t, q, dq, ddq = spline.get_full_config(...)
is_violated = spline.check_cfg_constraints(q)
if is_violated:
print("Trajectory violates position limits!")
Full constraint check with safety margin:
is_violated = spline.check_cfg_constraints(
q, v=dq, tau=torques, soft_lim=0.1
)
Note
Constraint violations are logged at DEBUG level with specific joint indices and violation types; callers report the outcome.
Source code in src/figaroh/utils/cubic_spline.py
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 | |
WaypointsGeneration(robot, num_waypoints, active_joints, soft_lim=0)
¶
Bases: CubicSpline
Automated waypoint generation for cubic spline trajectories.
This class extends CubicSpline to provide automated generation of feasible waypoints that respect robot joint constraints. It creates pools of valid configurations and uses random sampling to generate diverse trajectory waypoints.
The class generates waypoints for position, velocity, and acceleration that can be used as initial guesses for trajectory optimization or as standalone feasible trajectories.
Attributes:
| Name | Type | Description |
|---|---|---|
n_set |
int
|
Size of waypoint pools (default: 10) |
pool_q |
ndarray
|
Pool of valid position configurations |
pool_dq |
ndarray
|
Pool of valid velocity configurations |
pool_ddq |
ndarray
|
Pool of valid acceleration configurations |
soft_limit_pool_default |
ndarray
|
Default soft limit values |
Examples:
Basic waypoint generation:
wp_gen = WaypointsGeneration(robot, num_waypoints=5,
active_joints=['joint1', 'joint2'])
# Generate random feasible waypoints
pos_wp, vel_wp, acc_wp = wp_gen.random_feasible_waypoints()
# Use with cubic spline
time_pts = np.linspace(0, 4, 5).reshape(-1, 1)
t, q, dq, ddq = wp_gen.get_full_config(
freq=100, time_points=time_pts, waypoints=pos_wp.T,
vel_waypoints=vel_wp.T, acc_waypoints=acc_wp.T
)
With custom soft limits:
# Different safety margins for position/velocity/acceleration
soft_lim_custom = np.array([
[0.1, 0.15], # Position limits (10%, 15% for joints)
[0.2, 0.2], # Velocity limits (20% for both joints)
[0.3, 0.25] # Acceleration limits (30%, 25%)
])
wp_gen.set_soft_limit_pool(soft_lim_custom)
pos_wp, vel_wp, acc_wp = wp_gen.random_feasible_waypoints()
Note
The class automatically ensures waypoints don't violate joint constraints and avoids repeated waypoint values that could cause numerical issues in spline generation.
Initialize waypoint generation for cubic spline trajectories.
Sets up pools for generating random feasible waypoints that respect robot joint constraints. Initializes configuration pools for positions, velocities, and accelerations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Robot model instance containing kinematic information |
required | |
num_waypoints
|
int
|
Number of waypoints for trajectory generation |
required |
active_joints
|
list
|
List of joint names to include in trajectory |
required |
soft_lim
|
float
|
Soft limit reduction factor (0-1). Defaults to 0. |
0
|
Note
The soft_lim parameter affects the base CubicSpline initialization but does not set the waypoint generation pools. Use set_soft_limit_pool() for custom pool limits.
Source code in src/figaroh/utils/cubic_spline.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
gen_rand_pool(soft_limit_pool=None)
¶
Generate a uniformly distributed waypoint pool of pos/vel/acc over a specific range
Source code in src/figaroh/utils/cubic_spline.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
gen_rand_wp(wp_init=None, vel_wp_init=None, acc_wp_init=None, vel_set_zero=True, acc_set_zero=True)
¶
Generate waypoint pos/vel/acc which randomly pick from waypoint pool Or, set vel and/or acc at waypoints to be zero
Source code in src/figaroh/utils/cubic_spline.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 | |
gen_equal_wp(wp_init=None, vel_wp_init=None, acc_wp_init=None)
¶
Generate equal waypoints everywhere same as first waypoints with default: zero vel and zero acc
Source code in src/figaroh/utils/cubic_spline.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
Results Manager¶
Shared fallback-plotting helper and the joint-major torque-plotting fix used
by both calibration and identification (plot_with_fallback,
plot_calibration_results, plot_identification_results).
Unified results management for FIGAROH examples.
This module provides standardized plotting and saving functionality across all task types: Calibration, Identification, OptimalCalibration, OptimalTrajectory.
ResultsManager(task_type, robot_name='robot', results_data=None)
¶
Unified results management for all FIGAROH task types.
This class provides standardized plotting and saving functionality with consistent styling and formats across different analysis types.
Initialize results manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_type
|
str
|
Type of task ('calibration', 'identification', 'optimal_calibration', 'optimal_trajectory') |
required |
robot_name
|
str
|
Name of the robot for file naming |
'robot'
|
results_data
|
Optional[Dict[str, Any]]
|
Optional dictionary of results data |
None
|
Source code in src/figaroh/utils/results_manager.py
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 | |
plot_calibration_results(measured_poses=None, estimated_poses=None, residuals=None, parameter_values=None, parameter_names=None, outlier_indices=None, title='Calibration Results')
¶
Plot calibration results with pose comparison and residual analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measured_poses
|
Optional[ndarray]
|
Measured poses (optional, uses self.result) |
None
|
estimated_poses
|
Optional[ndarray]
|
Estimated poses (optional, uses self.result) |
None
|
residuals
|
Optional[ndarray]
|
Position/orientation residuals (optional, uses self.result) |
None
|
parameter_values
|
Optional[ndarray]
|
Calibrated parameters (optional, uses self.result) |
None
|
parameter_names
|
Optional[List[str]]
|
Parameter names (optional, uses self.result) |
None
|
outlier_indices
|
Optional[List[int]]
|
Outlier indices (optional, uses self.result) |
None
|
title
|
str
|
Plot title |
'Calibration Results'
|
Source code in src/figaroh/utils/results_manager.py
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 | |
plot_identification_results(tau_measured=None, tau_identified=None, parameter_values=None, parameter_names=None, time_vector=None, joint_names=None, n_joints=None, title='Identification Results')
¶
Plot identification results with torque comparison and analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tau_measured
|
Optional[ndarray]
|
Measured joint torques (optional, uses self.result) |
None
|
tau_identified
|
Optional[ndarray]
|
Estimated torques (optional, uses self.result) |
None
|
parameter_values
|
Optional[ndarray]
|
Parameter values (optional, uses self.result) |
None
|
parameter_names
|
Optional[List[str]]
|
Parameter names (optional, uses self.result) |
None
|
time_vector
|
Optional[ndarray]
|
Time vector for plots |
None
|
joint_names
|
Optional[List[str]]
|
Names of robot joints |
None
|
n_joints
|
Optional[int]
|
Number of active joints. Required when a torque array is 1D, since a flattened array is joint-major (all samples of joint 0, then joint 1, ...) and cannot be reshaped correctly without knowing the joint count. |
None
|
title
|
str
|
Plot title |
'Identification Results'
|
Source code in src/figaroh/utils/results_manager.py
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 | |
plot_optimal_calibration_results(configurations, weights, condition_numbers=None, information_matrix=None, title='Optimal Calibration Results')
¶
Plot optimal calibration configuration results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configurations
|
Dict[str, ndarray]
|
Dictionary of configuration data |
required |
weights
|
ndarray
|
Weights assigned to each configuration |
required |
condition_numbers
|
Optional[ndarray]
|
Condition numbers for analysis |
None
|
information_matrix
|
Optional[ndarray]
|
Fisher information matrix |
None
|
title
|
str
|
Plot title |
'Optimal Calibration Results'
|
Source code in src/figaroh/utils/results_manager.py
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 | |
plot_optimal_trajectory_results(trajectories, condition_number, joint_names=None, title='Optimal Trajectory Results', q_indices=None, v_indices=None)
¶
Plot optimal trajectory generation results.
Positions span the model's nq coordinates and velocities and
accelerations its nv coordinates, which differ for continuous,
spherical or free-flyer joints. Pass q_indices and v_indices
(e.g. each plotted joint's idx_q and idx_v) to plot those
joints; without them every column is plotted, which requires
nq == nv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Dict[str, Any]
|
Dictionary containing trajectory data |
required |
condition_number
|
float
|
Final condition number achieved |
required |
joint_names
|
Optional[List[str]]
|
Names of the plotted joints, used as row labels |
None
|
title
|
str
|
Plot title |
'Optimal Trajectory Results'
|
q_indices
|
Optional[List[int]]
|
Position column of each plotted joint |
None
|
v_indices
|
Optional[List[int]]
|
Velocity/acceleration column of each plotted joint |
None
|
Source code in src/figaroh/utils/results_manager.py
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 | |
save_results(results=None, output_dir='results', file_prefix=None, save_formats=['yaml', 'csv'])
¶
Save results to files with standardized format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Optional[Dict[str, Any]]
|
Dictionary containing results to save (uses self.result if None) |
None
|
output_dir
|
str
|
Output directory path |
'results'
|
file_prefix
|
Optional[str]
|
Prefix for output files (default: robot_name_task_type) |
None
|
save_formats
|
List[str]
|
List of formats to save ('yaml', 'csv', 'json', 'npz') |
['yaml', 'csv']
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary mapping format to file path |
Source code in src/figaroh/utils/results_manager.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
plot_with_fallback(primary, fallback, logger, context)
¶
Run primary(); on any exception, log it and run fallback().
Shared by every Base*.plot_results() method, each of which
previously duplicated this same try/except pattern around a call into
:class:ResultsManager with a raw-matplotlib fallback.
Source code in src/figaroh/utils/results_manager.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
plot_calibration_results(measured_poses, estimated_poses, residuals, **kwargs)
¶
Plot calibration results (convenience function).
Source code in src/figaroh/utils/results_manager.py
890 891 892 893 894 895 896 897 898 899 900 | |
plot_identification_results(tau_measured, tau_identified, parameters, **kwargs)
¶
Plot identification results (convenience function).
Source code in src/figaroh/utils/results_manager.py
903 904 905 906 907 908 909 910 911 912 913 | |
save_results(results, task_type, output_dir='results', **kwargs)
¶
Save results (convenience function).
Source code in src/figaroh/utils/results_manager.py
916 917 918 919 920 921 922 923 924 | |
Error Handling¶
Custom exceptions and error handling for FIGAROH examples.
This module provides standardized error handling and validation utilities for robot identification and calibration workflows.
FigarohExampleError
¶
Bases: Exception
Base exception for FIGAROH examples.
RobotInitializationError
¶
Bases: FigarohExampleError
Exception raised when robot initialization fails.
ConfigurationError
¶
Bases: FigarohExampleError
Exception raised for configuration-related issues.
DataProcessingError
¶
Bases: FigarohExampleError
Exception raised during data processing operations.
CalibrationError
¶
Bases: FigarohExampleError
Exception raised during calibration procedures.
IdentificationError
¶
Bases: FigarohExampleError
Exception raised during identification procedures.
ValidationError
¶
Bases: FigarohExampleError
Exception raised when validation fails.
ErrorContext(operation_name, raise_on_error=True)
¶
Context manager for structured error handling.
Source code in src/figaroh/utils/error_handling.py
350 351 352 353 | |
validate_robot_config(config)
¶
Validate robot configuration dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary to validate |
required |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If configuration is invalid |
Source code in src/figaroh/utils/error_handling.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
validate_trajectory_data(q, qd=None, qdd=None, tau=None)
¶
Validate trajectory data arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
ndarray
|
Joint positions |
required |
qd
|
Optional[ndarray]
|
Joint velocities (optional) |
None
|
qdd
|
Optional[ndarray]
|
Joint accelerations (optional) |
None
|
tau
|
Optional[ndarray]
|
Joint torques (optional) |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If data is invalid |
Source code in src/figaroh/utils/error_handling.py
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 | |
validate_numeric_range(value, min_val=None, max_val=None, name='value')
¶
Validate that numeric value(s) are within specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[float, int, ndarray]
|
Value or array to validate |
required |
min_val
|
Optional[float]
|
Minimum allowed value |
None
|
max_val
|
Optional[float]
|
Maximum allowed value |
None
|
name
|
str
|
Name of the value for error messages |
'value'
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If value is out of range |
Source code in src/figaroh/utils/error_handling.py
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 | |
validate_robot_initialization(func)
¶
Decorator to validate robot initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
F
|
Function to decorate |
required |
Returns:
| Type | Description |
|---|---|
F
|
Decorated function with robot validation |
Source code in src/figaroh/utils/error_handling.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
validate_input_data(func)
¶
Decorator to validate input data for processing functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
F
|
Function to decorate |
required |
Returns:
| Type | Description |
|---|---|
F
|
Decorated function with input validation |
Source code in src/figaroh/utils/error_handling.py
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 | |
handle_calibration_errors(func)
¶
Decorator to handle calibration-specific errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
F
|
Function to decorate |
required |
Returns:
| Type | Description |
|---|---|
F
|
Decorated function with calibration error handling |
Source code in src/figaroh/utils/error_handling.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
handle_identification_errors(func)
¶
Decorator to handle identification-specific errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
F
|
Function to decorate |
required |
Returns:
| Type | Description |
|---|---|
F
|
Decorated function with identification error handling |
Source code in src/figaroh/utils/error_handling.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
safe_execute(func, *args, **kwargs)
¶
Safely execute a function and return (success, result_or_error).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
F
|
Function to execute |
required |
*args
|
Positional arguments for the function |
()
|
|
**kwargs
|
Keyword arguments for the function |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (success_flag, result_or_exception) |
Source code in src/figaroh/utils/error_handling.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
setup_example_logging(log_level='INFO', log_file=None)
¶
Setup logging for FIGAROH examples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_level
|
str
|
Logging level (DEBUG, INFO, WARNING, ERROR) |
'INFO'
|
log_file
|
Optional[str]
|
Optional log file path |
None
|
Returns:
| Type | Description |
|---|---|
Logger
|
Configured logger instance |
Source code in src/figaroh/utils/error_handling.py
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 | |
Config Migration¶
Converts a legacy flat (calibration:/identification:) config to the
unified extends:/tasks: format, including an optional round-trip
self-check against a URDF. See "Migrating from legacy to unified format"
in Config Parameters.
Legacy -> unified config migration.
Converts a legacy flat calibration:/identification: config into the
unified extends:/tasks: format, using the exact field mapping
documented in docs/source/concepts/config_parameters.md. This is the
reverse of :func:figaroh.calibration.config.unified_to_legacy_config and
:func:figaroh.identification.config.unified_to_legacy_identif_config.
Fields with no unified-format consumer today (is_static_regressor,
is_inertia_regressor, embedded_forces, sync_joint_motion, and the
parsed-but-unused joint limit / ratio_essential fields — see
config_parameters.md) are preserved under the custom: section rather than
silently dropped.
CLI usage::
python -m figaroh.utils.config_migration \
--input legacy_config.yaml --output unified_config.yaml \
[--task auto|calibration|identification] \
[--template base|manipulator|humanoid] \
[--urdf robot.urdf] # enables the round-trip self-check
legacy_calibration_to_unified(calib_data)
¶
Convert a legacy calibration: section to unified tasks.calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calib_data
|
Dict[str, Any]
|
The dict under the |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A |
Dict[str, Any]
|
with the identification fragment and an |
Source code in src/figaroh/utils/config_migration.py
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 | |
legacy_identification_to_unified(identif_data)
¶
Convert a legacy identification: section to unified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identif_data
|
Dict[str, Any]
|
The dict under the |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A ``{"robot": {"properties": {...}}, "tasks": {"identification": |
Dict[str, Any]
|
{...}}, "custom": {...}} |
Dict[str, Any]
|
fields shared across tasks (mechanics, joints); |
Dict[str, Any]
|
fields with no current unified-format consumer. |
Source code in src/figaroh/utils/config_migration.py
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 | |
merge_unified_sections(*docs)
¶
Merge fragments produced by legacy_*_to_unified into one document.
A legacy file commonly has both calibration: and identification:
sections; each converts independently and the results are merged here.
Source code in src/figaroh/utils/config_migration.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
convert_legacy_to_unified(legacy_config, template='base')
¶
Convert a full legacy config dict (both sections, if present).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legacy_config
|
Dict[str, Any]
|
The parsed legacy YAML (top-level dict with
|
required |
template
|
str
|
Which template to |
'base'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A complete unified-format config dict, ready to |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
Source code in src/figaroh/utils/config_migration.py
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 | |
self_check(robot, legacy_config, unified_doc)
¶
Round-trip unified_doc back through the real unified parser and
diff the recovered calib_config/identif_config against the
original legacy sections.
This reuses the exact same code path production uses
(create_task_config + unified_to_legacy_*config) rather than
reimplementing the flattening logic, so it can't silently diverge from
what the pipeline actually does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
A robot instance with |
required | |
legacy_config
|
Dict[str, Any]
|
The original parsed legacy YAML. |
required |
unified_doc
|
Dict[str, Any]
|
The output of :func: |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
``{"ok": bool, "mismatches": {" |
Dict[str, Any]
|
..., "got": ...}}}`` |
Source code in src/figaroh/utils/config_migration.py
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 | |