_api-control:
Control API Reference#
This page documents ManipulaPy.control, the module for manipulator control algorithms.
Note
As of v1.3.2, the control module is GPU-optional / backend-agnostic: it
runs on NumPy by default and accepts CuPy arrays where available. Public type
hints no longer reference cp.ndarray β inputs are coerced to NumPy
internally, so callers can mix backends freely.
Tip
For conceptual explanations, see Control Module User Guide.
β
ManipulatorController Class#
- class ManipulaPy.control.ManipulatorController(dynamics)[source]#
Bases:
objectCPU-based manipulator controller implementations and tuning utilities.
Main class for control of robotic manipulators. Backend-agnostic: works with NumPy or CuPy arrays (CuPy inputs are coerced to NumPy internally as of v1.3.2).
Constructor
- Parameters:
dynamics (Any)
- __init__(dynamics)[source]#
Initialize the ManipulatorController with the dynamics of the manipulator.
Note: Control algorithms now use CPU (NumPy) to avoid GPU-CPU transfer overhead, since the dynamics module operates on NumPy arrays.
- Parameters:
dynamics (ManipulatorDynamics) β An instance of ManipulatorDynamics.
- Return type:
None
Parameters:
dynamics (ManipulatorDynamics) β Instance providing dynamics computations
β
Control Strategies#
Basic Controllers#
- ManipulatorController.pid_control(thetalistd, dthetalistd, thetalist, dthetalist, dt, Kp, Ki, Kd, i_clamp=None)[source]#
PID Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint angles.
dthetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint velocities.
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
dt (float) β Time step.
Kp (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Proportional gain.
Ki (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Integral gain.
Kd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Derivative gain.
i_clamp (float | None)
- Returns:
PID control signal (CPU-based NumPy array).
- Return type:
NDArray
- ManipulatorController.pd_control(desired_position, desired_velocity, current_position, current_velocity, Kp, Kd)[source]#
PD Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
desired_position (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint positions.
desired_velocity (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint velocities.
current_position (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint positions.
current_velocity (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
Kp (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Proportional gain.
Kd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Derivative gain.
- Returns:
PD control signal (CPU-based NumPy array).
- Return type:
NDArray
Advanced Controllers#
- ManipulatorController.computed_torque_control(thetalistd, dthetalistd, ddthetalistd, thetalist, dthetalist, g, dt, Kp, Ki, Kd, i_clamp=None)[source]#
Computed Torque Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead. The dynamics module operates on NumPy arrays, so keeping everything on CPU is more efficient than repeated GPUβCPU transfers.
- Parameters:
thetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint angles.
dthetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint velocities.
ddthetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint accelerations.
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
dt (float) β Time step.
Kp (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Proportional gain.
Ki (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Integral gain.
Kd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Derivative gain.
i_clamp (float | None)
- Returns:
Torque command (CPU-based NumPy array).
- Return type:
NDArray
- ManipulatorController.adaptive_control(thetalist, dthetalist, ddthetalist, g, Ftip, measurement_error, adaptation_gain)[source]#
Adaptive Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
ddthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint accelerations.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
Ftip (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β External forces applied at the end effector.
measurement_error (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Error in measurement.
adaptation_gain (float) β Gain for the adaptation term.
- Returns:
Adaptive control torque (CPU-based NumPy array).
- Return type:
NDArray
- ManipulatorController.robust_control(thetalist, dthetalist, ddthetalist, g, Ftip, disturbance_estimate, adaptation_gain)[source]#
Robust Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
ddthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint accelerations.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
Ftip (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β External forces applied at the end effector.
disturbance_estimate (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Estimate of disturbances.
adaptation_gain (float) β Gain for the adaptation term.
- Returns:
Robust control torque (CPU-based NumPy array).
- Return type:
NDArray
Feedforward Control#
- ManipulatorController.feedforward_control(desired_position, desired_velocity, desired_acceleration, g, Ftip)[source]#
Feedforward Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
desired_position (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint positions.
desired_velocity (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint velocities.
desired_acceleration (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint accelerations.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
Ftip (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β External forces applied at the end effector.
- Returns:
Feedforward torque (CPU-based NumPy array).
- Return type:
NDArray
- ManipulatorController.pd_feedforward_control(desired_position, desired_velocity, desired_acceleration, current_position, current_velocity, Kp, Kd, g, Ftip)[source]#
PD Feedforward Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
desired_position (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint positions.
desired_velocity (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint velocities.
desired_acceleration (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint accelerations.
current_position (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint positions.
current_velocity (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
Kp (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Proportional gain.
Kd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Derivative gain.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
Ftip (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β External forces applied at the end effector.
- Returns:
Control signal (CPU-based NumPy array).
- Return type:
NDArray
Space-Specific Control#
- ManipulatorController.joint_space_control(desired_joint_angles, current_joint_angles, current_joint_velocities, Kp, Kd)[source]#
Joint Space Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
desired_joint_angles (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint angles.
current_joint_angles (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
current_joint_velocities (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
Kp (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Proportional gain.
Kd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Derivative gain.
- Returns:
Control torque (CPU-based NumPy array).
- Return type:
NDArray
- ManipulatorController.cartesian_space_control(desired_position, current_joint_angles, current_joint_velocities, Kp, Kd)[source]#
Cartesian Space Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
desired_position (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired end-effector position.
current_joint_angles (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
current_joint_velocities (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
Kp (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Proportional gain.
Kd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Derivative gain.
- Returns:
Control torque (CPU-based NumPy array).
- Return type:
NDArray
β
State Estimation#
- ManipulatorController.kalman_filter_predict(thetalist, dthetalist, taulist, g, Ftip, dt, Q)[source]#
Kalman Filter Prediction.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
taulist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Applied torques.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
Ftip (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β External forces applied at the end effector.
dt (float) β Time step.
Q (ndarray[tuple[Any, ...], dtype[float64]]) β Process noise covariance.
- Returns:
None
- Return type:
None
- ManipulatorController.kalman_filter_update(z, R)[source]#
Kalman Filter Update.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
- Returns:
None
- Raises:
ValueError β if
kalman_filter_predicthas not been called (self.x_hat is None).ValueError β if
self.PisNoneor does not have shape(n, n)wheren == self.x_hat.shape[0].
- Return type:
None
Changed in version 1.3.2: Both the
x_hatandPpreconditions are now validated up-front and raiseValueErrorwith a descriptive message instead of failing inside the matrix algebra.
- ManipulatorController.kalman_filter_control(thetalistd, dthetalistd, thetalist, dthetalist, taulist, g, Ftip, dt, Q, R)[source]#
Kalman Filter Control.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint angles.
dthetalistd (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Desired joint velocities.
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Current joint velocities.
taulist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Applied torques.
g (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Gravity vector.
Ftip (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β External forces applied at the end effector.
dt (float) β Time step.
Q (ndarray[tuple[Any, ...], dtype[float64]]) β Process noise covariance.
R (ndarray[tuple[Any, ...], dtype[float64]]) β Measurement noise covariance.
- Returns:
Estimated joint angles and velocities (CPU-based NumPy arrays).
- Return type:
β
Performance Analysis Tools#
- ManipulatorController.plot_steady_state_response(time, response, set_point, title='Steady State Response')[source]#
Plot the steady-state response of the controller.
- ManipulatorController.calculate_rise_time(time, response, set_point)[source]#
Calculate the rise time.
- ManipulatorController.calculate_percent_overshoot(response, set_point)[source]#
Calculate the percent overshoot.
- ManipulatorController.calculate_settling_time(time, response, set_point, tolerance=0.02)[source]#
Calculate the settling time.
Returns the first time at which the response enters the tolerance band and never leaves it again. Returns
float('inf')when the response never enters the band, or enters but does not remain settled through the end of the recorded data.- Parameters:
time (np.ndarray) β Array of time steps.
response (np.ndarray) β Array of response values.
set_point (float) β Desired set point value.
tolerance (float) β Fractional tolerance band (default 0.02 = 2 %).
time β Array of time steps.
response β Array of response values.
set_point β Desired set point value (may be negative).
tolerance β Fractional tolerance band (default
0.02= 2 %).
- Returns:
Settling time, or inf if the response never settles.
- Return type:
- Returns:
First time at which the response enters the tolerance band and never leaves it again, or
float('inf')if it never settles.- Return type:
Changed in version 1.3.2: Returns the first time the response enters the settling band and stays there (was returning the last cross). Negative setpoints are now handled correctly.
- ManipulatorController.calculate_steady_state_error(response, set_point)[source]#
Calculate the steady-state error.
β
Auto-Tuning and Limits#
- ManipulatorController.ziegler_nichols_tuning(Ku, Tu, kind='PID')[source]#
Compute Ziegler-Nichols controller gains.
- ManipulatorController.tune_controller(Ku, Tu, kind='PID')[source]#
Convenience wrapper that logs and returns NumPy arrays (length = DOF).
- ManipulatorController.find_ultimate_gain_and_period(thetalist, desired_joint_angles, dt, max_steps=1000)[source]#
Find the ultimate gain and period using the ZieglerβNichols method.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Initial joint angles (shape [6]).
desired_joint_angles (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Step target angles (shape [6]).
dt (float) β Simulation time step.
max_steps (int) β Number of integration steps to try.
- Returns:
ultimate_gain (float)
ultimate_period (float)
gain_history (list of float)
error_history (list of np.ndarray)
- Return type:
- static ManipulatorController.enforce_limits(thetalist, dthetalist, tau, joint_limits, torque_limits)[source]#
Enforce joint and torque limits.
Uses CPU-based computation to avoid GPU-CPU transfer overhead.
- Parameters:
thetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Joint angles.
dthetalist (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Joint velocities.
tau (ndarray[tuple[Any, ...], dtype[float64]] | List[float]) β Torques.
joint_limits (ndarray[tuple[Any, ...], dtype[float64]] | List[Tuple[float, float]]) β Joint angle limits.
torque_limits (ndarray[tuple[Any, ...], dtype[float64]] | List[Tuple[float, float]]) β Torque limits.
- Returns:
Clipped joint angles, velocities, and torques (CPU-based NumPy arrays).
- Return type:
β
See Also#
Dynamics API Reference β Robot dynamics for model-based control
Kinematics API Reference β Kinematic models for Cartesian control
Path Planning API Reference β Trajectory reference generation
Simulation API Reference β Simulator integration and testing tools