-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
256 lines (203 loc) · 8.3 KB
/
example.py
File metadata and controls
256 lines (203 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python3
"""
Example usage of Gocator Interface with GoSDK
This example demonstrates how to:
1. Connect to a Gocator sensor
2. Configure sensor parameters
3. Acquire point cloud data
4. Process and save point clouds
"""
from gocator import GocatorScanner
import numpy as np
# Configure your sensor IP address
IP = "192.168.100.125"
# SDK path is auto-detected from common installation locations
# If needed, specify manually for your system:
# Linux: SDK_PATH = "/opt/lmi/gocator/lib/libGoSdk.so"
# Windows: SDK_PATH = "C:\\Program Files\\LMI Technologies\\Gocator\\lib\\GoSdk.dll"
# macOS: SDK_PATH = "/usr/local/lib/libGoSdk.dylib"
SDK_PATH = None # None for auto-detection
def example_basic_connection():
"""Basic connection and single scan example with software triggering."""
print("=" * 60)
print("Example 1: Basic Connection and Software-Triggered Scan")
print("=" * 60)
# SDK path is auto-detected from common installation locations
# Or specify manually: sdk_path="/path/to/libGoSdk.so"
scanner = GocatorScanner(
ip_address=IP,
sdk_path=SDK_PATH
)
try:
if scanner.connect():
# Get sensor information
info = scanner.get_sensor_info()
print("\nSensor Info:")
print(f" Model: {info['model']}")
print(f" Serial: {info['serial_number']}")
print(f" IP: {info['ip_address']}")
# Start the acquisition system
print("\nStarting acquisition system...")
scanner.start()
# Software trigger the sensor
print("Sending software trigger...")
if scanner.trigger():
print("Trigger sent successfully")
# Wait for and receive the triggered scan
print("Waiting for point cloud data...")
point_cloud = scanner.get_point_cloud()
if point_cloud is not None:
print(f"\nReceived {len(point_cloud)} points")
print(f"Shape: {point_cloud.shape}")
print(f"Data type: {point_cloud.dtype}")
# Save point cloud to files
print("\nSaving point cloud to files...")
# Save as NumPy binary
np.save("point_cloud.npy", point_cloud)
print(" ✓ Saved to point_cloud.npy")
# Save as CSV
np.savetxt(
"point_cloud.csv", point_cloud,
delimiter=",",
header="X,Y,Z",
comments="",
fmt="%.6f"
)
print(" ✓ Saved to point_cloud.csv")
# Save as PLY
save_ply("point_cloud.ply", point_cloud)
print(" ✓ Saved to point_cloud.ply")
else:
print("\nNote: If no data received, ensure sensor is configured for:")
print(" - Trigger Mode: Software or Time")
print(" - Output: Surface data enabled")
else:
print("Failed to trigger sensor")
# Stop the acquisition system
scanner.stop()
scanner.disconnect()
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
def example_context_manager():
"""Using context manager for automatic connection/disconnection."""
print("\n" + "=" * 60)
print("Example 2: Context Manager Usage")
print("=" * 60)
with GocatorScanner(IP, SDK_PATH) as scanner:
# Convenience method: start, get data, and stop
point_cloud = scanner.scan_and_get()
if point_cloud is not None:
print(f"\nReceived {len(point_cloud)} points")
# Analyze point cloud
print("\nPoint Cloud Statistics:")
print(f" X: min={point_cloud[:, 0].min():.6f}, max={point_cloud[:, 0].max():.6f}")
print(f" Y: min={point_cloud[:, 1].min():.6f}, max={point_cloud[:, 1].max():.6f}")
print(f" Z: min={point_cloud[:, 2].min():.6f}, max={point_cloud[:, 2].max():.6f}")
def example_configure_parameters():
"""Configure sensor parameters before scanning."""
print("\n" + "=" * 60)
print("Example 3: Configure Sensor Parameters")
print("=" * 60)
with GocatorScanner(IP, SDK_PATH) as scanner:
# Get current settings
current_exposure = scanner.get_exposure()
current_spacing = scanner.get_spacing_interval()
print("\nCurrent Settings:")
print(f" Exposure: {current_exposure:.2f} µs")
print(f" Spacing Interval: {current_spacing:.6f} mm")
# Set new parameters
print("\nConfiguring sensor...")
scanner.set_exposure(100.0) # 100 microseconds
scanner.set_spacing_interval(0.5) # 0.5 mm
# Verify new settings
new_exposure = scanner.get_exposure()
new_spacing = scanner.get_spacing_interval()
print("\nNew Settings:")
print(f" Exposure: {new_exposure:.2f} µs")
print(f" Spacing Interval: {new_spacing:.6f} mm")
# Acquire with new settings
point_cloud = scanner.scan_and_get()
if point_cloud is not None:
print(f"\nAcquired {len(point_cloud)} points with new settings")
def example_multiple_scans():
"""Acquire multiple scans continuously."""
print("\n" + "=" * 60)
print("Example 4: Multiple Continuous Scans")
print("=" * 60)
with GocatorScanner(IP, SDK_PATH) as scanner:
scanner.start()
num_scans = 5
point_clouds = []
for i in range(num_scans):
print(f"\nAcquiring scan {i+1}/{num_scans}...")
point_cloud = scanner.get_point_cloud(timeout_us=10000000) # 10 sec timeout
if point_cloud is not None:
point_clouds.append(point_cloud)
print(f" Points: {len(point_cloud)}")
else:
print(f" Failed to acquire scan {i+1}")
scanner.stop()
print(f"\nSuccessfully acquired {len(point_clouds)} scans")
# Combine all point clouds
if point_clouds:
combined = np.vstack(point_clouds)
print(f"Combined point cloud: {len(combined)} points")
def example_save_point_cloud():
"""Save point cloud to file formats."""
print("\n" + "=" * 60)
print("Example 5: Save Point Cloud to Files")
print("=" * 60)
with GocatorScanner(IP, SDK_PATH) as scanner:
point_cloud = scanner.scan_and_get()
if point_cloud is not None:
# Save as NumPy binary
np.save("point_cloud.npy", point_cloud)
print("Saved to point_cloud.npy")
# Save as text (CSV format)
np.savetxt(
"point_cloud.csv", point_cloud,
delimiter=",",
header="X,Y,Z",
comments="",
fmt="%.6f"
)
print("Saved to point_cloud.csv")
# Save as PLY (common 3D format)
save_ply("point_cloud.ply", point_cloud)
print("Saved to point_cloud.ply")
def save_ply(filename: str, points: np.ndarray):
"""
Save point cloud to PLY format.
Args:
filename: Output file path
points: Nx3 numpy array of XYZ coordinates
"""
with open(filename, 'w') as f:
# PLY header
f.write("ply\n")
f.write("format ascii 1.0\n")
f.write(f"element vertex {len(points)}\n")
f.write("property float x\n")
f.write("property float y\n")
f.write("property float z\n")
f.write("end_header\n")
# Point data
for point in points:
f.write(f"{point[0]:.6f} {point[1]:.6f} {point[2]:.6f}\n")
if __name__ == "__main__":
print("Gocator SDK Python Interface Examples")
print("Make sure the Gocator SDK is installed and the sensor is connected")
print()
# Run examples (comment out examples you don't want to run)
try:
example_basic_connection()
# example_context_manager()
# example_configure_parameters()
# example_multiple_scans()
# example_save_point_cloud()
except Exception as e:
print(f"\nExample failed: {e}")
import traceback
traceback.print_exc()