trossen_arm_sim 0.2.0__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.
- trossen_arm_sim-0.2.0/LICENSE +201 -0
- trossen_arm_sim-0.2.0/PKG-INFO +142 -0
- trossen_arm_sim-0.2.0/README.md +127 -0
- trossen_arm_sim-0.2.0/pyproject.toml +29 -0
- trossen_arm_sim-0.2.0/setup.cfg +4 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/__init__.py +11 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/__main__.py +70 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/base_link.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/camera_mount_d405.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/carriage_left.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/carriage_right.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/d405.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/gripper_left.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/gripper_right.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/link_1.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/link_2.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/link_3.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/link_4.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/link_5.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/link_6.stl +0 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/scene_empty.xml +21 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/assets/wxai_follower.xml +118 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/collision.py +208 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/collision_server.py +74 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/protocol.py +165 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/server.py +240 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim/sim.py +170 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim.egg-info/PKG-INFO +142 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim.egg-info/SOURCES.txt +31 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim.egg-info/dependency_links.txt +1 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim.egg-info/entry_points.txt +2 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim.egg-info/requires.txt +4 -0
- trossen_arm_sim-0.2.0/trossen_arm_sim.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trossen_arm_sim
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Simulated Trossen WidowX AI arm controller: a network drop-in replacement for real hardware, running in MuJoCo
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/depetrol/trossen_arm_sim
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: mujoco>=3.0
|
|
11
|
+
Requires-Dist: numpy
|
|
12
|
+
Requires-Dist: trossen_arm==1.10.*
|
|
13
|
+
Requires-Dist: websockets>=13
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# trossen_arm_sim
|
|
17
|
+
|
|
18
|
+
Runs `trossen_arm` in simulation. The server speaks the wire protocol of the WidowX AI (wxai_v0) arm controller (firmware v1.10), so the unmodified `trossen_arm` driver connects to it as if it were real hardware — the arm runs in MuJoCo instead.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install .
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Clients need `trossen_arm==1.10.*` (the driver rejects other firmware versions).
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
trossen-arm-sim # default scene: arm on a ground plane
|
|
32
|
+
trossen-arm-sim scene.xml # custom scene
|
|
33
|
+
mjpython -m trossen_arm_sim --viewer # MuJoCo viewer (macOS needs mjpython)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Point any `trossen_arm` client at `127.0.0.1` instead of the robot's IP:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
driver.configure(
|
|
40
|
+
trossen_arm.Model.wxai_v0,
|
|
41
|
+
trossen_arm.StandardEndEffector.wxai_v0_follower,
|
|
42
|
+
"127.0.0.1",
|
|
43
|
+
False,
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A custom scene is MJCF that includes the arm via the `WIDOWX_XML` placeholder, replaced with the installed arm model path at load time (`TROSSEN_ARM_ASSET_DIR` likewise for the packaged asset directory):
|
|
48
|
+
|
|
49
|
+
```xml
|
|
50
|
+
<mujoco>
|
|
51
|
+
<include file="WIDOWX_XML"/>
|
|
52
|
+
<worldbody>
|
|
53
|
+
<light pos="0 0 1.5" dir="0 0 -1" directional="true"/>
|
|
54
|
+
<geom name="floor" size="0 0 0.05" type="plane" rgba="0.5 0.5 0.5 1"/>
|
|
55
|
+
</worldbody>
|
|
56
|
+
</mujoco>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Example
|
|
60
|
+
|
|
61
|
+
Numpad scene plus a client that presses its keys and prints every collision the simulator reports (see [Collision stream](#collision-stream) below):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
trossen-arm-sim examples/scene_numpad.xml # terminal 1
|
|
65
|
+
python examples/press_button.py 1 2 3 enter # terminal 2
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Collision stream
|
|
69
|
+
|
|
70
|
+
The simulator streams contacts between geoms over a WebSocket, so a client can tell when the arm touches something, what it touched, and how hard.
|
|
71
|
+
|
|
72
|
+
### Connecting
|
|
73
|
+
|
|
74
|
+
Connect to `ws://<host>:50002` (`--ws-port` changes the port). The server sends JSON text messages and ignores anything the client sends. Any WebSocket library works; with `websockets`:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import json
|
|
78
|
+
from websockets.sync.client import connect
|
|
79
|
+
|
|
80
|
+
with connect("ws://127.0.0.1:50002") as ws:
|
|
81
|
+
for message in ws:
|
|
82
|
+
event = json.loads(message)
|
|
83
|
+
print(event["type"], event.get("geom1"), event.get("geom2"))
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Messages
|
|
87
|
+
|
|
88
|
+
| `type` | When | Content |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| `snapshot` | Once, right after connecting | `time` and `contacts`, the list of contact pairs active at that moment (each with the fields below except `type`, `time`, `duration`, `peak_force`) |
|
|
91
|
+
| `begin` | A pair of geoms starts touching | The contact fields; `duration` is 0 and `peak_force` equals `force` |
|
|
92
|
+
| `end` | The pair has not touched for 20 ms | The contact as last seen; `duration` and `peak_force` cover the whole contact |
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{"type": "snapshot", "time": 3.2, "contacts": []}
|
|
96
|
+
{"type": "begin", "time": 10.736, "geom1": "carriage_right", "body1": "carriage_right", "geom2": "key_5", "body2": "numpad", "force": 0.78, "pos": [0.39, 0.296, 0.026], "duration": 0.0, "peak_force": 0.78}
|
|
97
|
+
{"type": "end", "time": 11.404, "geom1": "carriage_right", "body1": "carriage_right", "geom2": "key_5", "body2": "numpad", "force": 0.0, "pos": [0.39, 0.296, 0.026], "duration": 0.65, "peak_force": 0.78}
|
|
98
|
+
{"type": "begin", "time": 15.1, "geom1": "link_6", "body1": "link_6", "geom2": "floor", "body2": "world", "force": 80.2, "pos": [0.378, -0.038, 0.0], "duration": 0.0, "peak_force": 80.2}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
| Field | Unit | Meaning |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| `time` | s | Simulation time of the message |
|
|
104
|
+
| `geom1`, `geom2` | | The two touching geoms (see naming below) |
|
|
105
|
+
| `body1`, `body2` | | The bodies those geoms belong to; `world` for the floor |
|
|
106
|
+
| `force` | N | Total normal force between the pair at the time of the message |
|
|
107
|
+
| `peak_force` | N | Largest `force` seen since the pair started touching |
|
|
108
|
+
| `pos` | m | Mean position of the contact points, world frame |
|
|
109
|
+
| `duration` | s | How long the pair has been touching |
|
|
110
|
+
|
|
111
|
+
### Naming
|
|
112
|
+
|
|
113
|
+
A contact pair is identified by two geom labels. A named geom is labelled with its name. An unnamed geom is labelled with its body's name, so all the unnamed collision geoms of one body aggregate into one pair. An unnamed body is labelled `body<id>`, and a deformable flex with its name. Name the geoms you want to tell apart, as `scene_numpad.xml` does with `key_*`.
|
|
114
|
+
|
|
115
|
+
When the arm is involved, it is always side 1: `geom1`/`body1` is one of `base_link`, `link_1` to `link_6`, `carriage_left` or `carriage_right` (the gripper fingers). Contacts between two arm parts, and between scene objects that do not involve the arm, are streamed as well, in MuJoCo's order.
|
|
116
|
+
|
|
117
|
+
### Filtering on the client
|
|
118
|
+
|
|
119
|
+
Everything MuJoCo resolves is streamed, including the two gripper fingers touching each other whenever the gripper closes and objects resting on the floor. The client decides what matters:
|
|
120
|
+
|
|
121
|
+
- **By name**: `geom1` starting with `carriage_` and `geom2` starting with `key_` is a key press; `geom2 == "floor"` is a crash; a key touched by `link_2` is a crash too, so check both sides.
|
|
122
|
+
- **By force**: a press and a smash on the same key differ only in `force` and `peak_force`. Pressing a numpad key reads about 1 N; a finger driven into the floor reads hundreds of N.
|
|
123
|
+
|
|
124
|
+
`examples/watch_collisions.py` does exactly this: it prints the stream on a background thread, labelling each event PRESS or CRASH (`--all` prints every pair unfiltered), while the prompt drives the arm through the `trossen_arm` driver. `wave` swings the arm clear of everything and prints nothing; `crash` drives the gripper into the floor and prints CRASH events with the impact force; `quit` returns home.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
python examples/watch_collisions.py
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Publish
|
|
131
|
+
|
|
132
|
+
Bump `version` in `pyproject.toml`, then:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pip install build twine
|
|
136
|
+
python -m build
|
|
137
|
+
twine upload dist/*
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Attributions
|
|
141
|
+
|
|
142
|
+
The arm model and meshes in `trossen_arm_sim/assets/` are from [trossen_arm_mujoco](https://github.com/TrossenRobotics/trossen_arm_mujoco), Copyright (c) 2025 Trossen Robotics, licensed under BSD-3-Clause.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# trossen_arm_sim
|
|
2
|
+
|
|
3
|
+
Runs `trossen_arm` in simulation. The server speaks the wire protocol of the WidowX AI (wxai_v0) arm controller (firmware v1.10), so the unmodified `trossen_arm` driver connects to it as if it were real hardware — the arm runs in MuJoCo instead.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Clients need `trossen_arm==1.10.*` (the driver rejects other firmware versions).
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
trossen-arm-sim # default scene: arm on a ground plane
|
|
17
|
+
trossen-arm-sim scene.xml # custom scene
|
|
18
|
+
mjpython -m trossen_arm_sim --viewer # MuJoCo viewer (macOS needs mjpython)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Point any `trossen_arm` client at `127.0.0.1` instead of the robot's IP:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
driver.configure(
|
|
25
|
+
trossen_arm.Model.wxai_v0,
|
|
26
|
+
trossen_arm.StandardEndEffector.wxai_v0_follower,
|
|
27
|
+
"127.0.0.1",
|
|
28
|
+
False,
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
A custom scene is MJCF that includes the arm via the `WIDOWX_XML` placeholder, replaced with the installed arm model path at load time (`TROSSEN_ARM_ASSET_DIR` likewise for the packaged asset directory):
|
|
33
|
+
|
|
34
|
+
```xml
|
|
35
|
+
<mujoco>
|
|
36
|
+
<include file="WIDOWX_XML"/>
|
|
37
|
+
<worldbody>
|
|
38
|
+
<light pos="0 0 1.5" dir="0 0 -1" directional="true"/>
|
|
39
|
+
<geom name="floor" size="0 0 0.05" type="plane" rgba="0.5 0.5 0.5 1"/>
|
|
40
|
+
</worldbody>
|
|
41
|
+
</mujoco>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
Numpad scene plus a client that presses its keys and prints every collision the simulator reports (see [Collision stream](#collision-stream) below):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
trossen-arm-sim examples/scene_numpad.xml # terminal 1
|
|
50
|
+
python examples/press_button.py 1 2 3 enter # terminal 2
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Collision stream
|
|
54
|
+
|
|
55
|
+
The simulator streams contacts between geoms over a WebSocket, so a client can tell when the arm touches something, what it touched, and how hard.
|
|
56
|
+
|
|
57
|
+
### Connecting
|
|
58
|
+
|
|
59
|
+
Connect to `ws://<host>:50002` (`--ws-port` changes the port). The server sends JSON text messages and ignores anything the client sends. Any WebSocket library works; with `websockets`:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import json
|
|
63
|
+
from websockets.sync.client import connect
|
|
64
|
+
|
|
65
|
+
with connect("ws://127.0.0.1:50002") as ws:
|
|
66
|
+
for message in ws:
|
|
67
|
+
event = json.loads(message)
|
|
68
|
+
print(event["type"], event.get("geom1"), event.get("geom2"))
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Messages
|
|
72
|
+
|
|
73
|
+
| `type` | When | Content |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `snapshot` | Once, right after connecting | `time` and `contacts`, the list of contact pairs active at that moment (each with the fields below except `type`, `time`, `duration`, `peak_force`) |
|
|
76
|
+
| `begin` | A pair of geoms starts touching | The contact fields; `duration` is 0 and `peak_force` equals `force` |
|
|
77
|
+
| `end` | The pair has not touched for 20 ms | The contact as last seen; `duration` and `peak_force` cover the whole contact |
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{"type": "snapshot", "time": 3.2, "contacts": []}
|
|
81
|
+
{"type": "begin", "time": 10.736, "geom1": "carriage_right", "body1": "carriage_right", "geom2": "key_5", "body2": "numpad", "force": 0.78, "pos": [0.39, 0.296, 0.026], "duration": 0.0, "peak_force": 0.78}
|
|
82
|
+
{"type": "end", "time": 11.404, "geom1": "carriage_right", "body1": "carriage_right", "geom2": "key_5", "body2": "numpad", "force": 0.0, "pos": [0.39, 0.296, 0.026], "duration": 0.65, "peak_force": 0.78}
|
|
83
|
+
{"type": "begin", "time": 15.1, "geom1": "link_6", "body1": "link_6", "geom2": "floor", "body2": "world", "force": 80.2, "pos": [0.378, -0.038, 0.0], "duration": 0.0, "peak_force": 80.2}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
| Field | Unit | Meaning |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `time` | s | Simulation time of the message |
|
|
89
|
+
| `geom1`, `geom2` | | The two touching geoms (see naming below) |
|
|
90
|
+
| `body1`, `body2` | | The bodies those geoms belong to; `world` for the floor |
|
|
91
|
+
| `force` | N | Total normal force between the pair at the time of the message |
|
|
92
|
+
| `peak_force` | N | Largest `force` seen since the pair started touching |
|
|
93
|
+
| `pos` | m | Mean position of the contact points, world frame |
|
|
94
|
+
| `duration` | s | How long the pair has been touching |
|
|
95
|
+
|
|
96
|
+
### Naming
|
|
97
|
+
|
|
98
|
+
A contact pair is identified by two geom labels. A named geom is labelled with its name. An unnamed geom is labelled with its body's name, so all the unnamed collision geoms of one body aggregate into one pair. An unnamed body is labelled `body<id>`, and a deformable flex with its name. Name the geoms you want to tell apart, as `scene_numpad.xml` does with `key_*`.
|
|
99
|
+
|
|
100
|
+
When the arm is involved, it is always side 1: `geom1`/`body1` is one of `base_link`, `link_1` to `link_6`, `carriage_left` or `carriage_right` (the gripper fingers). Contacts between two arm parts, and between scene objects that do not involve the arm, are streamed as well, in MuJoCo's order.
|
|
101
|
+
|
|
102
|
+
### Filtering on the client
|
|
103
|
+
|
|
104
|
+
Everything MuJoCo resolves is streamed, including the two gripper fingers touching each other whenever the gripper closes and objects resting on the floor. The client decides what matters:
|
|
105
|
+
|
|
106
|
+
- **By name**: `geom1` starting with `carriage_` and `geom2` starting with `key_` is a key press; `geom2 == "floor"` is a crash; a key touched by `link_2` is a crash too, so check both sides.
|
|
107
|
+
- **By force**: a press and a smash on the same key differ only in `force` and `peak_force`. Pressing a numpad key reads about 1 N; a finger driven into the floor reads hundreds of N.
|
|
108
|
+
|
|
109
|
+
`examples/watch_collisions.py` does exactly this: it prints the stream on a background thread, labelling each event PRESS or CRASH (`--all` prints every pair unfiltered), while the prompt drives the arm through the `trossen_arm` driver. `wave` swings the arm clear of everything and prints nothing; `crash` drives the gripper into the floor and prints CRASH events with the impact force; `quit` returns home.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python examples/watch_collisions.py
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Publish
|
|
116
|
+
|
|
117
|
+
Bump `version` in `pyproject.toml`, then:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pip install build twine
|
|
121
|
+
python -m build
|
|
122
|
+
twine upload dist/*
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Attributions
|
|
126
|
+
|
|
127
|
+
The arm model and meshes in `trossen_arm_sim/assets/` are from [trossen_arm_mujoco](https://github.com/TrossenRobotics/trossen_arm_mujoco), Copyright (c) 2025 Trossen Robotics, licensed under BSD-3-Clause.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "trossen_arm_sim"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Simulated Trossen WidowX AI arm controller: a network drop-in replacement for real hardware, running in MuJoCo"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"mujoco>=3.0",
|
|
14
|
+
"numpy",
|
|
15
|
+
"trossen_arm==1.10.*",
|
|
16
|
+
"websockets>=13",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Repository = "https://github.com/depetrol/trossen_arm_sim"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
trossen-arm-sim = "trossen_arm_sim.__main__:main"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
include = ["trossen_arm_sim*"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
trossen_arm_sim = ["assets/*"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Simulated Trossen arm controller: the trossen_arm driver connects to this
|
|
2
|
+
server exactly as it would to real hardware, and the arm runs in MuJoCo."""
|
|
3
|
+
|
|
4
|
+
from .collision import CollisionEvent, CollisionMonitor, Contact
|
|
5
|
+
from .collision_server import CollisionWebSocketServer
|
|
6
|
+
from .server import TrossenArmSimServer
|
|
7
|
+
from .sim import ARM_MODEL_PATH, DEFAULT_SCENE, WidowXSim, load_scene
|
|
8
|
+
|
|
9
|
+
__all__ = ["ARM_MODEL_PATH", "DEFAULT_SCENE", "CollisionEvent",
|
|
10
|
+
"CollisionMonitor", "CollisionWebSocketServer", "Contact",
|
|
11
|
+
"TrossenArmSimServer", "WidowXSim", "load_scene"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Run the simulated Trossen arm controller.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
python -m trossen_arm_sim [SCENE] [--viewer] [--verbose] [--ws-port PORT]
|
|
5
|
+
|
|
6
|
+
SCENE is a MuJoCo MJCF file that includes the packaged arm model via
|
|
7
|
+
`<include file="WIDOWX_XML"/>`; the WIDOWX_XML and TROSSEN_ARM_ASSET_DIR
|
|
8
|
+
placeholders are replaced with the installed asset paths at load time. It
|
|
9
|
+
defaults to a built-in empty scene with just the arm on a ground plane.
|
|
10
|
+
With --viewer, a MuJoCo viewer window shows the scene (on macOS this
|
|
11
|
+
requires running under mjpython).
|
|
12
|
+
|
|
13
|
+
Contacts in the scene are streamed as JSON over a WebSocket on --ws-port;
|
|
14
|
+
see collision_server.py for the messages.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import logging
|
|
19
|
+
import time
|
|
20
|
+
|
|
21
|
+
from .collision import CollisionMonitor
|
|
22
|
+
from .collision_server import WS_PORT, CollisionWebSocketServer
|
|
23
|
+
from .server import TrossenArmSimServer
|
|
24
|
+
from .sim import DEFAULT_SCENE, WidowXSim
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def main() -> None:
|
|
28
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
29
|
+
parser.add_argument("scene", nargs="?", default=DEFAULT_SCENE,
|
|
30
|
+
help="MuJoCo scene XML including the arm model "
|
|
31
|
+
"(default: built-in empty scene)")
|
|
32
|
+
parser.add_argument("--host", default="0.0.0.0", help="bind address")
|
|
33
|
+
parser.add_argument("--viewer", action="store_true",
|
|
34
|
+
help="show the MuJoCo viewer (macOS: run with mjpython)")
|
|
35
|
+
parser.add_argument("--verbose", action="store_true",
|
|
36
|
+
help="log every protocol request")
|
|
37
|
+
parser.add_argument("--ws-port", type=int, default=WS_PORT,
|
|
38
|
+
help="WebSocket port for the collision stream")
|
|
39
|
+
args = parser.parse_args()
|
|
40
|
+
|
|
41
|
+
logging.basicConfig(
|
|
42
|
+
level=logging.DEBUG if args.verbose else logging.INFO,
|
|
43
|
+
format="%(asctime)s %(name)s %(levelname)s: %(message)s",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
sim = WidowXSim(args.scene)
|
|
47
|
+
monitor = CollisionMonitor(sim)
|
|
48
|
+
sim.start()
|
|
49
|
+
server = TrossenArmSimServer(sim, host=args.host)
|
|
50
|
+
server.start()
|
|
51
|
+
collision_server = CollisionWebSocketServer(monitor, host=args.host,
|
|
52
|
+
port=args.ws_port)
|
|
53
|
+
collision_server.start()
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
if args.viewer:
|
|
57
|
+
sim.sync_viewer_loop()
|
|
58
|
+
else:
|
|
59
|
+
while True:
|
|
60
|
+
time.sleep(1)
|
|
61
|
+
except KeyboardInterrupt:
|
|
62
|
+
pass
|
|
63
|
+
finally:
|
|
64
|
+
collision_server.stop()
|
|
65
|
+
server.stop()
|
|
66
|
+
sim.stop()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<mujoco model="wxai empty scene">
|
|
2
|
+
<include file="wxai_follower.xml"/>
|
|
3
|
+
|
|
4
|
+
<statistic center="0.2 0 0.2" extent="0.6"/>
|
|
5
|
+
|
|
6
|
+
<visual>
|
|
7
|
+
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0"/>
|
|
8
|
+
<global azimuth="160" elevation="-20"/>
|
|
9
|
+
</visual>
|
|
10
|
+
|
|
11
|
+
<asset>
|
|
12
|
+
<texture type="2d" name="groundplane" builtin="checker" mark="edge"
|
|
13
|
+
rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300"/>
|
|
14
|
+
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.2"/>
|
|
15
|
+
</asset>
|
|
16
|
+
|
|
17
|
+
<worldbody>
|
|
18
|
+
<light pos="0 0 1.5" dir="0 0 -1" directional="true"/>
|
|
19
|
+
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane"/>
|
|
20
|
+
</worldbody>
|
|
21
|
+
</mujoco>
|