premiere ebauche

Dependencies:   mbed PinDetect

Revision:
10:f0b382368614
Child:
11:e88e487c467a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/recommendedspeed.cpp	Fri Nov 16 17:47:35 2018 +0000
@@ -0,0 +1,67 @@
+#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};
+    
+    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]));
+    
+    this->push_back(segment0);
+    this->push_back(segment1);
+    this->push_back(segment2);
+    this->push_back(segment3);
+    this->push_back(segment4);
+    
+}
+
+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;
+    }  
+}
\ No newline at end of file