dummy_cnc
plantimager.controller.scanner.dummy_cnc Link
Dummy CNC Implementation for Plant Imaging Systems.
A simulated CNC controller that mimics the behavior of a real GRBL-based CNC machine without requiring actual hardware. This is useful for development, testing, and demonstration purposes when physical hardware is unavailable.
Key Features: - Simulates all standard CNC operations (movement, homing, positioning) - Implements the AbstractCNC interface for compatibility with scanner code - Adds realistic delays and position noise to mimic real hardware behavior - Provides status reporting and command handling like a real GRBL controller - Enforces position limits and validates movement commands - Thread-safe asynchronous operation support
Usage Examples:
>>> from plantimager.controller.scanner.dummy_cnc import DummyCNC
>>> # Initialize the dummy CNC
>>> cnc = DummyCNC()
>>> # Perform operations just like with a real CNC
>>> cnc.home()
>>> cnc.moveto(100, 100, 45)
>>> x, y, z = cnc.get_position()
>>> print(f"Current position: ({x}, {y}, {z})")
>>> # Async movement
>>> cnc.moveto_async(200, 200, 90)
>>> # Do other things...
>>> cnc.wait() # Wait for movement to complete
DummyCNC Link
DummyCNC(x_limits=(0, 740), y_limits=(0, 740), z_limits=(0, 360))
Bases: AbstractCNC
A dummy implementation of CNC machine control for testing purposes.
This class mimics the behavior of the real CNC class without connecting to actual hardware. It simulates basic CNC operations like movement, positioning, and homing.
Attributes:
Name | Type | Description |
---|---|---|
x_lims |
tuple[float, float]
|
Allowed range for X-axis movement |
y_lims |
tuple[float, float]
|
Allowed range for Y-axis movement |
z_lims |
tuple[float, float]
|
Allowed range for Z-axis movement (rotational axis) |
_position |
tuple[float, float, float]
|
Current position (x, y, z) |
_busy |
bool
|
Flag indicating if the CNC is currently moving |
Initialize the dummy CNC controller with default axis limits.
Source code in plantimager/controller/scanner/dummy_cnc.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
get_position Link
get_position()
Get the current XYZ position of the dummy CNC machine.
Returns:
Type | Description |
---|---|
length_mm
|
Current X-axis position in millimeters |
length_mm
|
Current Y-axis position in millimeters |
deg
|
Current Z-axis position in degrees |
Source code in plantimager/controller/scanner/dummy_cnc.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
get_status Link
get_status()
Simulate querying the current status of the GRBL controller.
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing simulated status information |
Source code in plantimager/controller/scanner/dummy_cnc.py
279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
home Link
home()
Simulate performing a homing cycle.
Sets the current position to a starting point near the origin, simulating the behavior of the real CNC homing procedure.
Source code in plantimager/controller/scanner/dummy_cnc.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
moveto Link
moveto(x, y, z)
Move the dummy CNC machine to specified coordinates and wait until the target position is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
length_mm
|
Target position along the X-axis in millimeters |
required |
y
|
length_mm
|
Target position along the Y-axis in millimeters |
required |
z
|
deg
|
Target position along the Z-axis in degrees |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the target coordinates are outside the allowed limits |
Source code in plantimager/controller/scanner/dummy_cnc.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
moveto_async Link
moveto_async(x, y, z)
Asynchronously move the dummy CNC machine to specified coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
length_mm
|
Target position along the X-axis in millimeters |
required |
y
|
length_mm
|
Target position along the Y-axis in millimeters |
required |
z
|
deg
|
Target position along the Z-axis in degrees |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the target coordinates are outside the allowed limits |
Source code in plantimager/controller/scanner/dummy_cnc.py
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 |
|
send_cmd Link
send_cmd(cmd)
Simulate sending a command to the GRBL controller.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd
|
str
|
A GRBL-compatible G-code command or system command |
required |
Returns:
Type | Description |
---|---|
str
|
Simulated response from the controller |
Source code in plantimager/controller/scanner/dummy_cnc.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
stop Link
stop()
Stop the dummy CNC and clean up resources.
Source code in plantimager/controller/scanner/dummy_cnc.py
256 257 258 259 |
|
wait Link
wait(timeout=60)
Wait for the dummy CNC machine to complete any ongoing operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
Maximum time to wait in seconds, by default 60 |
60
|
Raises:
Type | Description |
---|---|
TimeoutError
|
If the simulated movement doesn't complete within the timeout |
Source code in plantimager/controller/scanner/dummy_cnc.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|