nepyope commited on
Commit
951b7bc
Β·
verified Β·
1 Parent(s): f1e56e0

Delete CAMERA_README.md

Browse files
Files changed (1) hide show
  1. CAMERA_README.md +0 -256
CAMERA_README.md DELETED
@@ -1,256 +0,0 @@
1
- # Camera System for MuJoCo G1 Simulator
2
-
3
- ## Overview
4
-
5
- The simulator has two cameras defined:
6
-
7
- ### 1. **`head_camera`** - Robot Ego-View
8
- - **Location**: Attached to `torso_link` body
9
- - **Position**: `[0.06, 0.0, 0.45]` relative to torso (6cm forward, 45cm up)
10
- - **Orientation**: `euler="0 -0.8 -1.57"` (facing forward, slightly tilted down)
11
- - **FOV**: 90 degrees
12
- - **Purpose**: First-person view from the robot's perspective (like a head-mounted camera)
13
-
14
- ### 2. **`global_view`** - Third-Person View
15
- - **Location**: Fixed in world coordinates
16
- - **Position**: `[2.910, -5.040, 3.860]` (behind and above the robot)
17
- - **Purpose**: External observer view for visualization
18
-
19
- ## How Camera Publishing Works
20
-
21
- The camera system uses a **zero-copy architecture** with three components:
22
-
23
- ```
24
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
25
- β”‚ MuJoCo Simulator β”‚
26
- β”‚ (Main Process) β”‚
27
- β”‚ β”‚
28
- β”‚ 1. Render cameras β”‚
29
- β”‚ 2. Copy to shmem │──┐
30
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
31
- β”‚ Shared Memory
32
- β”‚ (fast IPC)
33
- β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
34
- β”‚ Image Publisher β”‚
35
- β”‚ (Subprocess) β”‚
36
- β”‚ β”‚
37
- β”‚ 3. Encode images β”‚
38
- β”‚ 4. ZMQ publish β”‚
39
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
40
- β”‚
41
- β”‚ TCP (ZMQ)
42
- β”‚ port 5555
43
- β–Ό
44
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
45
- β”‚ Your Policy/Client β”‚
46
- β”‚ (Subscribe) β”‚
47
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
48
- ```
49
-
50
- ### Key Technologies:
51
- - **MuJoCo Renderer**: Captures RGB images from virtual cameras
52
- - **Shared Memory (`multiprocessing.shared_memory`)**: Zero-copy transfer between processes
53
- - **ZMQ (ZeroMQ)**: Network socket for publishing images (TCP)
54
- - **No ROS2 required!** Pure Python multiprocessing
55
-
56
- ## Usage
57
-
58
- ### Basic Simulation (No Camera Publishing)
59
- ```bash
60
- python run_sim.py
61
- ```
62
-
63
- ### With Camera Publishing
64
- ```bash
65
- # Publish head camera on default port 5555
66
- python run_sim.py --publish-images
67
-
68
- # Publish multiple cameras
69
- python run_sim.py --publish-images --cameras head_camera global_view
70
-
71
- # Custom port
72
- python run_sim.py --publish-images --camera-port 6000
73
- ```
74
-
75
- ### Viewing Camera Streams
76
-
77
- In a **separate terminal**, run the camera viewer:
78
-
79
- ```bash
80
- # Basic usage (default: localhost:5555)
81
- python view_cameras.py
82
-
83
- # Custom host/port
84
- python view_cameras.py --host 192.168.1.100 --port 6000
85
-
86
- # Save images to directory
87
- python view_cameras.py --save ./camera_recordings
88
-
89
- # Adjust display rate
90
- python view_cameras.py --fps 60
91
- ```
92
-
93
- **Keyboard Controls:**
94
- - `q`: Quit viewer
95
- - `s`: Save snapshot of current frame
96
-
97
- **Example Workflow:**
98
- ```bash
99
- # Terminal 1: Start simulator with camera publishing
100
- python run_sim.py --publish-images
101
-
102
- # Terminal 2: View the camera feed
103
- python view_cameras.py
104
- ```
105
-
106
- ### Receiving Images in Your Code
107
-
108
- ```python
109
- import zmq
110
- import numpy as np
111
- from gr00t_wbc.control.sensor.sensor_server import ImageMessageSchema
112
-
113
- # Connect to camera publisher
114
- context = zmq.Context()
115
- socket = context.socket(zmq.SUB)
116
- socket.connect("tcp://localhost:5555")
117
- socket.setsockopt(zmq.SUBSCRIBE, b"") # Subscribe to all messages
118
-
119
- while True:
120
- # Receive serialized image data
121
- data = socket.recv_pyobj()
122
-
123
- # Decode images
124
- if "head_camera" in data:
125
- # Decode image (returns numpy array HxWx3 uint8)
126
- img = decode_image(data["head_camera"])
127
-
128
- # Use image for your policy
129
- process_observation(img)
130
- ```
131
-
132
- ## Camera Configuration
133
-
134
- Edit `config.yaml` to change camera settings:
135
-
136
- ```yaml
137
- IMAGE_DT: 0.033333 # Publishing rate (30 Hz)
138
- ENABLE_OFFSCREEN: false # Enable for camera rendering
139
- MP_START_METHOD: "spawn" # Multiprocessing method
140
- ```
141
-
142
- Or programmatically in `run_sim.py`:
143
-
144
- ```python
145
- camera_configs = {
146
- "head_camera": {
147
- "height": 480,
148
- "width": 640
149
- },
150
- "custom_camera": {
151
- "height": 224,
152
- "width": 224
153
- }
154
- }
155
- ```
156
-
157
- ## Adding Custom Cameras
158
-
159
- Edit `assets/g1_29dof_with_hand.xml` or `assets/scene_43dof.xml`:
160
-
161
- ```xml
162
- <!-- Camera attached to robot body -->
163
- <body name="torso_link" pos="0 0 0.019">
164
- <camera name="my_camera" pos="0.1 0.0 0.5" euler="0 0 0" fovy="60"/>
165
- </body>
166
-
167
- <!-- Camera in world coordinates -->
168
- <worldbody>
169
- <camera name="side_view" pos="0 -3.0 1.5" xyaxes="1 0 0 0 0.5 0.866"/>
170
- </worldbody>
171
- ```
172
-
173
- Then publish it:
174
- ```bash
175
- python run_sim.py --publish-images --cameras my_camera
176
- ```
177
-
178
- ## Performance Notes
179
-
180
- - **Rendering overhead**: ~5-10ms per camera per frame @ 640x480
181
- - **Publishing overhead**: ~2-3ms for encoding + network
182
- - Image publishing runs in **separate subprocess** to not block simulation
183
- - Uses **shared memory** for fast inter-process image transfer
184
- - Target: 30 FPS camera publishing while maintaining 500 Hz simulation
185
-
186
- ## Troubleshooting
187
-
188
- ### No images received?
189
- 1. Check if offscreen rendering is enabled (`--publish-images` flag)
190
- 2. Verify ZMQ port is not blocked
191
- 3. Check camera exists in scene XML
192
-
193
- ### Images are delayed?
194
- - Reduce `IMAGE_DT` in config
195
- - Lower camera resolution
196
- - Use fewer cameras
197
-
198
- ### "Camera not found" error?
199
- - Verify camera name in XML matches config
200
- - Check XML syntax is valid
201
- - Ensure MuJoCo model loads successfully
202
-
203
- ## Quick Reference
204
-
205
- ### File Structure
206
- ```
207
- mujoco_sim_g1/
208
- β”œβ”€β”€ run_sim.py # Simulator launcher
209
- β”œβ”€β”€ view_cameras.py # Camera viewer (this file!)
210
- β”œβ”€β”€ config.yaml # Simulator config
211
- β”œβ”€β”€ assets/
212
- β”‚ β”œβ”€β”€ scene_43dof.xml # Scene with global_view camera
213
- β”‚ └── g1_29dof_with_hand.xml # Robot model with head_camera
214
- └── sim/
215
- β”œβ”€β”€ base_sim.py # MuJoCo environment
216
- β”œβ”€β”€ sensor_utils.py # ZMQ camera server/client
217
- └── image_publish_utils.py # Multiprocessing image publisher
218
- ```
219
-
220
- ### Camera Definitions
221
-
222
- Edit these files to modify cameras:
223
-
224
- **`assets/g1_29dof_with_hand.xml`** - Robot-attached cameras:
225
- ```xml
226
- <body name="torso_link" pos="0 0 0.019">
227
- <camera name="head_camera" pos="0.06 0.0 0.45" euler="0 -0.8 -1.57" fovy="90"/>
228
- </body>
229
- ```
230
-
231
- **`assets/scene_43dof.xml`** - World-frame cameras:
232
- ```xml
233
- <worldbody>
234
- <camera name="global_view" pos="2.910 -5.040 3.860" xyaxes="0.866 0.500 0.000 -0.250 0.433 0.866" fovy="45"/>
235
- </worldbody>
236
- ```
237
-
238
- ### Complete Example
239
-
240
- ```bash
241
- # Terminal 1: Start simulator with camera publishing
242
- cd mujoco_sim_g1
243
- python run_sim.py --publish-images --cameras head_camera global_view
244
-
245
- # Terminal 2: View cameras in real-time
246
- python view_cameras.py
247
-
248
- # Terminal 3: Use in your policy (Python code)
249
- from sim.sensor_utils import SensorClient, ImageUtils
250
- client = SensorClient()
251
- client.start_client("localhost", 5555)
252
- data = client.receive_message()
253
- img = ImageUtils.decode_image(data["head_camera"])
254
- # img is now numpy array (H, W, 3) in BGR format
255
- ```
256
-