armchaos 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
armchaos-0.3.1/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: armchaos
3
+ Version: 0.3.1
4
+ Summary: Break a ros2_control arm on purpose (frozen, late, noisy, NaN or spoofed joint states, a deactivated controller) and restore it.
5
+ Home-page: https://github.com/darshmenon/armchaos
6
+ Maintainer: darshmenon
7
+ Maintainer-email: darshmenon02@gmail.com
8
+ License: Apache-2.0
9
+ Requires-Python: >=3.9
10
+ License-File: LICENSE
11
+ Requires-Dist: setuptools
12
+ Requires-Dist: pyyaml
13
+ Dynamic: home-page
14
+ Dynamic: license
15
+ Dynamic: license-file
16
+ Dynamic: maintainer
17
+ Dynamic: maintainer-email
18
+ Dynamic: requires-dist
19
+ Dynamic: requires-python
20
+ Dynamic: summary
@@ -0,0 +1,151 @@
1
+ # armchaos
2
+
3
+ [![CI](https://github.com/darshmenon/armchaos/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/darshmenon/armchaos/actions/workflows/ci.yml) [![Release](https://img.shields.io/github/v/release/darshmenon/armchaos)](https://github.com/darshmenon/armchaos/releases) [![License](https://img.shields.io/badge/license-Apache--2.0-green)](LICENSE) ![ROS 2](https://img.shields.io/badge/ROS_2-Humble-blue)
4
+
5
+ **Does your arm stack notice when something breaks?** Break a ros2_control arm on purpose (frozen, late, noisy, NaN or spoofed joint states, a deactivated controller), then restore it. Pair it with [armdoc](https://github.com/darshmenon/armdoc) to check the doctor names each fault.
6
+
7
+ ![UR5e in MuJoCo: armchaos faults on the joint-state stream, armdoc's verdict underneath](docs/demo_ur5e_faults.gif)
8
+
9
+ *A real UR5e model (MuJoCo Menagerie) moves through a loop. The five faults reshape the joint-state stream with the real armchaos fault models; the arm drawn is the arm as the stack sees it, and the bar underneath is what the real armdoc checks say. Simulated time, no ROS: `PYTHONPATH=.:../armdoc python3 examples/make_demo_gif.py`. A model, not a real robot.*
10
+
11
+ All four tools in one run (armchaos faults, armdoc names each one, trajlens scores the damage, forcetrace reads the squeezed joint's effort as a force proxy), no ROS: `PYTHONPATH=.:../armdoc:../trajlens:../forcetrace python3 examples/pipeline_demo.py`.
12
+
13
+ Part of [ros2-doctor-tools](https://github.com/darshmenon/ros2-doctor-tools), an index of my ROS 2 diagnosis, fault injection and evaluation tools.
14
+
15
+ ## Quick start
16
+
17
+ ```bash
18
+ # install (ROS 2 Humble sourced; C++ package also built in CI on Jazzy and Lyrical; use --system-site-packages if you use a venv)
19
+ pip install git+https://github.com/darshmenon/armchaos # or: colcon build --packages-select armchaos
20
+
21
+ armchaos list # the faults and their parameters
22
+ armchaos inject freeze --for 8 --dry-run # show the plan, touch nothing
23
+ armchaos inject freeze --for 8 # joint_states stop for 8 s (point your stack at /joint_states_chaos)
24
+ ```
25
+
26
+ A pip install puts the `armchaos` command on your PATH; run it directly. The `ros2 run` form below needs the colcon build.
27
+
28
+ Try it without a robot, from a clone of this repo (a fake arm and controller manager, plus armdoc on `PYTHONPATH`):
29
+
30
+ ```bash
31
+ python3 test/fake_cm.py & # publishes /joint_states_raw, serves list/switch_controller
32
+ armchaos run test/scenario_expect.yaml --armdoc --source /joint_states_raw
33
+ ```
34
+
35
+ The last command ends with a pass/fail table and exits non-zero if an expected armdoc code did not fire, so it works as a CI test:
36
+
37
+ ```
38
+ # fault when expect armdoc said result
39
+ - ------------------------------------- --------- --------------------------------- --------------------------------- ------
40
+ 1 freeze t=2s +6s JOINT_STATES_STALE JOINT_STATES_STALE PASS
41
+ 2 nan(joint=j1) t=12s +5s JOINT_NAN JOINT_NAN PASS
42
+ 3 deactivate(controller=arm_controller) t=21s +7s CTRL_INACTIVE, NO_ACTIVE_ARM_CTRL CTRL_INACTIVE, NO_ACTIVE_ARM_CTRL PASS
43
+ 4 noise(sigma=0.02, seed=0) t=32s +5s - nothing -
44
+ ```
45
+
46
+ (Real output against armdoc 0.2.0 and `test/fake_cm.py`: `docs/e2e_expect.txt`.)
47
+
48
+ ## Commands
49
+
50
+ ```bash
51
+ ros2 run armchaos armchaos list # faults and their parameters
52
+ ros2 run armchaos armchaos inject freeze --for 8 # joint_states stop for 8 s
53
+ ros2 run armchaos armchaos inject spoof joint=shoulder_pan_joint offset=7 --at 5 --for 6
54
+ ros2 run armchaos armchaos inject deactivate controller=arm_controller --for 10
55
+ ros2 run armchaos armchaos run scenario.yaml --events out.jsonl # several faults on a timeline
56
+ ros2 run armchaos armchaos inject nan --dry-run # show the plan, touch nothing
57
+ ```
58
+
59
+
60
+ ```yaml
61
+ # scenario.yaml: each fault starts at `at` seconds and lasts `for` seconds
62
+ faults:
63
+ - {at: 4, for: 8, fault: freeze, expect: JOINT_STATES_STALE}
64
+ - {at: 20, for: 8, fault: spoof, joint: shoulder_pan_joint, offset: 7.0, expect: LIMIT_POS}
65
+ - {at: 40, for: 10, fault: deactivate, controller: arm_controller, expect: [CTRL_INACTIVE, NO_ACTIVE_ARM_CTRL]}
66
+ ```
67
+
68
+ ### Checking armdoc: `--armdoc` and `expect:`
69
+
70
+ `expect:` names the armdoc codes that must appear while a fault is active: one code, a list (all of them must appear), or `none` (armdoc must stay quiet). A step without `expect:` is only reported, not judged.
71
+
72
+ With `--armdoc`, armchaos starts armdoc (it must be importable: installed, or on `PYTHONPATH`) on the faulted stream, waits `--armdoc-lead` seconds (default 4) so armdoc sees a healthy baseline, then runs the scenario and compares each step's window, plus 1.5 s after it ends, with the codes armdoc printed. It runs armdoc live for the whole run (one report per second), not once per step, so that short and intermittent faults are not missed. `inject` takes `--expect CODE` (repeatable) the same way. Without `--armdoc`, `expect:` is ignored and armchaos says so.
73
+
74
+ Exit codes: `0` ok, `1` an `expect:` failed, `2` bad usage or a scenario longer than `--max-duration`, `3` a controller could not be restored, `130` / `143` stopped by Ctrl-C / SIGTERM.
75
+
76
+ ## Safety
77
+
78
+ - **Controllers are always put back.** If a run stops early (Ctrl-C, SIGTERM, an error, or the guard below), armchaos reactivates every controller it switched off, blocking with retries, and exits `3` if it cannot (it prints which controller to switch on by hand). `--no-restore-on-exit` leaves them off instead. A fault that ends normally always reactivates its controller.
79
+ - **Nothing runs forever.** `--max-duration SECONDS` (default 600) refuses a scenario that is longer, and also stops the relay if the run overshoots it, restoring controllers first.
80
+ - Stream faults never touch the real `/joint_states`; only `deactivate` changes the running system.
81
+
82
+ ## How it works
83
+
84
+ Stream faults: armchaos subscribes to `--source` (default `/joint_states`), passes each sample through the active faults, and publishes the result on `--out` (default `/joint_states_chaos`). **The real `/joint_states` is never touched**, so point the thing under test at `--out` (a topic remap is enough), or move your real source to another topic and relay it back onto `/joint_states`.
85
+
86
+ Controller fault: `deactivate` calls `controller_manager/switch_controller` on the real controller manager and reactivates the controller when the fault ends (and on Ctrl-C or SIGTERM, see Safety). Unlike the stream faults this one does change the running system.
87
+
88
+ ## Faults, and what armdoc said
89
+
90
+ Real runs, one fault at a time with 6 s of recovery in between, `armdoc` live with a 1 s report period. "+2.2s" is how long after the fault started the first report named it. Raw output: `docs/e2e_*.txt` and `.json`.
91
+
92
+ | Fault | What it does | armdoc code | Fake arm | UR3 in Gazebo |
93
+ |---|---|---|---|---|
94
+ | `freeze` | joint_states stop | `JOINT_STATES_STALE` | +2.2 s | +2.2 s |
95
+ | `slow hz=0.2` | one sample every 5 s | `JOINT_STATES_STALE` | +3.0 s | +2.3 s |
96
+ | `stutter up=1 down=4` | 1 s on, 4 s silent, repeating | `JOINT_STATES_STALE` | +3.8 s | +3.4 s |
97
+ | `lag delay=3` | every sample 3 s late | `JOINT_STATES_STALE` | +2.4 s | +2.5 s |
98
+ | `noise sigma=0.02` | Gaussian noise on positions | **none** (armdoc has no noise check) | none | none |
99
+ | `nan` | one joint position is NaN | `JOINT_NAN` | +0.7 s | +0.5 s |
100
+ | `spoof offset=...` | one joint shifted past its limit | `LIMIT_POS` | +0.8 s | +0.5 s |
101
+ | `squeeze effort=100` | one joint reports effort above its limit | `EFFORT_SAT` | +2.9 s | +2.5 s |
102
+ | `spike velocity=10` | one joint reports a velocity above its limit | `LIMIT_VEL` | +0.0 s | +0.5 s |
103
+ | `deactivate` | arm controller switched off | `CTRL_INACTIVE`, `NO_ACTIVE_ARM_CTRL` | +2.0 s | +1.6 s |
104
+
105
+ Every fault was followed by an `OK` report within 6 s of it ending, on both setups.
106
+
107
+ Two honest notes on those rows:
108
+ - `lag` is reported as stale, not as late: the first `delay` seconds are silent, and after that the stream flows normally, only shifted. armdoc has no check for a constant delay.
109
+ - `noise` is a real gap in armdoc, not a bug in armchaos. Small position noise does not break a limit, so nothing fires.
110
+
111
+ ## C++ relay (low overhead)
112
+
113
+ `armchaos_cpp` is a sibling colcon package with the same stream faults in C++, so the relay itself adds little CPU and memory next to a fast controller:
114
+
115
+ ```bash
116
+ colcon build --packages-select armchaos_cpp && source install/setup.bash
117
+ ros2 run armchaos_cpp armchaos_fast --ros-args -p "faults:=['2,6,freeze','10,5,spoof,joint=shoulder_pan_joint,offset=7']"
118
+ ```
119
+
120
+ Each fault is `"at,for,name[,key=value...]"` with the same parameters and defaults as the Python tool; other parameters are `source` (default `/joint_states`, like the Python tool; use `-p source:=/joint_states_raw` for the fake arm), `out` (default `/joint_states_chaos`), `lead`, `linger` and `max_duration` (hard guard). `deactivate,controller=NAME` works too (parameter `controller_manager`, default `/controller_manager`): the relay switches the controller off, back on when the fault ends, and restores it on Ctrl-C, SIGTERM and the `max_duration` guard (exit 130 / 143, or 3 if it could not restore), checked by `test/cpp_restore_check.py` against `fake_cm.py`. Run the binary directly if you need signals to reach it (`ros2 run` is a wrapper). On a 500 Hz stream (one 15 s run each, busy machine) the C++ relay used 4.6% of a core and 22 MB, the Python relay 18.2% and 60 MB, with median latency 235 us against 326 us (the latency includes a Python publisher and subscriber, so read the CPU and memory gap, not the latency gap). A test replays the same event sequences through both and requires identical output.
121
+
122
+ ## What was and wasn't tested
123
+
124
+ - **Fake arm** (`test/fake_arm_raw.py`, armdoc's fake graph on a remapped topic): all nine stream faults. `deactivate` ran against `test/fake_cm.py`, a small stateful fake controller manager, because the fake arm's controller list is fixed.
125
+ - **UR3 in Gazebo Harmonic** (ros2_control, `arm_controller` + `joint_state_broadcaster`, peg tool, no MoveIt): all nine stream faults plus `deactivate` on the real controller manager. The sim reported `arm_controller` active again after the run.
126
+ - Armdoc was pointed at the faulted stream with a ROS remap (`test/armdoc_remap.py`); the sim's real `/joint_states` stayed untouched.
127
+ - Unit tests (`pytest test`) cover the fault models and the scheduler without ROS.
128
+ - **Safety (0.2.0):** `test/restore_check.py` runs against `test/fake_cm.py`, a fake controller manager, and checks five cases: SIGINT and SIGTERM restore the controller and exit 130 / 143, the `--max-duration` guard stops a run and restores, `--no-restore-on-exit` leaves it off, and a normal run restores. All five pass. This was not run against the real `ros2_control` controller manager (a Gazebo run was out of scope), so the switching is only verified against the fake one.
129
+ - **`--armdoc` summary (0.2.0):** run on the fake graph with armdoc v0.2.0: three expectations passed. With a newer armdoc that has a noise check, a step with `expect: none` failed as it should (exit 1). `pip install .` was tested in a clean venv and `colcon build` still works.
130
+ - **Two arms that are not URs, on the real ros2_control controller manager** (Humble, mock hardware from `moveit_resources_*_moveit_config`, started headless with `test/fanuc_headless.launch.py` and `test/panda_headless.launch.py`): **FANUC** (6 joints, `fanuc_controller`; `test/scenario_fanuc.yaml`, output `docs/e2e_fanuc_ros2_control.txt`) and **Franka Panda** (7 joints, `panda_arm_controller` plus a separate gripper controller; `test/scenario_panda.yaml`, output `docs/e2e_panda_ros2_control.txt`). Every fault was named by the expected armdoc code on both (10 of 10), and the arm controller was active again afterwards. Differences worth knowing: the Fanuc URDF has effort limit 0 and the mock hardware reports no effort, so `squeeze` is expected to go unnoticed there (the scenario says `expect: none`); the Panda has effort limits, so `squeeze` raises `EFFORT_SAT`. Mock hardware, not a real arm.
131
+ - **ROS 2 Jazzy (docker `ros:jazzy-ros-base`):** the `armchaos_cpp` package builds, its 26 equivalence tests pass, and the C++ relay applies a freeze on the fake controller manager; armdoc and `armdoc_cpp` agree on the fake arm there too. Only the C++ packages and the fake graph were run on Jazzy, not the Python relay against a Jazzy simulator.
132
+ - **Not tested:** MoveIt, a real robot, two arms at once, a Jazzy simulator, the new Jazzy CI jobs (only their commands, in docker).
133
+
134
+ ## Reproduce
135
+
136
+ For a ros2_control stack without a simulator: `ros2 launch test/panda_headless.launch.py` (needs `ros-humble-moveit-resources-panda-moveit-config`), then `armchaos run test/scenario_panda.yaml --armdoc --source /joint_states`. If the controller manager says it cannot find the `mock_components` library, run the launch from a clean shell with only `/opt/ros/humble/setup.bash` sourced: stale entries in `AMENT_PREFIX_PATH` from old workspaces broke the plugin lookup here.
137
+
138
+ ```bash
139
+ python3 test/fake_arm_raw.py & # or a simulator publishing /joint_states_raw
140
+ python3 test/e2e.py test/scenario_stream.yaml --source /joint_states_raw
141
+ ```
142
+
143
+ `test/e2e.py` starts armchaos and a remapped armdoc, then prints the fault-to-code table above (for pass/fail checks use `armchaos run ... --armdoc` instead). For a simulator, use `--source /joint_states` and `test/scenario_gazebo.yaml` (UR3 joint names).
144
+
145
+ ## Limits
146
+
147
+ - Verified against `armdoc` on a UR3 and a UR5e in Gazebo (all ten faults, `docs/e2e_ur5e_gazebo.txt` for the UR5e run) and on a fake arm. No real robot and no non-UR arm yet.
148
+ - Joint-state faults only, plus one controller fault. No TF, camera or force-sensor faults yet.
149
+ - Stream faults apply to the relayed topic, so they need a remap in the stack under test.
150
+ - YAML reads `on`, `off`, `yes` and `no` as booleans, so `stutter` uses `up` and `down`; a boolean key gets a clear error.
151
+ - Needs `controller_manager_msgs` and PyYAML.
@@ -0,0 +1,2 @@
1
+ """armchaos: break a ros2_control arm on purpose, then restore it."""
2
+ __version__ = "0.3.1"
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env python3
2
+ """armchaos: break a ros2_control arm on purpose, then restore it.
3
+
4
+ Exit codes: 0 ok, 1 an `expect:` check failed, 2 bad usage, 3 a controller could not be restored,
5
+ 130/143 stopped by Ctrl-C / SIGTERM (controllers are restored first)."""
6
+ import argparse
7
+ import sys
8
+
9
+ from armchaos import __version__
10
+ from armchaos.faults import FAULTS, make_fault
11
+ from armchaos.probe import ArmdocWatcher
12
+ from armchaos.report import build_results, exit_code, format_table
13
+ from armchaos.scenario import Step, over_budget, parse_expect, parse_scenario
14
+
15
+
16
+ def _kv(items):
17
+ out = {}
18
+ for it in items:
19
+ if "=" not in it:
20
+ raise ValueError(f"parameter {it!r} must look like key=value")
21
+ k, v = it.split("=", 1)
22
+ try:
23
+ out[k] = float(v)
24
+ except ValueError:
25
+ out[k] = v
26
+ return out
27
+
28
+
29
+ def build_parser():
30
+ ap = argparse.ArgumentParser(prog="armchaos", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
31
+ ap.add_argument("--version", action="version", version=f"armchaos {__version__}")
32
+ sub = ap.add_subparsers(dest="cmd", required=True)
33
+ sub.add_parser("list", help="list the faults and their parameters")
34
+ for name in ("run", "inject"):
35
+ p = sub.add_parser(name, help="run a scenario file" if name == "run" else "apply one fault")
36
+ if name == "run":
37
+ p.add_argument("scenario")
38
+ else:
39
+ p.add_argument("fault", choices=sorted(FAULTS))
40
+ p.add_argument("params", nargs="*", help="fault parameters as key=value (see `armchaos list`)")
41
+ p.add_argument("--at", type=float, default=2.0, help="seconds before the fault starts")
42
+ p.add_argument("--for", dest="dur", type=float, default=8.0, help="seconds the fault lasts")
43
+ p.add_argument("--expect", action="append", metavar="CODE",
44
+ help="armdoc code that must fire (repeat for several, or `none`); needs --armdoc")
45
+ p.add_argument("--source", default="/joint_states", help="real joint states to relay")
46
+ p.add_argument("--out", default="/joint_states_chaos", help="topic the faulted stream is published on")
47
+ p.add_argument("--cm", default="/controller_manager")
48
+ p.add_argument("--events", help="write start/stop events here as JSON lines")
49
+ p.add_argument("--dry-run", action="store_true", help="print the plan, touch nothing")
50
+ p.add_argument("--armdoc", action="store_true",
51
+ help="run armdoc on the faulted stream and check each step's `expect:` codes")
52
+ p.add_argument("--armdoc-lead", type=float, default=4.0,
53
+ help="healthy seconds before the first fault, so armdoc sees a good baseline (with --armdoc)")
54
+ p.add_argument("--max-duration", type=float, default=600.0, metavar="SECONDS",
55
+ help="hard limit for the whole run; a longer scenario is refused (default 600)")
56
+ p.add_argument("--restore-on-exit", action=argparse.BooleanOptionalAction, default=True,
57
+ help="on Ctrl-C, SIGTERM or the --max-duration guard, switch deactivated controllers "
58
+ "back on (default on)")
59
+ return ap
60
+
61
+
62
+ def main(argv=None):
63
+ a = build_parser().parse_args(argv)
64
+ if a.cmd == "list":
65
+ for n, c in sorted(FAULTS.items()):
66
+ d = ", ".join(f"{k}={v}" for k, v in c().defaults().items())
67
+ print(f"{n:11} {c.help}\n{'':11} params: {d or '-'}")
68
+ return 0
69
+ try:
70
+ if a.cmd == "run":
71
+ import yaml
72
+ with open(a.scenario) as f:
73
+ steps = parse_scenario(yaml.safe_load(f))
74
+ else:
75
+ steps = [Step(a.at, a.dur, make_fault(a.fault, **_kv(a.params)),
76
+ expect=parse_expect(a.expect if a.expect != ["none"] else "none") if a.expect else None)]
77
+ except (ValueError, KeyError, OSError) as e:
78
+ print(f"armchaos: {e}", file=sys.stderr)
79
+ return 2
80
+ lead = a.armdoc_lead if a.armdoc else 0.0
81
+ if a.armdoc and not ArmdocWatcher.available():
82
+ print("armchaos: --armdoc needs armdoc (https://github.com/darshmenon/armdoc) on PYTHONPATH", file=sys.stderr)
83
+ return 2
84
+ msg = over_budget(steps, a.max_duration, lead)
85
+ if msg:
86
+ print(f"armchaos: {msg}", file=sys.stderr)
87
+ return 2
88
+ for s in steps:
89
+ e = "" if s.expect is None else (" expect: none" if s.expect == () else f" expect: {', '.join(s.expect)}")
90
+ print(f"plan: t={s.at:g}s for {s.dur:g}s {s.label()}{e}")
91
+ print(f"plan: relay {a.source} -> {a.out}" + (f", controllers via {a.cm}" if any(s.fault.controller for s in steps) else ""))
92
+ print(f"plan: stops after {a.max_duration:g}s at most; controllers "
93
+ + ("restored on Ctrl-C/SIGTERM" if a.restore_on_exit else "NOT restored on Ctrl-C/SIGTERM"))
94
+ if a.dry_run:
95
+ return 0
96
+ if not a.armdoc and any(s.expect is not None for s in steps):
97
+ print("note: `expect:` is only checked with --armdoc", file=sys.stderr)
98
+ from armchaos.relay import run
99
+ watcher = ArmdocWatcher(a.out) if a.armdoc else None
100
+ res = run(steps, a.source, a.out, a.cm, a.events, lead=lead, max_duration=a.max_duration,
101
+ restore_on_exit=a.restore_on_exit, watcher=watcher)
102
+ results = []
103
+ if watcher:
104
+ if not watcher.alive() and not watcher.reports:
105
+ print("armchaos: the armdoc probe produced no reports: " + " | ".join(watcher.other), file=sys.stderr)
106
+ results = build_results(steps, res.windows, watcher.reports)
107
+ print("\n" + format_table(results))
108
+ ok = sum(r.status == "PASS" for r in results)
109
+ bad = sum(r.status == "FAIL" for r in results)
110
+ print(f"\n{ok} passed, {bad} failed, {sum(r.status == '-' for r in results)} unchecked, "
111
+ f"{sum(r.status == 'SKIP' for r in results)} not run")
112
+ else:
113
+ print(f"\ndone: {len(res.windows)} of {len(steps)} fault(s) applied")
114
+ return exit_code(results, res.unrestored, res.stopped_by if res.stopped_by in ("SIGINT", "SIGTERM") else None)
115
+
116
+
117
+ if __name__ == "__main__":
118
+ sys.exit(main())