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