Field guide
Robot Joint Angle Wrap: Preserve Motion and Turn Count
Distinguish wrapped joint angles from multi-turn position, avoid false velocity spikes, and run an offline unwrapping example that rejects ambiguous sample gaps.
The short answer
Establish whether a joint signal means orientation modulo one revolution or accumulated position before subtracting samples. A wrap-aware difference can remove a false spike, but it cannot prove how many turns occurred between observations.
A log might change from 179 degrees to minus 179 degrees while the physical axis advances only two degrees. Ordinary subtraction reports minus 358 degrees. Conversely, an axis can make a complete revolution and return the same wrapped value. Replacing subtraction with a shortest-angle function addresses the first representation problem, not the second information loss.
This guide provides an offline Python demonstration and a signal-review worksheet. We reviewed the linked first-party definitions on November 26, 2026 and executed the exact standalone calculation below. We did not run ROS, read an encoder, change a controller or move a robot. Every motion example is hypothetical.
Separate orientation from accumulated position
There are three different quantities to preserve:
| Quantity | What it tells you | What it leaves unresolved |
|---|---|---|
| Wrapped angle | Orientation within a chosen one-turn interval | Completed revolutions |
| Accumulated position | Position relative to a declared multi-turn reference | Whether that reference survived a restart or reset |
| Reconstructed position | A path inferred from samples and assumptions | Motions the sampling and assumptions cannot distinguish |
The ROS angles implementation explicitly normalizes angles into a one-turn range. Its shortest_angular_distance(from, to) normalizes to - from and returns a difference between minus pi and pi. Adding that difference reaches an equivalent orientation, not necessarily the same accumulated coordinate.
Do not infer the representation from a graph that happens to stay within one revolution. Ask the driver or signal owner whether it wraps, which interval it uses, where zero originates, and what a power cycle does. A field named position is not a complete answer.
The pinned Jazzy JointState definition specifies radians for rotational position and radians per second for rotational velocity. It identifies joints by name and says the header time is when the states were recorded. It does not provide a separate revolution-count or wrap-mode field. Those semantics must come from the producer’s contract.
Check names, units and time before repairing a spike
Use this proposed diagnostic order:
- Match each position to its joint name in the same message. Do not assume a fixed array index across different producers or records. The message definition requires arrays to have equal sizes or be empty, enabling that association.
- Confirm units at every conversion. REP 103 uses radians for angles. This article displays degrees only to make the examples readable.
- Use acquisition timestamps, with their clock domain identified, rather than silently differentiating against message-arrival time. See the separate sensor timing and clock-domain guide.
- Mark gaps, duplicate or decreasing timestamps, restarts, homing and position resets. Do not unwrap across a discontinuity merely because a plotting library can connect it.
- Confirm whether the signal is measured feedback, simulated state or a command-derived estimate. Agreement with a command is not independent movement evidence.
A wrap crossing is one candidate explanation for a spike. Wrong units, a changed name mapping, a reset or bad timestamps need different corrections. Keep the original samples so a visually smoother plot does not conceal the actual defect.
When shortest-step unwrapping is justified
For a rotational signal known to wrap, a common reconstruction adds the shortest circular difference between successive samples. That chooses the path with magnitude below half a revolution.
Our conservative screening rule is to require an independently justified bound on absolute angular speed throughout each interval, not merely a velocity value sampled at its endpoint. If that bound multiplied by the actual sample gap reaches pi radians, this method refuses to reconstruct the interval. When the bound is strictly below pi, two possible displacements separated by a full revolution cannot both satisfy it.
This is a mathematical sufficient condition for the idealized example, not a ROS requirement, hardware rating or safety rule. Measurement noise and uncertainty need additional margin and checks. An exact half-turn is direction-ambiguous. Even a small shortest difference is insufficient when the speed bound or gap is unknown.
A configured velocity limit is not automatically evidence that a real axis respected it throughout a recording. Establish the bound’s provenance separately. Nor can this procedure recover the initial turn count: the reconstructed sequence starts from the first observed representative.
Run the offline counterexamples
The following Python 3 example uses invented data and sends no commands. Its half-open normalization interval is [-pi, pi). At exactly pi it chooses minus pi, unlike the reviewed ROS implementation’s endpoint convention. The reconstruction rejects half-turn ambiguity rather than relying on that tie choice.
from math import pi, radians, degrees, isclose
def wrap(angle):
return (angle + pi) % (2 * pi) - pi
def reconstruct(samples, speed_bound):
# samples: (acquisition time in seconds, wrapped angle in radians)
if not samples or speed_bound <= 0:
raise ValueError("samples and a positive bound required")
result = [samples[0][1]]
for (t0, q0), (t1, q1) in zip(samples, samples[1:]):
dt = t1 - t0
if dt <= 0:
raise ValueError("timestamps must increase")
if speed_bound * dt >= pi:
raise ValueError("ambiguous gap: half-turn bound reached")
step = wrap(q1 - q0)
if abs(step) > speed_bound * dt + 1e-12:
raise ValueError("samples contradict the stated speed bound")
result.append(result[-1] + step)
return result
samples = [(0.0, radians(179)), (0.1, radians(-179))]
raw = samples[1][1] - samples[0][1]
path = reconstruct(samples, radians(30))
step = path[1] - path[0]
assert isclose(degrees(step), 2.0)
print(f"raw difference: {degrees(raw):.1f} deg")
print(f"reconstructed difference: {degrees(step):.1f} deg")
print(f"interval-average velocity: {degrees(step) / 0.1:.1f} deg/s")
# Two different physical histories can have the same wrapped endpoints.
assert isclose(wrap(0.0), wrap(2 * pi))
print("0 and 360 deg have identical wrapped endpoints")
try:
reconstruct([(0.0, 0.0), (1.0, 0.0)], radians(400))
except ValueError as error:
print(f"long-gap result: {error}")
else:
raise AssertionError("ambiguous gap was not rejected")
Our execution produced:
raw difference: -358.0 deg
reconstructed difference: 2.0 deg
interval-average velocity: 20.0 deg/s
0 and 360 deg have identical wrapped endpoints
long-gap result: ambiguous gap: half-turn bound reached
The first interval is reconstructable under the stated idealized speed bound. Its reported velocity is an interval average, not an instantaneous peak measurement. The second example deliberately permits enough movement for a hidden revolution, so the procedure returns no reconstructed result.
This small teaching function is not a production data validator. It assumes finite, correctly typed samples, known signal semantics and an appropriate bound. It does not model encoder noise, calibration error, missed events, sign changes in gearing or reference resets. Do not copy it into an actuator command path.
Do not erase bounded travel or intentional turns
Suppose an accumulated target is one revolution beyond the current position. Their normalized orientations match, but their coordinates do not. Comparing only normalized values could label the turn complete before it happened.
Likewise, the shortest direction between two orientations may cross a joint’s forbidden interval. A mathematically equivalent endpoint does not authorize that path. The reviewed angles source provides separate limit-aware functions, including one for large limits, with explicit validity conditions. Their existence is not proof that your controller calls them or that a supplied limit matches the hardware.
Keep joint model, drive feedback, controller error convention and target representation consistent. Do not normalize a bounded or multi-turn coordinate solely to make an error plot smaller. Our trajectory execution guide covers the separate issue of resolving the controller’s actual tolerances and terminal result.
The same distinction matters in wheel odometry calibration: a wrapped final orientation cannot stand in for accumulated wheel rotation or total body rotation. Correct geometry cannot restore revolutions that the recorded representation discarded.
A joint-signal handoff worksheet
Keep this proposed review record with the original recording. Physical observations remain NOT TESTED until the responsible team provides them.
Joint name, model, driver and controller versions:
Signal source: measured / simulated / command-derived / unknown:
Units, sign, gearing and joint-to-encoder conversion:
Representation: wrapped interval / accumulated / unknown:
Zero reference, initial turn count and evidence:
Reset, homing, restart and power-cycle behavior:
Acquisition clock, timestamp origin and actual sample gaps:
Message name-to-array mapping and absent-field handling:
Speed bound across each interval, provenance and uncertainty:
Noise margin, contradictory samples and ambiguous gaps:
Reconstruction method, initial anchor and excluded intervals:
Target and controller error conventions, limit handling:
Independent movement evidence and retained original samples:
Disposition: representation understood / unresolved / rejected:
Store both raw and derived traces with the method and assumptions. Use the incident-recording guide for the broader evidence bundle. A clean plot is useful presentation, not proof of a completed turn, accurate tracking or safe physical motion.
Sources and evidence boundaries
- ROS angles at revision
a96224f. Commit dated September 23, 2025, reviewed November 26, 2026. Supports normalization, shortest angular difference, endpoint convention and separate limit-aware functions. This is a source review, not execution of that C++ library or a controller. - ROS 2 Jazzy
JointStateat revisiona941f14. Commit dated June 8, 2026, reviewed November 26. Supports units, joint-name association, optional arrays and acquisition-time semantics. The definition does not establish the behavior of a particular driver. - REP 103 at revision
11ca24a. Informational REP created October 7, 2010, reviewed November 26, 2026. Supports standard ROS angle units and documented convention exceptions.
The reconstruction rule, Python example, hypothetical observations, diagnostic order and worksheet are Physical AI Guide’s synthesis. Only the displayed offline calculation was executed. No encoder, controller, trajectory or physical safety performance was validated.
Frequently asked questions
Does a jump from 179 degrees to minus 179 degrees mean the joint moved backwards almost a full turn?
Not necessarily. Those orientations are two degrees apart across a wrap boundary, but the samples alone do not establish the physical path. Check signal semantics, timestamps, resets and a justified bound on movement between samples.
Can shortest angular distance recover a joint's turn count?
No. It gives a shortest orientation difference modulo a full revolution. Recovering relative travel from wrapped samples requires additional assumptions. The initial revolution count still needs an independent reference.
Should I normalize every robot joint position before comparing it with a target?
No. If the application distinguishes revolutions or a joint has bounded travel, normalization can erase meaningful position or limit information. Use the model and controller's documented coordinate semantics.