@holoscript/robotics-plugin 1.0.0
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.
- package/README.md +3 -0
- package/dist/ast.d.ts +21 -0
- package/dist/ast.js +5 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +44 -0
- package/dist/lexer.d.ts +52 -0
- package/dist/lexer.js +275 -0
- package/dist/parser.d.ts +22 -0
- package/dist/parser.js +202 -0
- package/dist/usd-codegen.d.ts +18 -0
- package/dist/usd-codegen.js +361 -0
- package/examples/robot-arm-complete.holo +199 -0
- package/package.json +66 -0
- package/python/ros2_bridge.py +77 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
ROS2 Bridge for HoloScript Robotics Plugin
|
|
4
|
+
Runtime integration with ROS2 via rosbridge_server
|
|
5
|
+
|
|
6
|
+
Requirements:
|
|
7
|
+
pip install roslibpy
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
from ros2_bridge import ROS2Bridge
|
|
11
|
+
|
|
12
|
+
bridge = ROS2Bridge('ws://localhost:9090')
|
|
13
|
+
bridge.connect()
|
|
14
|
+
bridge.publish_joint_command('/joint_states', {...})
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import sys
|
|
18
|
+
import json
|
|
19
|
+
from typing import Dict, Any, List
|
|
20
|
+
import roslibpy
|
|
21
|
+
|
|
22
|
+
class ROS2Bridge:
|
|
23
|
+
"""ROS2 runtime bridge for HoloScript robotics"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, ros_bridge_url: str = 'ws://localhost:9090'):
|
|
26
|
+
self.ros_bridge_url = ros_bridge_url
|
|
27
|
+
self.client = None
|
|
28
|
+
self.subscribers = {}
|
|
29
|
+
self.publishers = {}
|
|
30
|
+
|
|
31
|
+
def connect(self) -> Dict[str, Any]:
|
|
32
|
+
"""Connect to ROS2 via rosbridge_server"""
|
|
33
|
+
try:
|
|
34
|
+
self.client = roslibpy.Ros(host=self.ros_bridge_url.replace('ws://', '').split(':')[0],
|
|
35
|
+
port=int(self.ros_bridge_url.split(':')[-1]))
|
|
36
|
+
self.client.run()
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
'status': 'success',
|
|
40
|
+
'connected': self.client.is_connected,
|
|
41
|
+
'url': self.ros_bridge_url,
|
|
42
|
+
}
|
|
43
|
+
except Exception as e:
|
|
44
|
+
return {
|
|
45
|
+
'status': 'failed',
|
|
46
|
+
'error': str(e),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
def publish_joint_command(self, topic: str, joint_positions: Dict[str, float]) -> Dict[str, Any]:
|
|
50
|
+
"""Publish joint command to ROS2 topic"""
|
|
51
|
+
try:
|
|
52
|
+
if topic not in self.publishers:
|
|
53
|
+
self.publishers[topic] = roslibpy.Topic(self.client, topic, 'sensor_msgs/JointState')
|
|
54
|
+
|
|
55
|
+
msg = {
|
|
56
|
+
'name': list(joint_positions.keys()),
|
|
57
|
+
'position': list(joint_positions.values()),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
self.publishers[topic].publish(roslibpy.Message(msg))
|
|
61
|
+
|
|
62
|
+
return {'status': 'success', 'topic': topic}
|
|
63
|
+
except Exception as e:
|
|
64
|
+
return {'status': 'failed', 'error': str(e)}
|
|
65
|
+
|
|
66
|
+
def get_status(self) -> Dict[str, Any]:
|
|
67
|
+
"""Get bridge status"""
|
|
68
|
+
return {
|
|
69
|
+
'connected': self.client.is_connected if self.client else False,
|
|
70
|
+
'url': self.ros_bridge_url,
|
|
71
|
+
'version': '1.0.0',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if __name__ == '__main__':
|
|
75
|
+
bridge = ROS2Bridge()
|
|
76
|
+
status = bridge.connect()
|
|
77
|
+
print(f"ROS2 Bridge: {status}")
|