Skip to content

Commit 227a405

Browse files
committed
Add a manipulator demo using Electron + rclnodejs
1 parent a778426 commit 227a405

File tree

11 files changed

+1242
-4
lines changed

11 files changed

+1242
-4
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ API documentation is available [online](https://robotwebtools.github.io/rclnodej
7878

7979
Create rich, interactive desktop applications using Electron and web technologies like Three.js. Build 3D visualizations, monitoring dashboards, and control interfaces that run on Windows, macOS, and Linux.
8080

81-
Try the `electron_demo/turtle_tf2` demo for real-time coordinate frame visualization with dynamic transforms and keyboard-controlled turtle movement. More examples in [electron_demo](https://github.com/RobotWebTools/rclnodejs/tree/develop/electron_demo).
81+
| Demo | Description | Screenshot |
82+
| :-----------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------: |
83+
| **🐢 [turtle_tf2](./electron_demo/turtle_tf2)** | Real-time coordinate frame visualization with turtle control. Features TF2 transforms, keyboard control, and dynamic frame updates. | ![turtle_tf2](./electron_demo/turtle_tf2/turtle-tf2-demo.png) |
84+
| **🦾 [manipulator](./electron_demo/manipulator)** | Interactive two-joint robotic arm simulation. Features 3D joint visualization, manual/automatic control, and visual movement markers. | ![manipulator](./electron_demo/manipulator/manipulator-demo.png) |
8285

83-
![demo screenshot](./electron_demo/turtle_tf2/turtle-tf2-demo.png)
86+
Explore more examples in [electron_demo](https://github.com/RobotWebTools/rclnodejs/tree/develop/electron_demo).
8487

8588
## Using rclnodejs with TypeScript
8689

Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
# Two-Joint Manipulator Demo
2+
3+
An interactive Electron application demonstrating a two-joint robotic manipulator visualization using rclnodejs and Three.js.
4+
5+
![Manipulator Demo](./manipulator-demo.gif)
6+
7+
## 🚀 Features
8+
9+
- **Real-time 3D Visualization**: Interactive two-joint robotic arm with Three.js
10+
- **ROS2 Integration**: Publishes and subscribes to `sensor_msgs/msg/JointState` topics
11+
- **Interactive Control**: Manual joint control with sliders
12+
- **Automatic Animation**: Smooth sinusoidal motion patterns
13+
- **Live Feedback**: Real-time joint position display and ROS2 message frequency
14+
- **Visual Movement Markers**: Color-coded rings, arrows, and labels to identify joint movements
15+
- **Modern UI**: Clean, responsive interface with 3D orbit controls
16+
17+
## 📋 Prerequisites
18+
19+
- **Node.js** (>= 16.13.0) - JavaScript runtime
20+
- **ROS 2** (Humble, Jazzy, or newer) - Robot Operating System 2
21+
- **rclnodejs compatible environment** - Linux recommended (tested on Ubuntu/WSL)
22+
23+
## 🛠️ Installation
24+
25+
1. **Navigate to the demo directory**:
26+
27+
```bash
28+
cd rclnodejs/electron_demo/manipulator
29+
```
30+
31+
2. **Install dependencies**:
32+
33+
```bash
34+
npm install
35+
```
36+
37+
3. **Rebuild native modules for Electron**:
38+
```bash
39+
npm run rebuild
40+
```
41+
42+
## 📜 Available Scripts
43+
44+
- **`npm start`** - Run demo (requires manual ROS2 environment setup)
45+
- **`npm run start-with-ros2`** - Run demo with automatic ROS2 environment setup (recommended)
46+
- **`npm run rebuild`** - Rebuild native modules after dependency changes
47+
48+
## 🚀 Quick Start
49+
50+
### Option 1: Simple Demo (Works Everywhere)
51+
52+
```bash
53+
npm start
54+
```
55+
56+
-**No ROS2 environment required**
57+
-**Works without external setup**
58+
-**Pure visualization and manual control**
59+
- ⚠️ No ROS2 topic publishing (local mode only)
60+
61+
### Option 2: Full ROS2 Integration (Recommended)
62+
63+
```bash
64+
npm run start-with-ros2
65+
```
66+
67+
-**Automatically sources ROS2 environment**
68+
-**Publishes to `/joint_states` topic**
69+
-**Full ROS2 ecosystem integration**
70+
-**No manual environment setup needed**
71+
72+
### Option 3: Manual ROS2 Setup
73+
74+
1. **Source your ROS2 environment**:
75+
76+
```bash
77+
source /opt/ros/humble/setup.bash # or your ROS2 installation path
78+
```
79+
80+
2. **Run the demo**:
81+
```bash
82+
npm start
83+
```
84+
85+
## 🎮 Usage
86+
87+
### Interactive Controls
88+
89+
- **Joint Sliders**: Use the sliders in the control panel to manually adjust joint angles
90+
91+
- **Joint 1 (Base)**: Rotates the entire arm around the vertical axis (±180°)
92+
- **Joint 2 (Elbow)**: Bends the upper arm segment (±135°)
93+
94+
- **Animation**: Click "Start Animation" for automatic smooth motion
95+
- **Reset**: Click "Reset Position" to return to zero configuration
96+
97+
### 3D Visualization Controls
98+
99+
- **Orbit**: Click and drag to rotate the camera around the manipulator
100+
- **Zoom**: Use mouse wheel to zoom in/out
101+
- **View**: The manipulator is shown with color-coded components:
102+
- **Gray Base**: Fixed mounting base
103+
- **Red Joint 1**: Base rotation joint
104+
- **Blue Link 1**: Upper arm segment
105+
- **Green Joint 2**: Elbow rotation joint
106+
- **Yellow Link 2**: Forearm segment
107+
- **Purple End Effector**: Tool attachment point
108+
109+
### Visual Movement Markers
110+
111+
The demo includes visual indicators to help identify joint movements:
112+
113+
- **🔴 Red Markers**: Joint 1 (Base rotation)
114+
115+
- Red ring around the base joint
116+
- Red arrow showing rotation direction
117+
- "Joint1" text label
118+
119+
- **🟢 Green Markers**: Joint 2 (Elbow)
120+
121+
- Green ring around the elbow joint
122+
- Green arrow showing rotation direction
123+
- "Joint2" text label
124+
125+
- **⚪ White Reference Ring**: Fixed base reference point
126+
127+
These markers make it easy to visually confirm which joints are moving during manual control or animation.
128+
129+
## 🔧 ROS2 Topics
130+
131+
### Published Topics
132+
133+
- **`/joint_states`** (`sensor_msgs/msg/JointState`)
134+
- Joint names: `['joint1', 'joint2']`
135+
- Positions: Current joint angles in radians
136+
- Published at 10 Hz
137+
- Velocity and effort fields included (set to zero)
138+
139+
### Subscribed Topics
140+
141+
- **`/joint_states`** (`sensor_msgs/msg/JointState`)
142+
- Receives external joint commands
143+
- Updates visualization in real-time
144+
- Displays message frequency and count
145+
146+
### Monitoring Topics
147+
148+
To verify the demo is working correctly, you can monitor the published topics:
149+
150+
```bash
151+
# In a separate terminal, source ROS2 environment
152+
source /opt/ros/humble/setup.bash # or your ROS2 installation
153+
154+
# List all available topics
155+
ros2 topic list
156+
157+
# Monitor joint state messages
158+
ros2 topic echo /joint_states
159+
160+
# Check publishing frequency
161+
ros2 topic hz /joint_states
162+
163+
# View topic info
164+
ros2 topic info /joint_states
165+
```
166+
167+
## 🏗️ Architecture
168+
169+
### Main Process (`main.js`)
170+
171+
- **ROS2 Node Management**: Creates and manages the manipulator node
172+
- **Joint State Publishing**: Publishes current joint positions at 10 Hz
173+
- **Animation Control**: Handles smooth motion generation
174+
- **IPC Communication**: Bridges ROS2 data with renderer process
175+
176+
### Renderer Process (`renderer.js`)
177+
178+
- **3D Visualization**: Three.js scene with interactive manipulator model
179+
- **Visual Markers**: Color-coded rings, arrows, and labels for joint identification
180+
- **User Interface**: Control panels and status displays
181+
- **Real-time Updates**: Smooth joint motion and camera controls
182+
- **Message Handling**: Processes ROS2 data and user interactions
183+
184+
### Component Hierarchy
185+
186+
```
187+
Scene
188+
├── Lighting (Ambient + Directional + Point)
189+
├── Ground Plane
190+
├── Coordinate Axes
191+
├── Base (Fixed)
192+
├── Joint Markers (Red/Green Rings, Arrows, Labels)
193+
└── Joint1 Group (Rotates around Y-axis)
194+
├── Joint1 Sphere
195+
├── Link1 Cylinder
196+
└── Joint2 Group (Rotates around Z-axis)
197+
├── Joint2 Sphere
198+
├── Link2 Cylinder
199+
└── End Effector Cube
200+
```
201+
202+
## 🎯 Technical Details
203+
204+
### Joint Configuration
205+
206+
- **Joint 1 (Base)**: Revolute joint, Y-axis rotation, ±180° range
207+
- **Joint 2 (Elbow)**: Revolute joint, Z-axis rotation, ±135° range
208+
- **Forward Kinematics**: Hierarchical transformation chains
209+
- **Coordinate System**: Right-handed, Z-up convention
210+
211+
### Animation Patterns
212+
213+
```javascript
214+
// Sinusoidal motion with different frequencies (from main.js)
215+
joint1_angle = (sin(time * 1.0) * π) / 3; // ±60° at 1.0x speed
216+
joint2_angle = (sin(time * 1.5) * π) / 4; // ±45° at 1.5x speed
217+
```
218+
219+
### Performance
220+
221+
- **Rendering**: 60 FPS with requestAnimationFrame
222+
- **ROS2 Publishing**: 10 Hz joint state updates
223+
- **Animation**: 20 Hz smooth motion updates
224+
- **UI Updates**: Real-time slider and display synchronization
225+
226+
## 🛠️ Development
227+
228+
### File Structure
229+
230+
```
231+
manipulator/
232+
├── package.json # Dependencies and scripts
233+
├── main.js # Electron main process + ROS2 integration
234+
├── renderer.js # Three.js visualization + UI controls
235+
├── index.html # Application UI layout and styling
236+
├── start-demo.sh # Convenient ROS2 startup script
237+
├── README.md # This documentation
238+
├── VERSION_UPGRADE.md # rclnodejs upgrade details
239+
└── COMPLETION_SUMMARY.md # Implementation summary
240+
```
241+
242+
### Key Dependencies
243+
244+
- **electron**: `^31.7.7` - Desktop application framework
245+
- **rclnodejs**: `^1.5.1` - ROS2 JavaScript client library (latest compatible)
246+
- **@electron/rebuild**: `^3.7.2` - Native module rebuilding tool
247+
- **three.js**: `r128` - 3D graphics library (loaded via CDN)
248+
249+
### Debugging
250+
251+
- Press `F12` to open Developer Tools
252+
- Console logs show ROS2 initialization and message flow
253+
- Check ROS2 topics with: `ros2 topic list` and `ros2 topic echo /joint_states`
254+
255+
## 🔍 Troubleshooting
256+
257+
### Common Issues
258+
259+
1. **"librcl.so not found"**
260+
261+
```bash
262+
# Use the convenient script (recommended)
263+
npm run start-with-ros2
264+
265+
# Or manually source ROS2
266+
source /opt/ros/humble/setup.bash # or your ROS2 installation path
267+
npm start
268+
```
269+
270+
2. **Build errors with latest Electron**
271+
272+
- This demo uses Electron 31.7.7 for rclnodejs compatibility
273+
- Electron 38+ requires C++20, which rclnodejs doesn't support yet
274+
- The current versions are tested and stable
275+
276+
3. **No ROS2 messages received**
277+
278+
- Check if ROS2 daemon is running: `ros2 daemon start`
279+
- Verify topic exists: `ros2 topic list`
280+
- Check message flow: `ros2 topic echo /joint_states`
281+
282+
4. **Blank 3D scene**
283+
- Check browser console for Three.js errors
284+
- Ensure internet connection for Three.js CDN
285+
- Press F12 to open Developer Tools for debugging
286+
287+
### Performance Tips
288+
289+
- Reduce animation frequency for slower systems
290+
- Disable shadows in Three.js for better performance
291+
- Adjust rendering quality in renderer settings
292+
293+
## 📚 Learning Resources
294+
295+
- **ROS2 Concepts**: [ROS2 Documentation](https://docs.ros.org/en/humble/)
296+
- **Three.js Guide**: [Three.js Documentation](https://threejs.org/docs/)
297+
- **Electron Tutorials**: [Electron Documentation](https://electronjs.org/docs)
298+
- **rclnodejs API**: [rclnodejs Repository](https://github.com/RobotWebTools/rclnodejs)
299+
300+
## 🤝 Contributing
301+
302+
This demo is part of the rclnodejs project. Contributions welcome!
303+
304+
1. Fork the repository
305+
2. Create your feature branch
306+
3. Add tests for new functionality
307+
4. Submit a pull request
308+
309+
## 📄 License
310+
311+
Licensed under the Apache License, Version 2.0. See the main rclnodejs repository for details.

0 commit comments

Comments
 (0)