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

    Problem using functions

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    4
    21
    762
    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.
    • Phaedruxundefined
      Phaedrux Moderator
      last edited by

      I mean can you post the actual file so we can see the actual text contents?

      Z-Bot CoreXY Build | Thingiverse Profile

      anaghundefined 1 Reply Last reply Reply Quote 0
      • anaghundefined
        anagh @Phaedrux
        last edited by anagh

        @phaedrux This might be me doing something silly or missing something. I downloaded the macro file on my computer. Now I am trying to go to "upload file" and select the macro file, but it keeps saying invalid file format.
        Also, the macro file contains only this line and no other text in it. I tried sending this same line using the console as well but I get a similar error:
        Error: meta command: unknown value 'sin'

        Phaedruxundefined 1 Reply Last reply Reply Quote 0
        • infiniteloopundefined
          infiniteloop @anagh
          last edited by

          @anagh said in Problem using functions:

          var testValue = sin(50)

          Being just curious: do you run your Duet in CNC mode?

          anaghundefined 1 Reply Last reply Reply Quote 0
          • anaghundefined
            anagh @infiniteloop
            last edited by

            @infiniteloop yes.

            infiniteloopundefined 1 Reply Last reply Reply Quote 0
            • infiniteloopundefined
              infiniteloop @anagh
              last edited by

              @anagh OK. I just had a look at the documentation, it says:

              Sub-expressions may be enclosed in { } or in ( ). However, standard CNC GCode uses ( ) to enclose comments. So in CNC mode, RepRapFirmware treats ( ) as enclosing subexpressions when they appear inside { } and as enclosing comments when they do not. Therefore, when RepRapFirmware is running in CNC mode, any use of ( ) to enclose a subexpression or function parameter list must be within an expression enclosed in { }.

              Try to enclose the expression in curly braces like this:

              var testValue = { sin(50) }
              
              Phaedruxundefined 1 Reply Last reply Reply Quote 1
              • Phaedruxundefined
                Phaedrux Moderator @anagh
                last edited by

                @anagh said in Problem using functions:

                but it keeps saying invalid file format.

                What file extension does it have?

                How did you create the file in the first place?

                Can you test this macro?

                testsinmacro.g

                Z-Bot CoreXY Build | Thingiverse Profile

                anaghundefined 1 Reply Last reply Reply Quote 0
                • Phaedruxundefined
                  Phaedrux Moderator @infiniteloop
                  last edited by

                  @infiniteloop good catch

                  Z-Bot CoreXY Build | Thingiverse Profile

                  infiniteloopundefined anaghundefined 2 Replies Last reply Reply Quote 0
                  • infiniteloopundefined
                    infiniteloop @Phaedrux
                    last edited by

                    @phaedrux said in Problem using functions:

                    good catch

                    Let's wait what happens …

                    1 Reply Last reply Reply Quote 0
                    • anaghundefined
                      anagh @Phaedrux
                      last edited by anagh

                      @phaedrux I created the file by going to the macros tab, then "New File" and then writing this line in the file.
                      I tested the macro you uploaded. Here is the error message:
                      M98 P"0:/macros/testsinmacro.g"
                      Error: in file macro line 1 column 17: meta command: unknown value 'sin'

                      1 Reply Last reply Reply Quote 0
                      • anaghundefined
                        anagh @Phaedrux
                        last edited by

                        @phaedrux is running the machine in CNC mode an issue?
                        I still haven't been able to find a solution for this. I tried using math functions in macros and also sending them via the console. Both did not work.

                        infiniteloopundefined 1 Reply Last reply Reply Quote 0
                        • infiniteloopundefined
                          infiniteloop @anagh
                          last edited by

                          @anagh said in Problem using functions:

                          is running the machine in CNC mode an issue?

                          Sure you can ask @Phaedrux any question you want, but in this case, I had already posted the answer: CNC mode isn't an issue, but it is different. Round brackets are a special case, so you have to enclose your expressions in curly braces. Did my sample work?

                          I just entered the expression

                          echo {sin(50)}
                          

                          into my console, and I'm pretty sure it works - notably: in CNC mode. The result is -0.2623748 😊

                          anaghundefined 1 Reply Last reply Reply Quote 1
                          • anaghundefined
                            anagh @infiniteloop
                            last edited by

                            @infiniteloop Sorry, I missed your earlier answer. Your solution works. Thanks a lot for your help.

                            1 Reply Last reply Reply Quote 0
                            • dc42undefined dc42 marked this topic as a question
                            • dc42undefined dc42 has marked this topic as solved
                            • First post
                              Last post
                            Unless otherwise noted, all forum content is licensed under CC-BY-SA