Python control of Duet 2 via network?
-
Hi All,
Looking to do some vision work on a Single Board Computer which will use OpenCV to locate a target start point and trigger a repeat print.
This will be a repeated loop; scanning an image for a feature, moving the head to centralise the feature.
What is the current best supported way to achieve the single board computer to duet communications? Just fire network commands as a prototype? The system is using an expansion board.
-
After a couple of hours hunting I can see the direct method of connecting a Single Board Computer to the Duet 2 is not feasible. It involves removing the ethernet or wifi adaptor and making connections there.
Looking for guidance on controlling a Duet 2 from a Python Script rather than through the DWC, or more accurately alongside a normal DWC connection. It's likely that the build process would be triggered by a Macros.
-
@doctrucker You can turn on the telnet server on the Duet board and make a socket connection and send GCODE commands.
I don't know what you are trying to do, so I don't know if this helps or not.
This is someone who wanted to read from the Duet using Python. You can both send and receive using this socket from Python.
https://forum.duet3d.com/topic/27396/basic-telnet-connection-help/5?_=1645538054606
-
@alankilian That'll do nicely thanks.
I'll setup a macro that fires a message to the SBC then that will run a loop of imaging, calculating a required offset, and returning a G1 command until the required offset is within a set parameter. At that point the SBC will trigger a build gcode file and the process repeats a few times to copy a build at a number of semi-regular (hence need for camera) locations.
-
@doctrucker Most industrial CV for object location changes the coordinate system. In theory you can do this with the Duet, although I haven't looked into rotating the coordinate system yet. In this case the gcode from your SBC would change the translation and rotation values of the part coordinate system, and then the gcode file would stay the same.
-
@theolodian I've tested a macro that uses the gcode variables and coding to read in a set location and adjust the G10 tool offsets to make the current location 0,0. This did a regular grid of prints, the computer vision will be used to fettle the expected position to account for work piece variance. There may be a more elegant way of doing it with co-ordinate systems too, but I have something functional to work from initially.
-
@doctrucker OK, I may get corrected but: yes what you are doing will work if the parts are all in the same orientation. If you also need to rotate the print then you need to use coordinate system offsets instead, but otherwise it works in the same way that you are using tool offsets.
-
@theolodian good point, I'll read up on the coordinate system method another time. The printer is running in FFF rather than CNC mode which may complicate things a little, but can't see why you'd limit that feature to CNC - even if the request came from there.
As it happens I'm just aiming for the middle of a circular-ish feature, so rotation not an issue this time thankfully.
Here was what I had in the macro:
; https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Variable_naming ; https://duet3d.dozuki.com/Wiki/Object_Model_of_RepRapFirmware#Section_Uses ; https://forum.duet3d.com/topic/26368/object-model-report-contents-of-object ; https://forum.duet3d.com/topic/26370/sanity-check-tool-offsets-g10-p0-x var num_x_pattern = 3 var num_y_pattern = 2 var x_pattern_space = 50.0 var y_pattern_space = 25.0 var tool_num = 0 var int_x = move.axes[0].machinePosition var int_y = move.axes[1].machinePosition var initial_x_offset = tools[var.tool_num].offsets[0] var initial_y_offset = tools[var.tool_num].offsets[0] M98 P"0:/macros/intro.g" while true if iterations = (var.num_x_pattern * var.num_y_pattern) break else var x_i = mod(iterations, var.num_x_pattern) var y_i = ((iterations-var.x_i)/var.num_x_pattern) var x_pos = var.int_x + (var.x_i * var.x_pattern_space) var y_pos = var.int_y + (var.y_i * var.y_pattern_space) G10 P0 X{(-1 * var.x_pos)} Y{(-1 * var.y_pos)} M98 P"0:/gcodes/sample_build.g" continue G10 P0 X{(-1 * var.initial_x_offset)} Y{(-1 * var.initial_y_offset)} M98 P"0:/macros/extro.g"