grbl
plantimager.grbl Link
Implementation of a CNC module adapted to Grbl motherboard.
The CNC is used to move a multi-purpose arm. It offers 3-axis of movements.
CNC Link
CNC(port='/dev/ttyUSB0', baudrate=115200, homing=True, safe_start=True, x_lims=None, y_lims=None, z_lims=None, invert_x=True, invert_y=True, invert_z=True)
Bases: AbstractCNC
CNC functionalities.
Attributes:
Name | Type | Description |
---|---|---|
port |
str
|
Serial port to use for communication with the CNC controller (Arduino UNO). |
baudrate |
int
|
Communication baud rate, |
homing |
bool
|
If |
x_lims |
(int, int)
|
The allowed range of X-axis positions. |
y_lims |
(int, int)
|
The allowed range of Y-axis positions. |
z_lims |
(int, int)
|
The allowed range of Z-axis positions. |
serial_port |
Serial
|
The |
x |
int
|
The current position, in millimeter, of the CNC arm on the X-axis. |
y |
int
|
The current position, in millimeter, of the CNC arm on the Y-axis. |
z |
int
|
The current position, in millimeter, of the CNC arm on the Z-axis. |
invert_x |
bool
|
If |
invert_y |
bool
|
If |
invert_z |
bool
|
If |
References
http://linuxcnc.org/docs/html/gcode/g-code.html
See Also
plantimager.hal.AbstractCNC
Examples:
>>> from plantimager.grbl import CNC
>>> cnc = CNC("/dev/ttyACM0",x_lims=[0, 780],y_lims=[0, 780],z_lims=[0, 90])
>>> cnc.moveto(200, 200, 50) # move the CNC to this XYZ coordinate (in mm)
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port
|
str
|
Serial port to use for communication with the CNC controller.
This can also be a regular expression to identify in a unique way the corresponding port.
Defaults to |
'/dev/ttyUSB0'
|
baudrate
|
int
|
Communication baud rate, |
115200
|
homing
|
bool
|
If |
True
|
safe_start
|
bool
|
If |
True
|
x_lims
|
(int, int)
|
The allowed range of X-axis positions, if |
None
|
y_lims
|
(int, int)
|
The allowed range of Y-axis positions, if |
None
|
z_lims
|
(int, int)
|
The allowed range of Z-axis positions, if |
None
|
invert_x
|
bool
|
If |
True
|
invert_y
|
bool
|
If |
True
|
invert_z
|
bool
|
If |
True
|
Examples:
>>> from plantimager.grbl import CNC
>>> cnc = CNC("Arduino",x_lims=[0, 780],y_lims=[0, 780],z_lims=[0, 90])
>>> cnc.moveto(200, 200, 50) # move the CNC to this XYZ coordinate (in mm)
>>> cnc.home() # homing command (automatically called on startup)
>>> cnc.moveto_async(200, 200, 50)
>>> cnc.send_cmd("$$") # send a Grbl command, here "$$"
>>> cnc.print_grbl_settings() # Get Grbl settings from the firmware
>>> cnc.stop() # close the serial connection
Source code in plantimager/grbl.py
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 |
|
_check_axes_limits Link
_check_axes_limits(axis_limits, grbl_limits, axis_name)
Make sure given axe_limits
are within grbl_limits
(firmware limits).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis_limits
|
[float, float]
|
Axis limits to use. |
required |
grbl_limits
|
[float, float]
|
Limits knwon to Grbl firmaware ("$130", "$131" & "$132" in |
required |
axis_name
|
str
|
Name of the axis currently checked. |
required |
See Also
GRBL_SETTINGS
Raises:
Type | Description |
---|---|
ValueError
|
If given |
Examples:
>>> from plantimager.grbl import CNC
>>> cnc = CNC("/dev/ttyACM0")
>>> grbl = cnc.get_grbl_settings()
>>> print(f"Grbl axes limits are: X=[0, {grbl['$130']}], Y=[0, {grbl['$131']}], Z=[0, {grbl['$132']}]")
>>> wrong_cnc = CNC("/dev/ttyACM0",x_lims=[-1, 780],y_lims=[0, 780],z_lims=[0, 90])
Source code in plantimager/grbl.py
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 |
|
_check_move Link
_check_move(x, y, z)
Make sure the moveto
coordinates are within the axes limits.
Source code in plantimager/grbl.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
_start Link
_start(homing=True, safe_start=True)
Start the serial connection with the Arduino & initialize the CNC (hardware).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
homing
|
bool
|
If |
True
|
safe_start
|
bool
|
If |
True
|
References
http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g90-g91 http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g20-g21
Source code in plantimager/grbl.py
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 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
get_grbl_settings Link
get_grbl_settings()
Returns the Grbl settings as a dictionary {'param': value}.
Source code in plantimager/grbl.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
get_position Link
get_position()
Returns the x, y & z positions of the CNC.
Source code in plantimager/grbl.py
277 278 279 |
|
get_status Link
get_status()
Returns Grbl status.
Source code in plantimager/grbl.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
home Link
home()
Performs axes homing procedure.
References
https://github.com/gnea/grbl/wiki/Grbl-v1.1-Commands#h---run-homing-cycle http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g92
Source code in plantimager/grbl.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
moveto Link
moveto(x, y, z)
Send a 'G0' move command and wait until reaching target XYZ position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
The target position, in millimeters, along the X-axis. |
required |
y
|
int
|
The target position, in millimeters, along the Y-axis. |
required |
z
|
int
|
The target position, in millimeters, along the Z-axis. |
required |
Source code in plantimager/grbl.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
moveto_async Link
moveto_async(x, y, z)
Send a non-blocking 'G0' move command to target XYZ position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
The target position, in millimeters, along the X-axis. |
required |
y
|
int
|
The target position, in millimeters, along the Y-axis. |
required |
z
|
int
|
The target position, in millimeters, along the Z-axis. |
required |
References
http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g0
Source code in plantimager/grbl.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
print_grbl_settings Link
print_grbl_settings()
Print the Grbl settings.
See Also
GRBL_SETTINGS
References
https://github.com/gnea/grbl/wiki/Grbl-v1.1-Configuration#grbl-settings
Source code in plantimager/grbl.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
send_cmd Link
send_cmd(cmd)
Send given command to Grbl.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd
|
str
|
A Grbl compatible command. |
required |
References
https://github.com/gnea/grbl/wiki/Grbl-v1.1-Commands
Source code in plantimager/grbl.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
stop Link
stop()
Close the serial connection.
Source code in plantimager/grbl.py
271 272 273 274 275 |
|
wait Link
wait()
Send a 1-second wait (dwell) command to Grbl.
References
http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g4
Source code in plantimager/grbl.py
360 361 362 363 364 365 366 367 368 369 |
|