]> git.leonardobizzoni.com Git - pioneer-stm32/commitdiff
move encoder methods to header file
authorFederica Di Lauro <federicadilauro1998@gmail.com>
Thu, 6 Feb 2020 13:21:50 +0000 (14:21 +0100)
committerFederica Di Lauro <federicadilauro1998@gmail.com>
Thu, 6 Feb 2020 13:21:50 +0000 (14:21 +0100)
otto_controller/Core/Inc/encoder.h
otto_controller/Core/Src/encoder.cpp [deleted file]

index 977507bf634722d001b85bd83d9b55d73b640525..479cc1a7fb22d1f9dec1115b7a5af799cb3fcefe 100644 (file)
@@ -17,9 +17,11 @@ class Encoder {
     wheel_circumference_ = 0;
   }
 
-  Encoder(TIM_HandleTypeDef *timer, float wheel_circ);
+  Encoder(TIM_HandleTypeDef *timer, float wheel_circ) {
+      timer_ = timer;
+      wheel_circumference_ = wheel_circ;
 
-  void Setup();
+  }
 
   int GetCount() {
     int count = ((int) __HAL_TIM_GET_COUNTER(this->timer_)
@@ -32,11 +34,35 @@ class Encoder {
     __HAL_TIM_SET_COUNTER(timer_, (timer_->Init.Period / 2));
   }
 
-  void UpdateValues();
+  void Setup() {
+    HAL_TIM_Encoder_Start(timer_, TIM_CHANNEL_ALL);
+    this->ResetCount();
+    this->previous_millis_ = 0;
+    this->current_millis_ = HAL_GetTick();
+  }
+
+  void UpdateValues() {
+    this->previous_millis_ = this->current_millis_;
+    this->current_millis_ = HAL_GetTick();
+    this->ticks_ = this->GetCount();
+    this->ResetCount();
+  }
 
-  float GetMeters();
+  float GetMeters() {
+    float meters = ((float) this->ticks_ * this->wheel_circumference_)
+        / TICKS_PER_REVOLUTION;
+    return meters;
+  }
 
-  float GetLinearVelocity();
+  float GetLinearVelocity() {
+    this->UpdateValues();
+    float meters = this->GetMeters();
+    float deltaTime = this->current_millis_ - this->previous_millis_;
+    if (deltaTime == 0)
+      return 0;
+    float linear_velocity = (meters / (deltaTime / 1000));
+    return linear_velocity;
+  }
 
 };
 #endif
diff --git a/otto_controller/Core/Src/encoder.cpp b/otto_controller/Core/Src/encoder.cpp
deleted file mode 100644 (file)
index f3f7860..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "encoder.h"
-
-Encoder::Encoder(TIM_HandleTypeDef *timer, float wheel_circ) {
-  timer_ = timer;
-  wheel_circumference_ = wheel_circ;
-
-}
-
-void Encoder::Setup() {
-  HAL_TIM_Encoder_Start(timer_, TIM_CHANNEL_ALL);
-  this->ResetCount();
-  this->previous_millis_ = 0;
-  this->current_millis_ = HAL_GetTick();
-}
-
-void Encoder::UpdateValues() {
-  this->previous_millis_ = this->current_millis_;
-  this->current_millis_ = HAL_GetTick();
-  this->ticks_ = this->GetCount();
-  this->ResetCount();
-}
-
-float Encoder::GetMeters() {
-  float meters = ((float) this->ticks_ * this->wheel_circumference_)
-      / TICKS_PER_REVOLUTION;
-  return meters;
-}
-
-float Encoder::GetLinearVelocity() {
-  this->UpdateValues();
-  float meters = this->GetMeters();
-  float deltaTime = this->current_millis_ - this->previous_millis_;
-  if (deltaTime == 0)
-    return 0;
-  float linear_velocity = (meters / (deltaTime / 1000));
-  return linear_velocity;
-}
-