Exemple #1
0
int mgcurv::fitCurve(int knotCount, Point2d* knots, Vector2d* knotvs,
                     int count, const Point2d* pts, float tol)
{
    FitCurveHelper helper;
    
    helper.index = 0;
    helper.knotCount = knotCount;
    helper.knots = knots;
    helper.knotvs = knotvs;
    
    FitCurve(&FitCurveHelper::append, &helper, pts, count, tol);
    return helper.index;
}
/*
 *  main:
 *  Example of how to use the curve-fitting code.  Given an array
 *   of points and a tolerance (squared error between points and
 *  fitted curve), the algorithm will generate a piecewise
 *  cubic Bezier representation that approximates the points.
 *  When a cubic is generated, the routine "DrawBezierCurve"
 *  is called, which outputs the Bezier curve just created
 *  (arguments are the degree and the control points, respectively).
 *  Users will have to implement this function themselves
 *   ascii output, etc.
 *
 */
main()
{
    static Point2 d[7] = {  /*  Digitized points */
    { 0.0, 0.0 },
    { 0.0, 0.5 },
    { 1.1, 1.4 },
    { 2.1, 1.6 },
    { 3.2, 1.1 },
    { 4.0, 0.2 },
    { 4.0, 0.0 },
    };
    double  error = 4.0;        /*  Squared error */
    FitCurve(d, 7, error);      /*  Fit the Bezier curves */
}
void FitOneCurve(string subdet, string run, ULong64_t modid, int debug=0)
{
  
  TGraphErrors* g = GetClusterWidthGraph(subdet, run, modid, 0);
  if(!g) return;

  // Correct for voltage drop due to leakage current
  string corr_name="_"+subdet+run;
  int corrected = CorrectGraphForLeakageCurrent(g, modid, corr_name);
  if(corrected) g->SetMarkerColor(13);

  g->SetTitle(Form("DetID %i", (int) modid));
  g->SetName("g");

  FitCurve(g, debug);
}
Exemple #4
0
void mgcurv::fitCurve3(FitCubicCallback fc, void* data, const Point2d *pts, int n, float tol)
{
    FitCurve(fc, data, pts, n, tol);
}
Exemple #5
0
static void *Spindown_Thread(void *arg)
{
    struct TimerInfo info;

    SpinDownState s_state = IDLE;
    SpinDownData  s_data[MAX_SPINDOWN_SAMPLES];
    uint8_t       s_index = 0;
    uint8_t       doSpinDown = 1;

    // set resistance to 0

    // Start the periodic timer @ 1s
    TimerStart (1000000, &info);

    // start the spindown process..
    while(doSpinDown && currentMode == MODE_CALIBRATE)
    {
        // Wait for periodic timer to expire
        TimerWait (&info);

        double kph = currentSpeed;

        switch (s_state)
        {
            case IDLE:
                //printf("%.2f : ", kph);
                //printf("Starting spindown calibration process...\n");
                snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE, "Starting spindown calibration process...");

                // zero out the array of spindown entries & set index to start
                memset(s_data, 0, sizeof (s_data));
                s_index = 0;

                s_state = WAIT;
                break;

            case WAIT:
                if (kph > 50)
                {
                    s_state = READY;
                }
                else
                {
                    //printf("%.2f : ", kph);
                    //printf("Please increase speed to over 50 km/h...\n");
                    snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE, "Please increase speed to over 50 km/h...");
                }
                break;

            case READY:
                if (kph > 50)
                {
                    //printf("%.2f : ", kph);
                    //printf("Please stop pedaling to initiate calibration...\n");
                    snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE, "Please stop pedaling to initiate calibration...");
                }
                else
                {
                    s_state = RUNNING;
                }
                break;

            case RUNNING:
                //printf("%.2f : ", kph);
                //printf("Calibrating, please wait....\n");
                snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE, "Calibrating, please wait....");

                // get current speed & add to array
                s_data[s_index].time = s_index+1;
                s_data[s_index].speed = kph;

                // check current speed is less than previous, else error
                if (s_index > 0)
                {
                    if (s_data[s_index].speed > s_data[s_index-1].speed)
                    {
                        s_state = ERROR;
                        break;
                    }
                }

                // have we reached enough samples, or low enough speed
                if ((s_data[s_index].speed < 10) || (s_index == MAX_SPINDOWN_SAMPLES))
                {
                    s_state = DONE;
                    break;
                }

                // ready for next sample
                s_index++;
                break;

            case ERROR:
                //printf("%.2f : ", kph);
                //printf("Error, did you start pedaling? ;)...\n\n");
                snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE, "Error, did you start pedaling? ;)...");
                s_state = IDLE;
                break;

            case DONE:
                //printf("%.2f : ", kph);
                //printf("Spindown calibration process successful...\n\n");
                snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE,
                        "Spindown successful: a = %lf, b = %lf, c = %lf, d = %lf",
                        power_curve_a, power_curve_b,
                        power_curve_c, power_curve_d);

                //int i;
                for (int i = 0; i < s_index; i++)
                {
                    //printf("%.0f, %.2f\n", s_data[i].time, s_data[i].speed);
                }
                //printf("\n");

                // ...and finish
                doSpinDown = 0;
                break;

            default:
                break;
        }

        if (s_state == DONE)
        {
            // Spindown completed, now fit data to curve
            FitCurve(s_data, s_index);
        }

        if (currentMode != MODE_CALIBRATE)
        {
            //printf("Spindown aborted..\n");
            snprintf(DisplayMessage, DISPLAY_MAX_MSG_SIZE, "Spindown aborted...");
        }
    }

    currentMode = lastMode;
    return NULL;
}