Chapter 15: Safety, Standards, and Ethics
Lesson 6: Responsible Robotics Case Studies
This lesson examines real-world patterns of failure and responsibility in robotics systems, and shows how to formalize “responsible robotics” with mathematical risk models, safety constraints, and supervisory architectures. We connect industrial and service-robot case studies to control-theoretic notions such as safe sets and invariance, and illustrate how simple runtime safety monitors can be implemented in Python, C++, Java, and MATLAB/Simulink.
1. Responsible Robotics – Concepts and Formal View
Responsible robotics is an engineering and ethical stance that requires that robotic systems be designed, deployed, and monitored in a way that systematically reduces harm, respects human values, and provides clear accountability when failures occur.
We can make this notion more precise by starting from a simple dynamical representation of a robot (students are assumed to know basic linear control):
\[ \dot{\mathbf{x}}(t) = \mathbf{A}\,\mathbf{x}(t) + \mathbf{B}\,\mathbf{u}(t), \qquad \mathbf{x}(t)\in\mathbb{R}^n,\; \mathbf{u}(t)\in\mathbb{R}^m. \]
We distinguish three ingredients:
- A safe set \( \mathcal{S} \subset \mathbb{R}^n \) of “acceptable” states (e.g., distances, joint angles, speeds).
- A hazard set \( \mathcal{H} \subset \mathbb{R}^n \), typically the complement of \( \mathcal{S} \) or a subset of it, such as states where a human is likely to be harmed.
- A policy (controller) \( \mathbf{u}(t) = \mathbf{K}\,\mathbf{x}(t) \) or more generally \( \mathbf{u}(t) = \pi(\mathbf{x}(t)) \).
A minimal responsibility requirement is forward invariance of the safe set:
\[ \mathbf{x}(0)\in\mathcal{S} \quad \Longrightarrow \quad \mathbf{x}(t)\in\mathcal{S}\;\;\forall t \ge 0. \]
In practice, uncertainties, modeling errors, and software bugs violate this ideal. Responsible design therefore layers:
- preventive design (controllers that tend to stay safe),
- monitoring (detect deviations from assumptions), and
- fallback behaviors (e.g., safe stop, emergency shut-down).
flowchart TD
RQ["Requirements (safety, ethics, accountability)"]
--> M["Model robot and environment (linear control + bounds)"]
M --> C["Design nominal controller"]
C --> A1["Analyze invariance of safe set S"]
A1 --> MON["Add independent safety monitor"]
MON --> FB["Specify fallback behaviors (e_stop, slow_mode)"]
FB --> VAL["Test and validate with worst_case scenarios"]
VAL --> GOV["Document responsibilities and traceability"]
2. Quantitative Risk and Expected Harm
Many safety standards for robots (industrial and collaborative) formalize risk as a combination of probability and severity of harm. A simple model over discrete time steps \( k = 0,1,\dots,N-1 \) is:
\[ R = \mathbb{E}\!\left[ \sum_{k=0}^{N-1} L(\mathbf{x}_k, \mathbf{u}_k) \right], \]
where \( L(\mathbf{x}_k, \mathbf{u}_k) \) is a loss (cost) function that encodes:
- severity of a possible impact (e.g., kinetic energy near a person),
- vulnerability of the human (age, posture, proximity),
- frequency of exposure (how often the scenario occurs).
For a single hazard type with probability \( p(\mathbf{x}_k,\mathbf{u}_k) \) at step \( k \) and constant severity \( s > 0 \), we might approximate:
\[ L(\mathbf{x}_k,\mathbf{u}_k) \approx s \, p(\mathbf{x}_k,\mathbf{u}_k), \qquad R \approx s \sum_{k=0}^{N-1} p(\mathbf{x}_k,\mathbf{u}_k). \]
Responsibility requires that:
- We make the assumptions explicit (how \( p(\mathbf{x}_k,\mathbf{u}_k) \) is estimated).
- We keep a margin between “designed risk” and thresholds in safety standards.
- We provide ways to monitor whether the realized behavior violates the assumed risk model.
3. Safe Sets and a Simple Invariance Proof
Consider a 1D point-mass robot moving along a line toward a human at position \( x=0 \). Let \( x(t) \) denote the distance from the human, so that \( x(t) > 0 \) is safe and \( x(t) \le 0 \) is a collision.
We model the dynamics as
\[ \dot{x}(t) = u(t), \qquad |u(t)| \le u_{\max}, \]
which corresponds to a simple integrator (position is the integral of velocity command).
Define the safe set \( \mathcal{S} = \{ x \in \mathbb{R} \mid x \ge d_{\min} \} \), where \( d_{\min} > 0 \) is a design parameter that encodes the minimum distance allowed by the standard.
A basic invariance condition is: if we are on the boundary (worst case), \( x = d_{\min} \), the derivative must not point “out of” the safe set. In other words,
\[ x(t) = d_{\min} \;\Longrightarrow\; \dot{x}(t) \ge 0, \]
because \( x < d_{\min} \) would be unsafe. For our system \( \dot{x}(t) = u(t) \), this becomes the simple constraint \( u(t) \ge 0 \) whenever \( x(t) = d_{\min} \).
Proposition (simple invariance). Suppose the control policy satisfies:
- \( u(t) \ge 0 \) whenever \( x(t) = d_{\min} \),
- \( x(0) \ge d_{\min} \).
Then \( x(t) \ge d_{\min} \) for all \( t \ge 0 \).
Sketch of proof. Suppose for contradiction that there exists
\[ t^\star \ge 0 \quad\text{such that}\quad x(t^\star) < d_{\min}. \]
By continuity of \( x(t) \) (solutions of \( \dot{x}=u \) with bounded \( u \) are continuous), there exists the first time \( \bar{t} \) such that \( x(\bar{t}) = d_{\min} \). At that time, by assumption, \( \dot{x}(\bar{t}) \ge 0 \), so the trajectory cannot cross the boundary into \( x < d_{\min} \). This contradicts the existence of \( t^\star \). Hence, the safe set is forward invariant.
Responsible robotics uses this kind of reasoning (often generalized to higher dimensions) to prove that certain constraints can never be violated, under model assumptions. Case studies show what happens when these assumptions are wrong or not fully implemented in code.
4. Case Study 1 – Collaborative Manipulator and Safe Stopping Distance
Consider a collaborative robot (cobot) arm moving a payload near a human coworker. One critical scenario is when the human unexpectedly enters the robot’s workspace. A common control-level safety requirement is that the robot must be able to stop before entering a “no-go” distance \( d_{\text{ng}} \) around the human.
Assume 1D motion along the line toward the human, with:
- current distance between robot tool center point (TCP) and human: \( d \),
- current speed toward the human: \( v \ge 0 \),
- maximal braking deceleration: \( a_{\max} > 0 \),
- reaction delay of the controller and actuators: \( T_r > 0 \).
During the reaction delay \( T_r \), the robot continues at speed \( v \), so it travels \( d_r = v T_r \). Then it brakes with constant deceleration \( a_{\max} \) until it stops. The braking distance \( d_b \) is obtained from the kinematic equation \( v^2 = 2 a_{\max} d_b \), so
\[ d_b = \frac{v^2}{2 a_{\max}}. \]
The total stopping distance is then \( d_{\text{stop}} = d_r + d_b = v T_r + \dfrac{v^2}{2 a_{\max}} \). Safety requires
\[ d_{\text{stop}} \le d - d_{\text{ng}}, \]
or equivalently, a constraint on the current speed:
\[ v T_r + \frac{v^2}{2 a_{\max}} \le d - d_{\text{ng}}. \]
This inequality defines a speed–distance safety envelope. A responsible cobot implementation continuously monitors \( d \) and \( v \) and enforces this constraint (e.g., by limiting velocity commands or triggering an emergency stop).
Many industrial accidents can be traced to violations of some implicit or explicit inequality of this form, often due to:
- underestimating \( T_r \) (software or sensor delays),
- overestimating \( a_{\max} \) (actuator or friction limitations),
- assuming the human will not enter certain regions (faulty exposure model).
A responsible design documents these assumptions, tests worst-case values, and includes margins to account for uncertainty.
5. Case Study 2 – Mobile Robot and Perception Failures
A mobile robot (e.g., warehouse cart) navigates among humans using a perception system that classifies obstacles and predicts motion. Suppose that at each cycle the perception module either correctly detects a nearby human or misses them (false negative).
Let \( H_k \) be a Bernoulli random variable indicating “human is present in the danger zone” at time step \( k \), and \( D_k \) indicate “perception system detects the human”. Define:
- \( p_h = \mathbb{P}[H_k = 1] \): probability a human is in the danger zone,
- \( p_{\text{fn}} = \mathbb{P}[D_k = 0 \mid H_k = 1] \): false negative rate of the detector,
- impact severity \( s > 0 \).
The per-step expected harm due to missed detections is
\[ L_k = s \, \mathbb{P}\big[\text{impact at step }k\big] \approx s \, \mathbb{P}[H_k = 1, D_k = 0] = s \, p_h \, p_{\text{fn}}. \]
Over \( N \) steps, we obtain the expected harm
\[ R \approx N \, s \, p_h \, p_{\text{fn}}. \]
Responsibility here includes:
- designing the robot policy so that even when detection fails, the default behavior is conservative (slow speeds near uncertain regions);
- measuring and reducing \( p_{\text{fn}} \) for all subpopulations (e.g., people with different clothing or mobility aids) to avoid systematic bias;
- monitoring detection statistics during deployment and triggering updates or shutdowns when they deviate from validated values.
Note that this is not only a software issue; it is a system-level responsibility that couples perception design, control policies, and operational procedures.
6. Safety Supervisors and Runtime Monitors (Conceptual Architecture)
A widely used architectural pattern for responsible robotics is the independent safety supervisor. A nominal controller proposes commands, and a separate module monitors whether executing them would break safety constraints. If so, the supervisor overrides or shuts down the system.
The state machine below illustrates a simple pattern:
stateDiagram-v2
[*] --> SAFE
SAFE --> WARNING: near_constraint
WARNING --> SAFE: back_to_safe
WARNING --> EMERGENCY_STOP: violation_imminent
SAFE --> EMERGENCY_STOP: hardware_fault
EMERGENCY_STOP --> [*]: reset_and_recover
Implementing such a supervisor is largely a software engineering task, but its correctness depends on the mathematical safety envelopes (like the stopping distance inequality) and clear assumptions about sensors and actuators.
7. Python Example – Speed–Distance Safety Monitor
The following Python code implements a simple speed–distance safety
checker based on the stopping-distance inequality. It could be
integrated into a ROS2 node (via
rclpy) that subscribes to robot state and publishes a
“safety stop” command. Here we focus on the core logic.
import math
from dataclasses import dataclass
@dataclass
class SafetyEnvelope1D:
reaction_time: float # T_r
max_decel: float # a_max > 0
no_go_distance: float # d_ng safety radius around human
margin: float = 0.05 # extra margin [m]
def stopping_distance(self, v: float) -> float:
"""
Compute d_stop = v*T_r + v^2/(2*a_max).
Assumes v >= 0 and a_max > 0.
"""
return v * self.reaction_time + v * v / (2.0 * self.max_decel)
def is_safe(self, distance: float, v: float) -> bool:
"""
Return True if current state (distance, v) is within the safety envelope.
distance: current distance from human [m]
v: speed toward the human [m/s]
"""
if v < 0.0:
# Moving away from the human is always safe w.r.t this constraint.
return True
d_available = max(distance - self.no_go_distance - self.margin, 0.0)
d_required = self.stopping_distance(v)
return d_required <= d_available
# Example usage:
if __name__ == "__main__":
env = SafetyEnvelope1D(reaction_time=0.2, max_decel=3.0, no_go_distance=0.4)
distance = 1.0 # meters
v = 0.8 # m/s
if env.is_safe(distance, v):
print("Command accepted: within safety envelope.")
else:
print("Safety stop: requested speed is unsafe.")
In a ROS2 setup, this logic would be called from a callback that
receives current pose and velocity (for example from a
/joint_states or base odometry topic), and it would publish
an override to a topic such as /safety_stop. The same
envelope can be used offline to document and justify that the robot
satisfies a given safety standard, given validated values for reaction
time and deceleration.
Python libraries often used in such analyses include
numpy for vectorized computations and
python-control for modeling the underlying linear dynamics
that determine achievable braking performance.
8. C++ Example – Safety Wrapper Around Velocity Commands
In C++, the same safety envelope can be wrapped around velocity
commands, and plugged into a robotics middleware such as ROS2 via
rclcpp. We implement a small safety class; integration with
ROS2 publishers/subscribers is left as an exercise.
#include <iostream>
#include <cmath>
class SafetyEnvelope1D {
public:
SafetyEnvelope1D(double reaction_time,
double max_decel,
double no_go_distance,
double margin = 0.05)
: Tr_(reaction_time),
amax_(max_decel),
dng_(no_go_distance),
margin_(margin) {}
double stopping_distance(double v) const {
// d_stop = v*Tr + v^2/(2*a_max)
return v * Tr_ + (v * v) / (2.0 * amax_);
}
bool is_safe(double distance, double v) const {
if (v < 0.0) {
return true; // moving away
}
double d_available = distance - dng_ - margin_;
if (d_available < 0.0) d_available = 0.0;
double d_required = stopping_distance(v);
return d_required <= d_available;
}
private:
double Tr_, amax_, dng_, margin_;
};
int main() {
SafetyEnvelope1D env(0.2, 3.0, 0.4);
double distance = 1.0;
double v = 0.8;
if (env.is_safe(distance, v)) {
std::cout << "Command accepted (C++)." << std::endl;
} else {
std::cout << "Safety stop (C++)." << std::endl;
}
return 0;
}
In a ROS2-based system, one would typically encapsulate this in a node
deriving from
rclcpp::Node, subscribing to state topics and republishing
filtered velocity commands. Modern C++ robotics frameworks like ROS2 and
Orocos provide real-time primitives and standardized interfaces to
ensure that safety logic can execute deterministically.
9. Java Example – Safety Filter for Mobile Base
Java is used in several robotics contexts (e.g., ROS Java bindings, WPILib for educational robots). Below is a minimalist Java version of the safety envelope, which could be used in a periodic control loop for a mobile base:
public final class SafetyEnvelope1D {
private final double Tr;
private final double amax;
private final double dng;
private final double margin;
public SafetyEnvelope1D(double reactionTime,
double maxDecel,
double noGoDistance,
double margin) {
this.Tr = reactionTime;
this.amax = maxDecel;
this.dng = noGoDistance;
this.margin = margin;
}
public double stoppingDistance(double v) {
// d_stop = v*Tr + v^2/(2*a_max)
return v * Tr + (v * v) / (2.0 * amax);
}
public boolean isSafe(double distance, double v) {
if (v < 0.0) {
return true; // moving away
}
double dAvailable = distance - dng - margin;
if (dAvailable < 0.0) {
dAvailable = 0.0;
}
double dRequired = stoppingDistance(v);
return dRequired <= dAvailable;
}
public static void main(String[] args) {
SafetyEnvelope1D env = new SafetyEnvelope1D(0.2, 3.0, 0.4, 0.05);
double distance = 1.0;
double v = 0.8;
if (env.isSafe(distance, v)) {
System.out.println("Command accepted (Java).");
} else {
System.out.println("Safety stop (Java).");
}
}
}
In frameworks such as WPILib, similar safety checks are inserted into drivetrain commands to ensure that joystick inputs cannot drive the robot into unsafe states. A responsible robotics practice includes unit tests that verify the safety filter for a range of distances and velocities.
10. MATLAB/Simulink – Modeling a Safety Supervisor
MATLAB with Simulink and Robotics System Toolbox is well suited to prototyping safety supervisors at the block-diagram level. Below is an m-file function implementing the same safety envelope and a comment describing a corresponding Simulink model.
function [safe, d_required, d_available] = safetyEnvelope1D(distance, v, Tr, amax, dng, margin)
% safetyEnvelope1D Speed-distance safety envelope check.
% distance - current distance to human [m]
% v - speed toward the human [m/s]
% Tr - reaction time [s]
% amax - max braking deceleration [m/s^2]
% dng - no-go distance [m]
% margin - extra safety margin [m]
if nargin < 6
margin = 0.05;
end
if v < 0
% Moving away from the human w.r.t. this constraint.
safe = true;
d_required = 0;
d_available = inf;
return;
end
% d_stop = v*Tr + v^2/(2*a_max)
d_required = v * Tr + v.^2 / (2 * amax);
d_available = max(distance - dng - margin, 0);
safe = (d_required <= d_available);
end
In Simulink, a typical responsible robotics model would:
- take distance and speed as inputs from sensor/estimation blocks,
- implement the above computation using Sum, Gain, and MATLAB Function blocks,
- drive a Stateflow chart that realizes the state machine (“SAFE”, “WARNING”, “EMERGENCY_STOP”),
- output a “safety override” signal that forces the plant input to zero when unsafe.
Simulink’s capability to co-simulate plant and controller allows engineers to run worst-case scenarios systematically before deployment, which is central to responsible robotics practice.
11. Problems and Solutions
Problem 1 (Stopping Distance Envelope). A mobile robot travels at speed \( v \) toward a human. Its controller has a reaction time \( T_r \) and can command a maximal braking deceleration \( a_{\max} \). Derive the formula for the minimal separation distance \( d_{\min}(v) \) such that the robot can always stop before entering a no-go radius \( d_{\text{ng}} \). Assume 1D motion and constant deceleration.
Solution.
During reaction time the robot moves with constant speed \( v \), so it travels \( d_r = v T_r \). Afterwards, it brakes with constant deceleration \( a_{\max} \) until its speed reaches zero. From kinematics, \( v^2 = 2 a_{\max} d_b \), so the braking distance is \( d_b = \dfrac{v^2}{2 a_{\max}} \). The total stopping distance is
\[ d_{\text{stop}}(v) = d_r + d_b = v T_r + \frac{v^2}{2 a_{\max}}. \]
To avoid entering the no-go radius \( d_{\text{ng}} \), the current separation \( d \) must satisfy \( d_{\text{stop}}(v) \le d - d_{\text{ng}} \). Therefore, the minimal safe separation as a function of speed is
\[ d_{\min}(v) = d_{\text{ng}} + v T_r + \frac{v^2}{2 a_{\max}}. \]
Problem 2 (Invariance of a Symmetric Safe Interval). Consider the 1D system \( \dot{x} = -k x \), with constant \( k > 0 \). Let the safe set be \( \mathcal{S} = \{ x \mid |x| \le x_{\max} \} \). Show that \( \mathcal{S} \) is invariant, i.e., if \( |x(0)| \le x_{\max} \) then \( |x(t)| \le x_{\max} \) for all \( t \ge 0 \).
Solution.
The closed-form solution of \( \dot{x} = -k x \) with initial condition \( x(0) = x_0 \) is \( x(t) = x_0 e^{-k t} \). Taking absolute values,
\[ |x(t)| = |x_0| e^{-k t}. \]
Since \( e^{-k t} \le 1 \) for all \( t \ge 0 \), we have \( |x(t)| \le |x_0| \). If \( |x_0| \le x_{\max} \), then \( |x(t)| \le x_{\max} \) for all \( t \ge 0 \). Thus \( \mathcal{S} \) is invariant under this linear feedback. This illustrates how exponential stability often supports safety: the state is driven inward, not outward.
Problem 3 (Expected Harm for Perception Failures). In the perception case study, suppose the probability that a human is in the danger zone at each step is \( p_h = 0.02 \), the false negative rate is \( p_{\text{fn}} = 0.1 \), and the severity \( s = 1000 \) (arbitrary units). Compute the expected harm \( R \) over \( N = 10^4 \) steps.
Solution.
The per-step expected harm is \( L_k = s p_h p_{\text{fn}} \). Therefore,
\[ L_k = 1000 \times 0.02 \times 0.1 = 1000 \times 0.002 = 2. \]
Over \( N = 10^4 \) steps, the expected harm is \( R = N L_k = 10^4 \times 2 = 2\times 10^4 \) (in the chosen units). A responsible designer would evaluate whether this value is acceptable under domain standards, and if not, reduce \( p_{\text{fn}} \) or \( p_h \) (e.g., by redesigning routes) or both.
Problem 4 (Designing a Safety Supervisor Logic).
Suppose a robot is considered in SAFE state when the envelope
checker reports safe = true. When it reports
false, the robot should enter EMERGENCY_STOP. After
an emergency stop, it can only return to SAFE when an operator
sends a reset command and the envelope is safe
again. Describe, in words or pseudocode, the state update rule for this
supervisor.
Solution.
Let the supervisor state be \( q_k \in \{\text{SAFE}, \text{EMERGENCY\_STOP}\} \) and define \( s_k \) as the boolean safety flag at step \( k \), and \( r_k \) as the boolean reset command. The update rule is:
- If \( q_k = \text{SAFE} \) and \( s_k = \text{true} \), then \( q_{k+1} = \text{SAFE} \).
- If \( q_k = \text{SAFE} \) and \( s_k = \text{false} \), then \( q_{k+1} = \text{EMERGENCY\_STOP} \).
- If \( q_k = \text{EMERGENCY\_STOP} \) and \( r_k = \text{true} \) and \( s_k = \text{true} \), then \( q_{k+1} = \text{SAFE} \).
- Otherwise (still in emergency or reset while unsafe), \( q_{k+1} = \text{EMERGENCY\_STOP} \).
This supervisor logic is deterministic and encodes a simple but important responsibility principle: once an emergency stop occurs, an explicit human action and restored safety are needed before the robot can move again.
12. Summary
In this lesson, we connected the abstract idea of “responsible robotics” to mathematical notions of risk, safe sets, and invariance. We derived classic stopping-distance envelopes for collaborative robots and quantified expected harm under perception failures. We then showed how safety supervisors implement these constraints in software, using simple examples in Python, C++, Java, and MATLAB/Simulink. The case studies highlight that responsibility is not only about correct control design but also about explicit assumptions, monitoring, and clear recovery procedures when things go wrong.
13. References
- Alpern, B., & Schneider, F. B. (1987). Recognizing safety and liveness. Distributed Computing, 2(3), 117–126.
- Clarke, E. M., Grumberg, O., & Peled, D. (1999). Model Checking. MIT Press.
- Leitmann, G. (1994). On the efficiency of nonlinear control in systems with uncertain dynamics. Automatica, 30(1), 157–163.
- Prajna, S., Jadbabaie, A., & Pappas, G. J. (2004). A framework for worst-case and stochastic safety verification using barrier certificates. IEEE Transactions on Automatic Control, 52(8), 1415–1428.
- Ames, A. D., Coogan, S., Egerstedt, M., Notomista, G., Sreenath, K., & Tabuada, P. (2019). Control barrier functions: Theory and applications. European Journal of Control, 45, 1–15.
- Leveson, N. G. (2012). Engineering a Safer World: Systems Thinking Applied to Safety. MIT Press.
- Dennis, L., Fisher, M., Slavkovik, M., & Webster, M. (2016). Formal verification of ethical choices in autonomous systems. Robotics and Autonomous Systems, 77, 1–14.
- Winfield, A. F. T., & Jirotka, M. (2018). Ethical governance is essential to building trust in robotics and artificial intelligence systems. Philosophical Transactions of the Royal Society A, 376(2133), 20180085.
- Bringsjord, S., Arkoudas, K., & Bello, P. (2006). Toward a general logicist methodology for engineering ethically correct robots. IEEE Intelligent Systems, 21(4), 38–44.
- Dwork, C., Hardt, M., Pitassi, T., Reingold, O., & Zemel, R. (2012). Fairness through awareness. Proceedings of the 3rd Innovations in Theoretical Computer Science Conference, 214–226.