Browse Source

Angle calculation update

Bartosz Jakubski 2 months ago
parent
commit
24d23ed1a3
4 changed files with 38335 additions and 38275 deletions
  1. 2 2
      OZE_Sensor/Core/Inc/node-red-config.h
  2. 12 0
      OZE_Sensor/Core/Src/meas_tasks.c
  3. 37280 37232
      OZE_Sensor/Debug/OZE_Sensor.list
  4. 1041 1041
      OZE_Sensor/Debug/OZE_Sensor.map

+ 2 - 2
OZE_Sensor/Core/Inc/node-red-config.h

@@ -15,8 +15,8 @@
 
 #define UART_TASK_LOGS FEATURE_ON
 
-#define ENCODER_X_IMP_PER_TURN 20
-#define ENCODER_Y_IMP_PER_TURN 20
+#define ENCODER_X_IMP_PER_TURN 2000
+#define ENCODER_Y_IMP_PER_TURN 2000
 
 #define MAX_X_AXE_ANGLE 360	// Max angle value for 100% range
 #define MAX_Y_AXE_ANGLE 360 // Max angle value for 100% range

+ 12 - 0
OZE_Sensor/Core/Src/meas_tasks.c

@@ -5,6 +5,8 @@
  *      Author: jakubski
  */
 
+#include <math.h>
+
 #include "meas_tasks.h"
 #include "adc_buffers.h"
 #include "measurements.h"
@@ -337,7 +339,12 @@ void EncoderTask (void* arg) {
                     sensorsInfo.pvEncoderX += 360.0 / ENCODER_X_IMP_PER_TURN;
                 } else {
                     sensorsInfo.pvEncoderX -= 360.0 / ENCODER_X_IMP_PER_TURN;
+                    if(sensorsInfo.pvEncoderX < 0)
+                    {
+                    	sensorsInfo.pvEncoderX = 360.0 + sensorsInfo.pvEncoderX;
+                    }
                 }
+                sensorsInfo.pvEncoderX = fmodf(sensorsInfo.pvEncoderX, 360.0);
                 float currentPercentPos = 100 * sensorsInfo.pvEncoderX / MAX_X_AXE_ANGLE;
                 currentPercentPos = currentPercentPos < 0 ? 0 : currentPercentPos;
                 sensorsInfo.currentXPosition = currentPercentPos > 100 ? 100 : currentPercentPos;
@@ -347,7 +354,12 @@ void EncoderTask (void* arg) {
                     sensorsInfo.pvEncoderY += 360.0 / ENCODER_Y_IMP_PER_TURN;
                 } else {
                     sensorsInfo.pvEncoderY -= 360.0 / ENCODER_Y_IMP_PER_TURN;
+                    if(sensorsInfo.pvEncoderY < 0)
+                    {
+                    	sensorsInfo.pvEncoderY = 360.0 + sensorsInfo.pvEncoderY;
+                    }
                 }
+                sensorsInfo.pvEncoderY = fmodf(sensorsInfo.pvEncoderY, 360.0);
                 float currentPercentPos = 100 * sensorsInfo.pvEncoderY / MAX_X_AXE_ANGLE;
 				currentPercentPos = currentPercentPos < 0 ? 0 : currentPercentPos;
 				sensorsInfo.currentXPosition = currentPercentPos > 100 ? 100 : currentPercentPos;

File diff suppressed because it is too large
+ 37280 - 37232
OZE_Sensor/Debug/OZE_Sensor.list


File diff suppressed because it is too large
+ 1041 - 1041
OZE_Sensor/Debug/OZE_Sensor.map