• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
ModalAI Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
    • Register
    • Login

    ESC Calibration

    ESCs
    2
    11
    1.1k
    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.
    • A
      Alex Kushleyev ModalAI Team @dlee
      last edited by 2 Aug 2023, 14:16

      @dlee

      First, please make sure that you are running the calibration with propellers installed (and use safety precautions).

      Next, if you are doing several calibration tests (which sometimes makes sense) and want to use an average value, you have to be a little careful. Keep in mind that you cannot just average four a0 values and use it for a0_average (and so on). Also, even though the a0, a1, a2 numbers may look different, it is difficult to just look at the numbers and see how similar or different the curves are - the answer is to plot them.

      I have written a short script to plot your four results using python. You can run it and take a look (first you may need to install numpy and plotly python packages using pip3 install numpy plotly.

      import numpy as np
      import plotly.graph_objects as go
      
      rpms = np.arange(0,20000) #rpm range for the quadratic fit
      
      cals = []
      fits = []
      
      cals.append([7.53669159958e-06, 0.336081465707, 112.878194918])
      cals.append([2.9479165331e-06,  0.37353561309,  35.6265065345])
      cals.append([8.8413818561e-06,  0.3256003514,   132.362831923])
      cals.append([7.1523119742e-07,  0.405821707061, -98.2189291548])
      
      fig = go.Figure()
      
      for idx in range(len(cals)):
          fit = np.polyval(cals[idx], rpms)
          fits.append(fit)
          fig.add_trace(go.Scatter(x=rpms, y=fits[idx], name='Fit %d'%idx))
      
      
      fig.update_layout(title='Motor Voltage vs. RPM')
      fig.update_xaxes(title_text="RPM")
      fig.update_yaxes(title_text="Motor Voltage (mV)")
      fig.show()
      

      The resulting plot looks like below, the four plots are not quite the same. But i have a feeling you might not have used propellers on during calibration? please confirm.

      4c98e125-8fb0-4b0b-9350-d9b7f42e1fc7-image.png

      D 1 Reply Last reply 2 Aug 2023, 20:14 Reply Quote 0
      • A Alex Kushleyev referenced this topic on 2 Aug 2023, 14:39
      • D
        dlee @Alex Kushleyev
        last edited by 2 Aug 2023, 20:14

        @Alex-Kushleyev
        It seems that when I run the script once, it only calibrates for one motor. So I ran the script 4 times to calibrate 4 motors. The motors spinned when I ran each script. Is there something I'm doing wrong?
        I ran that script inside the drone, so I commented out the code to draw the plot.

        A 1 Reply Last reply 2 Aug 2023, 22:32 Reply Quote 0
        • A
          Alex Kushleyev ModalAI Team @dlee
          last edited by 2 Aug 2023, 22:32

          @dlee , the calibration script indeed only spins one motor at a time, by design. Can you please confirm that you calibrated with propellers on?

          D 1 Reply Last reply 3 Aug 2023, 23:18 Reply Quote 0
          • D
            dlee @Alex Kushleyev
            last edited by 3 Aug 2023, 23:18

            @Alex-Kushleyev Yes, I calibrated with propellers on.

            A 1 Reply Last reply 3 Aug 2023, 23:19 Reply Quote 0
            • A
              Alex Kushleyev ModalAI Team @dlee
              last edited by 3 Aug 2023, 23:19

              @dlee

              Got it. Can you tell me what was the maximum rpm reached during the calibration? I think i may have used too high rpm in the plot.

              D 1 Reply Last reply 3 Aug 2023, 23:28 Reply Quote 0
              • D
                dlee @Alex Kushleyev
                last edited by 3 Aug 2023, 23:28

                @Alex-Kushleyev Maximum RPM was reached at 13,000. I am using 2800kv motors.

                A 1 Reply Last reply 3 Aug 2023, 23:35 Reply Quote 0
                • A
                  Alex Kushleyev ModalAI Team @dlee
                  last edited by Alex Kushleyev 3 Aug 2023, 23:36 3 Aug 2023, 23:35

                  @dlee

                  Thanks. If you look at the plot at 13K rpm, the plots look much closer together. Also please note that there are two curves that are close together and another two that are also close together. I think they may correspond to CW and CCW rotating propellers. Sometimes the CW and CCW propellers are not exactly the same and could result in slightly different calibration..

                  I think for your initial testing you can use either of the calibration curves. However i am wondering whether your propellers are not symmetric CW and CCW.

                  You can also use a calibration that is an average. I will follow up soon how to calculate that.

                  D 2 Replies Last reply 3 Aug 2023, 23:38 Reply Quote 0
                  • D
                    dlee @Alex Kushleyev
                    last edited by 3 Aug 2023, 23:38

                    @Alex-Kushleyev I checked that all of propellers spin right side (top-left & bottom-right: CCW; top-right & bottom-left : CW).

                    1 Reply Last reply Reply Quote 0
                    • D
                      dlee @Alex Kushleyev
                      last edited by 15 Aug 2023, 19:58

                      @Alex-Kushleyev Is there any update?

                      A 1 Reply Last reply 16 Aug 2023, 19:43 Reply Quote 0
                      • A
                        Alex Kushleyev ModalAI Team @dlee
                        last edited by 16 Aug 2023, 19:43

                        @dlee , sorry for the delay.

                        Just to clarify, it is possible that your CW and CCW propellers are not exactly the same, therefore the CW and CCW motors are showing slightly different response to calibration. In this case we can calculate an average for this calibration and use that for all 4 motors. I modified the script to calculate the quadratic fit for all four calibration results together.

                        import numpy as np
                        import plotly.graph_objects as go
                        
                        rpms = np.arange(0,13000) #rpm range for the quadratic fit
                        
                        cals = []
                        fits = []
                        all_fits = []
                        
                        #enter the calibration results from each motor
                        cals.append([7.53669159958e-06, 0.336081465707, 112.878194918])
                        cals.append([2.9479165331e-06,  0.37353561309,  35.6265065345])
                        cals.append([8.8413818561e-06,  0.3256003514,   132.362831923])
                        cals.append([7.1523119742e-07,  0.405821707061, -98.2189291548])
                        
                        fig = go.Figure()
                        
                        for idx in range(len(cals)):
                            fit = np.polyval(cals[idx], rpms)
                            fits.append(fit)
                            fig.add_trace(go.Scatter(x=rpms, y=fits[idx], name='Fit %d'%idx))  #plot each fit
                        
                        #create an array that contains points sampled from each curve
                        #and perform a polynomial fit on all the data to find the average
                        all_data = np.array(fits).flatten('C')
                        all_rpms = np.array([rpms,rpms,rpms,rpms]).flatten('C')
                        
                        #evaluate the average poly fit
                        ply = np.polyfit(all_rpms, all_data, 2)
                        av_fit = np.polyval(ply, rpms)
                        
                        
                        #print the average fit coefficients
                        print('Average Fit coefficients:')
                        print('    pwm_vs_rpm_curve_a0 = ' + str(ply[2]))
                        print('    pwm_vs_rpm_curve_a1 = ' + str(ply[1]))
                        print('    pwm_vs_rpm_curve_a2 = ' + str(ply[0]))
                        
                        #plot the average
                        fig.add_trace(go.Scatter(x=rpms, y=av_fit, name='Average Fit'))
                        
                        #finalize and show the figure
                        fig.update_layout(title='Motor Voltage vs. RPM')
                        fig.update_xaxes(title_text="RPM")
                        fig.update_yaxes(title_text="Motor Voltage (mV)")
                        fig.show()
                        

                        It results in the following plot and average coefficients. You can enter these coefficients into your custom esc parameters xml file.

                        Average Fit coefficients:
                            pwm_vs_rpm_curve_a0 = 45.66215105517507
                            pwm_vs_rpm_curve_a1 = 0.36025978431449995
                            pwm_vs_rpm_curve_a2 = 5.01030529655002e-06
                        

                        2dd75e2f-f722-464d-be82-5548568ec25b-image.png

                        1 Reply Last reply Reply Quote 0
                        • John Nomikos 0J John Nomikos 0 referenced this topic on 22 Aug 2023, 20:51
                        • Alexander SaundersA Alexander Saunders referenced this topic on 12 Apr 2024, 20:49
                        • First post
                          Last post
                        Powered by NodeBB | Contributors