Duet3D Logo

    Duet3D

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Documentation
    • Order

    Python control of Duet 2 via network?

    General Discussion
    3
    8
    261
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DocTrucker
      DocTrucker last edited by DocTrucker

      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.

      Alive: 1 Ormerodish machines. 1 Custom Cantilever. 3 P3Steel. 1 Ciclopish scanner. In build: 1 P3Steel. Controllers: 2 Duet 2 , 2 D0.6, 1 D0.8.5, 1 D3 v0.5, 1 RAMPS/DRV8825, 1 Uno/Scan Card.

      1 Reply Last reply Reply Quote 0
      • DocTrucker
        DocTrucker last edited by

        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.

        Alive: 1 Ormerodish machines. 1 Custom Cantilever. 3 P3Steel. 1 Ciclopish scanner. In build: 1 P3Steel. Controllers: 2 Duet 2 , 2 D0.6, 1 D0.8.5, 1 D3 v0.5, 1 RAMPS/DRV8825, 1 Uno/Scan Card.

        alankilian 1 Reply Last reply Reply Quote 0
        • alankilian
          alankilian @DocTrucker last edited by

          @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

          SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

          DocTrucker 1 Reply Last reply Reply Quote 2
          • DocTrucker
            DocTrucker @alankilian last edited by

            @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.

            Alive: 1 Ormerodish machines. 1 Custom Cantilever. 3 P3Steel. 1 Ciclopish scanner. In build: 1 P3Steel. Controllers: 2 Duet 2 , 2 D0.6, 1 D0.8.5, 1 D3 v0.5, 1 RAMPS/DRV8825, 1 Uno/Scan Card.

            theolodian 1 Reply Last reply Reply Quote 0
            • theolodian
              theolodian @DocTrucker last edited by

              @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.

              DocTrucker 1 Reply Last reply Reply Quote 0
              • DocTrucker
                DocTrucker @theolodian last edited by

                @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.

                Alive: 1 Ormerodish machines. 1 Custom Cantilever. 3 P3Steel. 1 Ciclopish scanner. In build: 1 P3Steel. Controllers: 2 Duet 2 , 2 D0.6, 1 D0.8.5, 1 D3 v0.5, 1 RAMPS/DRV8825, 1 Uno/Scan Card.

                theolodian 1 Reply Last reply Reply Quote 0
                • theolodian
                  theolodian @DocTrucker last edited by

                  @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.

                  DocTrucker 1 Reply Last reply Reply Quote 1
                  • DocTrucker
                    DocTrucker @theolodian last edited by DocTrucker

                    @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"
                    

                    Alive: 1 Ormerodish machines. 1 Custom Cantilever. 3 P3Steel. 1 Ciclopish scanner. In build: 1 P3Steel. Controllers: 2 Duet 2 , 2 D0.6, 1 D0.8.5, 1 D3 v0.5, 1 RAMPS/DRV8825, 1 Uno/Scan Card.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    Unless otherwise noted, all forum content is licensed under CC-BY-SA