premiere ebauche

Dependencies:   mbed PinDetect

recommendedspeed.cpp

Committer:
shovelcat
Date:
2018-11-17
Revision:
11:e88e487c467a
Parent:
10:f0b382368614
Child:
12:cf97590d9df2

File content as of revision 11:e88e487c467a:

#include <vector>
#include "recommendedspeed.hpp"

#include "mbed.h"
static Serial* pc = new Serial(USBTX, USBRX);

/* Parcours */ 
Parcours::Parcours()
    : std::vector<Segment>()
    , currentSegmentIndex(0)
{
//    const float s0[] = {0};
//    const float s1[] = {0.5,0.79,1.08,1.37,1.66,1.95,2.24,2.53,2.82,3.11,3.4,3.69,3.98,4.27,4.56,4.85,5.14,5.43,5.72,6.01,6.3,6.59,6.88,7.17,7.46,7.75,8.04,8.33,8.62,8.91,9.2,9.49,9.78,10.07,10.36,10.65,10.94,11.23,11.52,11.81,12.1,12.39,12.68,12.97,13.26,13.55,13.84,14.13,14.42,14.71,15};
//    const float s2[] = {15,14.8,14.6,14.4,14.2,14,13.8,13.6,13.4,13.2,13,12.8,12.6,12.4,12.2,12,11.8,11.6,11.4,11.2,11,10.8,10.6,10.4,10.2,10,9.8,9.6,9.4,9.2,9,8.8,8.6,8.4,8.2,8,7.8,7.6,7.4,7.2,7,6.8,6.6,6.4,6.2,6,5.8,5.6,5.4,5.2,5};
//    const float s3[] = {5,5.1,5.2,5.3,5.4,5.5,5.6,5.7,5.8,5.9,6,6.1,6.2,6.3,6.4,6.5,6.6,6.7,6.8,6.9,7,7.1,7.2,7.3,7.4,7.5,7.6,7.7,7.8,7.9,8,8.1,8.2,8.3,8.4,8.5,8.6,8.7,8.8,8.9,9,9.1,9.2,9.3,9.4,9.5,9.6,9.7,9.8,9.9,10};
//    const float s4[] = {10,10.4,10.8,11.2,11.6,12,12.4,12.8,13.2,13.6,14,14.4,14.8,15.2,15.6,16,16.4,16.8,17.2,17.6,18,18.4,18.8,19.2,19.6,20,20.4,20.8,21.2,21.6,22,22.4,22.8,23.2,23.6,24,24.4,24.8,25.2,25.6,26,26.4,26.8,27.2,27.6,28,28.4,28.8,29.2,29.6,30};
//
    const float s0[] = {0};
    const float s1[] = {0,0.28302,0.56604,0.84906,1.1321,1.4151,1.6981,1.9811,2.2642,2.5472,2.8302,3.1132,3.3962,3.6792,3.9623,4.2453,4.5283,4.8113,5.0943,5.3774,5.6604,5.9434,6.2264,6.5094,6.7925,7.0755,7.3585,7.6415,7.9245,8.2075,8.4906,8.7736,9.0566,9.3396,9.6226,9.9057,10.189,10.472,10.755,11.038,11.321,11.604,11.887,12.17,12.453,12.736,13.019,13.302,13.585,13.868,14.151,14.434,14.717,15,15};
    const float s2[] = {15,14.688,14.375,14.062,13.75,13.438,13.125,12.813,12.5,12.188,11.875,11.563,11.25,10.937,10.625,10.313,10,9.6875,9.375,9.0625,8.75,8.4375,8.125,7.8125,7.5,7.1875,6.875,6.5625,6.25,5.9375,5.625,5.3125,5,4.6875,4.375,4.0625,3.75,3.4375,3.125,2.8125,2.5,2.1875,1.875,1.5625,1.25,0.9375,0.625,0.3125,0,0,1.0714,2.1429,3.2143,4.2857,5.3571,6.4286,7.5,8.5714,9.6429,10.714,11.786,12.857,13.929,15,15,18,21,24,27,30};
    const float s3[] = {30,29.333,28.667,28,27.333,26.667,26,25.333,24.667,24,23.333,22.667,22,21.333,20.667,20,19.333,18.667,18,17.333,16.667,16,15.333,14.667,14,13.333,12.667,12,11.333,10.667,10,9.3333,8.6667,8,7.3333,6.6667,6,5.3333,4.6667,4,3.3333,2.6667,2,1.3333,0.66667,0,0,0.78947,1.5789,2.3684,3.1579,3.9474,4.7368,5.5263,6.3158,7.1053,7.8947,8.6842,9.4737,10.263,11.053,11.842,12.632,13.421,14.211,15,15,16.667,18.333,20,21.667,23.333,25,26.667,28.333,30};
    const float s4[] = {30,27.778,25.556,23.333,21.111,18.889,16.667,14.444,12.222,10};
    const float s5[] = {10,11.667,13.333,15,16.667,18.333,20,21.667,23.333,25,26.667,28.333,30};
    const float s6[] = {30,25,20,15,10};
    const float s7[] = {10,10.426,10.851,11.277,11.702,12.128,12.553,12.979,13.404,13.83,14.255,14.681,15.106,15.532,15.957,16.383,16.809,17.234,17.66,18.085,18.511,18.936,19.362,19.787,20.213,20.638,21.064,21.489,21.915,22.34,22.766,23.191,23.617,24.043,24.468,24.894,25.319,25.745,26.17,26.596,27.021,27.447,27.872,28.298,28.723,29.149,29.574,30};
    const float s8[] = {30,29.318,28.636,27.955,27.273,26.591,25.909,25.227,24.545,23.864,23.182,22.5,21.818,21.136,20.455,19.773,19.091,18.409,17.727,17.045,16.364,15.682,15,14.318,13.636,12.955,12.273,11.591,10.909,10.227,9.5455,8.8636,8.1818,7.5,6.8182,6.1364,5.4545,4.7727,4.0909,3.4091,2.7273,2.0455,1.3636,0.68182,0,0,2.5,5,7.5,10,12.5,15,15,17.5,20,22.5,25,27.5,30,30,30};
    const float s9[] = {30,20,10,0,0,6.6667,13.333,20};
    const float s10[] = {20,19.231,18.462,17.692,16.923,16.154,15.385,14.615,13.846,13.077,12.308,11.538,10.769,10};
    const float s11[] = {10,10.185,10.37,10.556,10.741,10.926,11.111,11.296,11.481,11.667,11.852,12.037,12.222,12.407,12.593,12.778,12.963,13.148,13.333,13.519,13.704,13.889,14.074,14.259,14.444,14.63,14.815,15,15.185,15.37,15.556,15.741,15.926,16.111,16.296,16.481,16.667,16.852,17.037,17.222,17.407,17.593,17.778,17.963,18.148,18.333,18.519,18.704,18.889,19.074,19.259,19.444,19.63,19.815,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20};
    const float s12[] = {20,18.824,17.647,16.471,15.294,14.118,12.941,11.765,10.588,9.4118,8.2353,7.0588,5.8824,4.7059,3.5294,2.3529,1.1765,0,0,0.26316,0.52632,0.78947,1.0526,1.3158,1.5789,1.8421,2.1053,2.3684,2.6316,2.8947,3.1579,3.4211,3.6842,3.9474,4.2105,4.4737,4.7368,5,5.2632,5.5263,5.7895,6.0526,6.3158,6.5789,6.8421,7.1053,7.3684,7.6316,7.8947,8.1579,8.4211,8.6842,8.9474,9.2105,9.4737,9.7368,10,10.263,10.526,10.789,11.053,11.316,11.579,11.842,12.105,12.368,12.632,12.895,13.158,13.421,13.684,13.947,14.211,14.474,14.737,15,15.263,15.526,15.789,16.053,16.316,16.579,16.842,17.105,17.368,17.632,17.895,18.158,18.421,18.684,18.947,19.211,19.474,19.737,20,20.263,20.526,20.789,21.053,21.316,21.579,21.842,22.105,22.368,22.632,22.895,23.158,23.421,23.684,23.947,24.211,24.474,24.737,25,25.263,25.526,25.789,26.053,26.316,26.579,26.842,27.105,27.368,27.632,27.895,28.158,28.421,28.684,28.947,29.211,29.474,29.737,30};
    const float s13[] = {30,29.412,28.824,28.235,27.647,27.059,26.471,25.882,25.294,24.706,24.118,23.529,22.941,22.353,21.765,21.176,20.588,20,19.412,18.824,18.235,17.647,17.059,16.471,15.882,15.294,14.706,14.118,13.529,12.941,12.353,11.765,11.176,10.588,10,10,10.036,10.071,10.107,10.143,10.179,10.214,10.25,10.286,10.321,10.357,10.393,10.429,10.464,10.5,10.536,10.571,10.607,10.643,10.679,10.714,10.75,10.786,10.821,10.857,10.893,10.929,10.964,11,11.036,11.071,11.107,11.143,11.179,11.214,11.25,11.286,11.321,11.357,11.393,11.429,11.464,11.5,11.536,11.571,11.607,11.643,11.679,11.714,11.75,11.786,11.821,11.857,11.893,11.929,11.964,12,12.036,12.071,12.107,12.143,12.179,12.214,12.25,12.286,12.321,12.357,12.393,12.429,12.464,12.5,12.536,12.571,12.607,12.643,12.679,12.714,12.75,12.786,12.821,12.857,12.893,12.929,12.964,13,13.036,13.071,13.107,13.143,13.179,13.214,13.25,13.286,13.321,13.357,13.393,13.429,13.464,13.5,13.536,13.571,13.607,13.643,13.679,13.714,13.75,13.786,13.821,13.857,13.893,13.929,13.964,14,14.036,14.071,14.107,14.143,14.179,14.214,14.25,14.286,14.321,14.357,14.393,14.429,14.464,14.5,14.536,14.571,14.607,14.643,14.679,14.714,14.75,14.786,14.821,14.857,14.893,14.929,14.964,15,15,15,15,15,15,15,15,15,15,15,15,14.717,14.434,14.151,13.868,13.585,13.302,13.019,12.736,12.453,12.17,11.887,11.604,11.321,11.038,10.755,10.472,10.189,9.9057,9.6226,9.3396,9.0566,8.7736,8.4906,8.2075,7.9245,7.6415,7.3585,7.0755,6.7925,6.5094,6.2264,5.9434,5.6604,5.3774,5.0943,4.8113,4.5283,4.2453,3.9623,3.6792,3.3962,3.1132,2.8302,2.5472,2.2642,1.9811,1.6981,1.4151,1.1321,0.84906,0.56604,0.28302,0};

    std::vector<float> segment0(s0, s0 + sizeof(s0) / sizeof(s0[0]));
    std::vector<float> segment1(s1, s1 + sizeof(s1) / sizeof(s1[0]));
    std::vector<float> segment2(s2, s2 + sizeof(s2) / sizeof(s2[0]));
    std::vector<float> segment3(s3, s3 + sizeof(s3) / sizeof(s3[0]));
    std::vector<float> segment4(s4, s4 + sizeof(s4) / sizeof(s4[0]));
    std::vector<float> segment5(s5, s5 + sizeof(s5) / sizeof(s5[0]));
    std::vector<float> segment6(s6, s6 + sizeof(s6) / sizeof(s6[0]));
    std::vector<float> segment7(s7, s7 + sizeof(s7) / sizeof(s7[0]));
    std::vector<float> segment8(s8, s8 + sizeof(s8) / sizeof(s8[0]));
    std::vector<float> segment9(s9, s9 + sizeof(s9) / sizeof(s9[0]));
    std::vector<float> segment10(s10, s10 + sizeof(s10) / sizeof(s10[0]));
    std::vector<float> segment11(s11, s11 + sizeof(s11) / sizeof(s11[0]));
    std::vector<float> segment12(s12, s12 + sizeof(s12) / sizeof(s12[0]));
    std::vector<float> segment13(s13, s13 + sizeof(s13) / sizeof(s13[0]));
    
    
    
    this->push_back(segment0);
    this->push_back(segment1);
    this->push_back(segment2);
    this->push_back(segment3);
    this->push_back(segment4);
    this->push_back(segment5);
    this->push_back(segment6);
    this->push_back(segment7);
    this->push_back(segment8);
    this->push_back(segment9);
    this->push_back(segment10);
    this->push_back(segment11);
    this->push_back(segment12);
    this->push_back(segment13);
    
}

Segment& Parcours::getSegment()
{
    Segment& segment = this->at(currentSegmentIndex);
    
    return segment;
}

void Parcours::incrementIndex()
{
    if (currentSegmentIndex < (this->size() - 1))
    {
        currentSegmentIndex += 1;
    }
}

/* Segment */
Segment::Segment(std::vector<float> vals)
    : std::vector<float>(vals)
    , currentIndex(0)
{
}

float Segment::getSpeed()
{
    const float retval = this->at(currentIndex);
    
    return retval;
}

void Segment::incrementIndex()
{
    if (currentIndex < (this->size() - 1))
    {
        currentIndex += 1;
    }  
}