Commits

Pierre Surply committed c2c81a5

Ajout calcul vitesse moyenne

  • Participants
  • Parent commits 70e484f

Comments (0)

Files changed (3)

File src/roadmaster.cpp

   RoadMaster.cpp
 
   Pierre Surply
-  Time-stamp: <2012-04-15 11:19:31 surply_p>
+  Time-stamp: <2012-04-15 14:13:38 surply_p>
  */
 
 #include "roadmaster.h"
   int tmp;
   char buf[256];
 
+
   if (m_calibr->is_running())
     {
       sprintf(buf, "%d", (m_sensor->get_distance_tot()/10));
       tmp = m_sensor->get_distance_part();
       sprintf(buf, "%d.%d", tmp/1000, tmp % 1000);
       DistancePart->display(buf);
+
+      // Vitesse inst
+      tmp = m_sensor->get_vitesse_inst();
+      sprintf(buf, "%d.%d", tmp / 1000, (tmp % 1000) / 10);
+      VitesseInst->display(buf);
+
+      // Vitesse moy
+      tmp = m_sensor->get_vitesse_moy();
+      sprintf(buf, "%d.%d", tmp / 1000, (tmp % 1000) / 10);
+      VitesseMoy->display(buf);
     }
 }
 

File src/sensor.cpp

   sensor.cpp
 
   Pierre Surply
-  Time-stamp: <2012-04-15 11:15:04 surply_p>
+  Time-stamp: <2012-04-15 14:25:58 surply_p>
  */
 
 #include "sensor.h"
 
 
   m_rec = true;
-  m_tpm = 1;
+  m_tpm = 8;
 
 #ifdef __arm__
   m_fd = open("/dev/mem", O_RDWR);
   // thread
   pthread_create(&m_thread, NULL, thcount, this);
 #endif
+
+  this->reset();
 }
 
 Sensor::~Sensor()
 
 void Sensor::count()
 {
-  unsigned long last_state = 0xEEFF;
+  unsigned long last_state = BIT_NEUTRE;
   unsigned long read_result;
+  
+  bool count_vit = false;
 
   while(m_rec)
     {
 	      if (m_accu >= m_tpm)
 		{
 		  this->add_distance(10);
+		  if (!count_vit)
+		    {
+		      this->set_vitesse_inst();
+		      count_vit = true;
+		    }
+		  else
+		    {
+		      count_vit = false;
+		    }
 		  m_accu = 0;
 		}
 	      break;
 	      break;
 	    }
 	  m_parent->update();
-	  
 	}
       last_state = read_result;
     }
 {
   return m_distance_part;
 }
+
+void Sensor::set_vitesse_inst()
+{
+  double current = (double) time(NULL);
+  m_vitesse_inst = (int) ((10.0 / (current - m_last_tps)) * 3600);
+  m_last_tps = current;
+}
+
+int Sensor::get_vitesse_inst() const
+{
+  return m_vitesse_inst;
+}
+
+int Sensor::get_vitesse_moy() const // m/h
+{
+  double current = (double) time(NULL);
+  return (int) (((double) ((m_distance_tot) / ((current - m_begin_tps)))) * 3600);
+}

File src/sensor.h

   sensor.h
 
   Pierre Surply
-  Time-stamp: <2012-04-15 11:14:07 surply_p>
+  Time-stamp: <2012-04-15 14:14:49 surply_p>
  */
 #ifndef SENSOR_H
 #define SENSOR_H
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <pthread.h>
+#include <math.h>
 
 #include "gpio.h"
 
+#define BIT_NEUTRE  (0xEEFF)
 #define BIT_CAPTEUR (0xE6FF)
-#define BIT_ROUGE   (0xEECF)
+#define BIT_ROUGE   (0xEEFE)
 #define BIT_NOIR    (0xEEDF)
-#define BIT_BLANC   (0xEEFD)
+#define BIT_BLANC   (0xEECF)
 
 class RoadMaster;
 
   void add_distance(const int step);
   int get_distance_tot() const;
   int get_distance_part() const;
+  void set_vitesse_inst();
+  int get_vitesse_inst() const;
+  int get_vitesse_moy() const;
 
  private:
   RoadMaster* m_parent;
   int m_accu;
   int m_tpm;
   bool m_rec;
-  double m_begin_tps;
-  double m_last_tps;
-
+  int m_vitesse_inst; // km/h
+  double m_begin_tps; // s
+  double m_last_tps; // s
+  
   // GPIO
   int m_fd;
   void *m_map_base, *m_virt_addr;