Bartosz Jakubski 1 месяц назад
Родитель
Сommit
945be24d10

+ 1 - 1
OZE_Sensor/Core/Inc/meas_tasks.h

@@ -22,7 +22,7 @@ struct _EncoderTaskArg
 	float* currentPosition;
 	float* positionOffset;
 	int32_t* pvEncoder;
-	float maxAngle;
+	float impPerTurn;
 	uint32_t initPinStates;
 	osMessageQueueId_t dataQueue;
 };

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

@@ -18,8 +18,6 @@
 #define ENCODER_X_IMP_PER_TURN (1994) // (Encoder positions count for 100 units of movement)
 #define ENCODER_Y_IMP_PER_TURN (3670) // (Encoder positions count for 100 units of movement)
 
-#define MAX_X_AXE_ANGLE 360	// Max angle value for 100% range
-#define MAX_Y_AXE_ANGLE 360 // Max angle value for 100% range
 #define MOTOR_START_STOP_PWM_VALUE 60 // PWM duty for slow down/speed up movement phase
 #define MOTOR_HIGH_SPEED_PWM_VALUE 100 // PWM duty for normal movement phase
 

+ 3 - 9
OZE_Sensor/Core/Src/meas_tasks.c

@@ -113,7 +113,7 @@ void MeasTasksInit (void) {
     encoderXTaskArg.pvEncoder                = &(sensorsInfo.pvEncoderXraw);
     encoderXTaskArg.currentPosition          = &(sensorsInfo.currentXPosition);
     encoderXTaskArg.positionOffset           = &(sensorsInfo.positionXOffset);
-    encoderXTaskArg.maxAngle				 = MAX_X_AXE_ANGLE;
+    encoderXTaskArg.impPerTurn				 = ENCODER_X_IMP_PER_TURN;
     osMessageQueueAttr_t encoderMsgQueueAttr = { 0 };
     encoderXTaskArg.dataQueue                = osMessageQueueNew (16, sizeof (uint32_t), &encoderMsgQueueAttr);
     encoderXTaskArg.initPinStates            = ((HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_15) << 1) | HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_14)) & 0x3;
@@ -122,7 +122,7 @@ void MeasTasksInit (void) {
     encoderYTaskArg.pvEncoder       = &(sensorsInfo.pvEncoderYraw);
     encoderYTaskArg.currentPosition = &(sensorsInfo.currentYPosition);
     encoderYTaskArg.positionOffset  = &(sensorsInfo.positionYOffset);
-    encoderYTaskArg.maxAngle				 = MAX_Y_AXE_ANGLE;
+    encoderYTaskArg.impPerTurn				 = ENCODER_Y_IMP_PER_TURN;
     encoderYTaskArg.dataQueue       = osMessageQueueNew (16, sizeof (uint32_t), &encoderMsgQueueAttr);
     encoderYTaskArg.initPinStates   = ((HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_11) << 1) | HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_10)) & 0x3;
 
@@ -374,23 +374,17 @@ void EncoderTask (void* arg) {
 			if (encoderStates[(step + 1) % 4] == pinStates) {
 				step++;
 				encoderValue++;
-//				encoderValue += 360.0 / ENCODER_X_IMP_PER_TURN;
 //				printf ("Forward\n");
 			} else if (encoderStates[(step - 1) % 4] == pinStates) {
 				encoderValue--;
-//				encoderValue -= 360.0 / ENCODER_X_IMP_PER_TURN;
-//				if (encoderValue < 0) {
-//					encoderValue = 360.0 + encoderValue;
-//				}
 //				printf ("Reverse\n");
 				step--;
 			} else {
 				printf ("Forbidden\n");
 			}
 			step                             = step % 4;
-//			*encoderTaskArg->pvEncoder       = fmodf (encoderValue, 360.0);
 			*encoderTaskArg->pvEncoder       = encoderValue;
-			*encoderTaskArg->currentPosition = 100 * (*encoderTaskArg->pvEncoder) / encoderTaskArg->maxAngle;
+			*encoderTaskArg->currentPosition = 100 * (*encoderTaskArg->pvEncoder) / encoderTaskArg->impPerTurn;
 			osMutexRelease (sensorsInfoMutex);
 		}
         DbgLEDToggle (encoderTaskArg->dbgLed);

+ 0 - 4
OZE_Sensor/Core/Src/uart_tasks.c

@@ -447,8 +447,6 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
     	float enocoderXOffset = 0;
         ReadWordFromBufer (spFrameData->dataBuffer, &inputDataBufferPos, (uint32_t*)&enocoderXOffset);
         if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
-//            sensorsInfo.pvEncoderX = enocoderXValue;
-//            sensorsInfo.currentXPosition = 100 * enocoderXValue / MAX_X_AXE_ANGLE;
         	sensorsInfo.positionXOffset = enocoderXOffset;
             osMutexRelease (sensorsInfoMutex);
             respStatus = spOK;
@@ -460,8 +458,6 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
         float enocoderYOffset = 0;
         ReadWordFromBufer (spFrameData->dataBuffer, &inputDataBufferPos, (uint32_t*)&enocoderYOffset);
         if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
-//            sensorsInfo.pvEncoderY = enocoderYValue;
-//            sensorsInfo.currentYPosition = 100 * enocoderYValue / MAX_X_AXE_ANGLE;
         	sensorsInfo.positionYOffset = enocoderYOffset;
             osMutexRelease (sensorsInfoMutex);
             respStatus = spOK;