Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Unexpected behaviour of expression { } in command parameters.

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    12
    320
    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.
    • wackyfrogundefined
      wackyfrog
      last edited by wackyfrog

      Hi, David!

      It seems that not more that one expression can be used when it is necessary to specify several values, for instance:

      M581 P{var.myVar1}:{var.myVar2}:{var.myVar3} ...
      

      My test g-code:

      global x_axis_endstop_pin = 6
      global y_axis_left_endstop_pin = 7
      global y_axis_right_endstop_pin = 8
      global z_axis_endstop_pin = 9
      
      echo {global.x_axis_endstop_pin}
      echo {global.y_axis_left_endstop_pin}
      echo {global.y_axis_right_endstop_pin}
      echo {global.z_axis_endstop_pin}
      
      ; Emergency stop trigger on endstops hits
      M581 T8 R0 S1 P{global.x_axis_endstop_pin}:{global.y_axis_left_endstop_pin}:{global.y_axis_right_endstop_pin}:{global.z_axis_endstop_pin}
      

      Only the first pin triggers when its state changes. The rest 3 specified pins does not cause the trigger.

      Am I use wrong syntax or it is a bug ?

      Echoed values are correct, additionally I have checked them in the object viewer.

      And all 4 pins work correctly only when I specify them manually, like this:

      M581 T8 R0 S1 P6:7:8:9
      

      Board: Duet 2 WiFi (2WiFi)
      Firmware: RepRapFirmware for Duet 2 WiFi/Ethernet 3.4.0beta5 (2021-10-12)

      Thank you very much!

      dc42undefined 1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @wackyfrog
        last edited by

        @adegtiar I have updated https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Use_of_expressions_within_GCode_commands to show the correct syntax.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        1 Reply Last reply Reply Quote 0
        • wackyfrogundefined
          wackyfrog
          last edited by

          @dc42 said in Unexpected behaviour of expression { } in command parameters.:

          @adegtiar I have updated https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Use_of_expressions_within_GCode_commands to show the correct syntax.

          I have tried that syntax, but got an error:

          M581 T9 R0 S1 P{global.x_axis_endstop_pin, global.y_axis_left_endstop_pin, global.y_axis_right_endstop_pin, global.z_axis_endstop_pin}
          
          Error: M581: expected '}'
          
          jay_s_ukundefined 1 Reply Last reply Reply Quote 0
          • jay_s_ukundefined
            jay_s_uk @wackyfrog
            last edited by

            @adegtiar there should be + in between , not a ,

            Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

            wackyfrogundefined 1 Reply Last reply Reply Quote 2
            • wackyfrogundefined
              wackyfrog @jay_s_uk
              last edited by

              @jay_s_uk said in Unexpected behaviour of expression { } in command parameters.:

              @adegtiar there should be + in between , not a ,

              Thank you! It works 👍

              1 Reply Last reply Reply Quote 0
              • wackyfrogundefined
                wackyfrog
                last edited by wackyfrog

                Returning to the question, I found that the solution still does not work.

                Tested on Firmware: RepRapFirmware for Duet 2 WiFi/Ethernet 3.4.0 (2022-03-15)

                Operator '+' just summarizes pins values and as result I have one pin number 30 instead of 4 pins (6:7:8:9)

                G-CODE to reproduce

                ; Variables
                global x_axis_endstop_pin = 6
                global y_axis_left_endstop_pin = 7
                global y_axis_right_endstop_pin = 8
                global z_axis_endstop_pin = 9
                
                
                ; remove all pins from trigger
                M581 T9 P-1
                
                ; check the trigger configuration
                M581 T9
                Result: Trigger 9 is not configured
                
                ; setup new pins
                M581 T9 R0 S1 P{global.x_axis_endstop_pin + global.y_axis_left_endstop_pin + global.y_axis_right_endstop_pin + global.z_axis_endstop_pin}
                
                ;  check what we have
                M581 T9
                Result: Trigger 9 fires on a rising edge of endstops/inputs 30
                
                dc42undefined 1 Reply Last reply Reply Quote 0
                • dc42undefined
                  dc42 administrators @wackyfrog
                  last edited by dc42

                  @wackyfrog the M581 P parameter is a single string so you need to concatenate the various parts using ^. Try this:

                  M581 T9 R0 S1 P{global.x_axis_endstop_pin ^ "+" ^ global.y_axis_left_endstop_pin ^ "+" ^ global.y_axis_right_endstop_pin ^ "+" ^ global.z_axis_endstop_pin}
                  

                  Duet WiFi hardware designer and firmware engineer
                  Please do not ask me for Duet support via PM or email, use the forum
                  http://www.escher3d.com, https://miscsolutions.wordpress.com

                  wackyfrogundefined 1 Reply Last reply Reply Quote 0
                  • wackyfrogundefined
                    wackyfrog @dc42
                    last edited by

                    @dc42 I've got the error:

                    M581 T9 R0 S1 P{global.x_axis_endstop_pin ^ "+" ^ global.y_axis_left_endstop_pin ^ "+" ^ global.y_axis_right_endstop_pin ^ "+" ^ global.z_axis_endstop_pin}
                    Error: M581: expected integer value
                    
                    1 Reply Last reply Reply Quote 0
                    • wackyfrogundefined
                      wackyfrog
                      last edited by

                      As a workaround, I'm currently using the code below, but I would like to figure out how to correctly pass multiple values using variables in such parameters.

                      M581 T9 P-1
                      M581 T9 R0 S1 P{global.x_axis_endstop_pin}
                      M581 T9 R0 S1 P{global.y_axis_left_endstop_pin}
                      M581 T9 R0 S1 P{global.y_axis_right_endstop_pin}
                      M581 T9 R0 S1 P{global.z_axis_endstop_pin}
                      M581 T9
                      
                      Result: Trigger 9 fires on a rising edge of endstops/inputs 6 7 8 9
                      
                      dc42undefined 2 Replies Last reply Reply Quote 0
                      • dc42undefined
                        dc42 administrators @wackyfrog
                        last edited by

                        @wackyfrog I'm sorry, I made a mistake. In RRF 3.4 the M581 P parameter is a list of pin numbers that you created using M950 with the J parameter. So this command from your earlier post should work under firmware 3.4:

                        M581 T9 R0 S1 P{global.x_axis_endstop_pin, global.y_axis_left_endstop_pin, global.y_axis_right_endstop_pin, global.z_axis_endstop_pin}
                        

                        But I've just tested it, and I get the same error that you reported. I am investigating why.

                        Duet WiFi hardware designer and firmware engineer
                        Please do not ask me for Duet support via PM or email, use the forum
                        http://www.escher3d.com, https://miscsolutions.wordpress.com

                        1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators @wackyfrog
                          last edited by

                          @wackyfrog I found and fixed the problem. The fix will be in the 3.4.1 release.

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          wackyfrogundefined 1 Reply Last reply Reply Quote 0
                          • wackyfrogundefined
                            wackyfrog @dc42
                            last edited by

                            @dc42 Thanks, David!

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