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

    moving average, issue with types

    Scheduled Pinned Locked Moved
    Gcode meta commands
    2
    5
    148
    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.
    • Paskiundefined
      Paski
      last edited by

      Hi,
      I'm planning on adding a moving average function to average an analog input and trigger some actions if that decreases too much.
      for that, i'm declaring an array of the tension in the config.g

      global TensionAverage = {0,0,0,0,0,0} ;list of 6 tension to average the tension in a moving average
      

      And in a macro called by deamon.g is the following. with parameter P being the analog senor reading

      ;Tension WatchDog
      
      ;tension average: list of 1 elements, move element i to i+1. scrap element 5. add current to element 0
      var i = 5
      var average = 0
      while var.i>0
          set global.TensionAverage[var.i] = global.TensionAverage[var.i-1]
          set var.average = var.average + global.TensionAverage[var.i]
          set var.i = var.i -1
      set global.TensionAverage[0]=param.P
      set var.average = var.average + global.TensionAverage[0]
      
      set var.average = var.average /6
      echo "average: "^{var.average}
      
      if var.average < global.TensTreshold*0.5
          m98 P"/sys/tension-error.g"
      

      But in line 7, i got this error:
      "error: in file macro line 7 column 70: meta command: Cannot index into variable or parameter 'TensionAverage^' of non-array type"

      so, my question is, is there a more efficient way to get the moving average with Gcode/metacomands?
      how can i cast it to an array?
      Thanks!

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

        @Paski firmware version?

        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

        Paskiundefined 1 Reply Last reply Reply Quote 0
        • Paskiundefined
          Paski @dc42
          last edited by

          @dc42 RRF 3,5.4

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

            @Paski can you try firmware 3.6.0-rc.2 ? I think this may have been fixed already.

            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

            Paskiundefined 1 Reply Last reply Reply Quote 0
            • Paskiundefined
              Paski @dc42
              last edited by

              @dc42 Will try. 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