|
@@ -110,17 +110,21 @@ void MeasTasksInit (void) {
|
|
limiterSwitchTaskHandle = osThreadNew (LimiterSwitchTask, NULL, &osThreadAttradc1LimiterSwitchTask);
|
|
limiterSwitchTaskHandle = osThreadNew (LimiterSwitchTask, NULL, &osThreadAttradc1LimiterSwitchTask);
|
|
|
|
|
|
encoderXTaskArg.dbgLed = DBG_LED2;
|
|
encoderXTaskArg.dbgLed = DBG_LED2;
|
|
- encoderXTaskArg.pvEncoder = &(sensorsInfo.pvEncoderX);
|
|
|
|
|
|
+ encoderXTaskArg.pvEncoder = &(sensorsInfo.pvEncoderXraw);
|
|
encoderXTaskArg.currentPosition = &(sensorsInfo.currentXPosition);
|
|
encoderXTaskArg.currentPosition = &(sensorsInfo.currentXPosition);
|
|
|
|
+ encoderXTaskArg.positionOffset = &(sensorsInfo.positionXOffset);
|
|
|
|
+ encoderXTaskArg.maxAngle = MAX_X_AXE_ANGLE;
|
|
osMessageQueueAttr_t encoderMsgQueueAttr = { 0 };
|
|
osMessageQueueAttr_t encoderMsgQueueAttr = { 0 };
|
|
encoderXTaskArg.dataQueue = osMessageQueueNew (16, sizeof (uint32_t), &encoderMsgQueueAttr);
|
|
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;
|
|
|
|
|
|
+ encoderXTaskArg.initPinStates = ((HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_15) << 1) | HAL_GPIO_ReadPin (GPIOD, GPIO_PIN_14)) & 0x3;
|
|
|
|
|
|
encoderYTaskArg.dbgLed = DBG_LED3;
|
|
encoderYTaskArg.dbgLed = DBG_LED3;
|
|
- encoderYTaskArg.pvEncoder = &(sensorsInfo.pvEncoderY);
|
|
|
|
|
|
+ encoderYTaskArg.pvEncoder = &(sensorsInfo.pvEncoderYraw);
|
|
encoderYTaskArg.currentPosition = &(sensorsInfo.currentYPosition);
|
|
encoderYTaskArg.currentPosition = &(sensorsInfo.currentYPosition);
|
|
|
|
+ encoderYTaskArg.positionOffset = &(sensorsInfo.positionYOffset);
|
|
|
|
+ encoderYTaskArg.maxAngle = MAX_Y_AXE_ANGLE;
|
|
encoderYTaskArg.dataQueue = osMessageQueueNew (16, sizeof (uint32_t), &encoderMsgQueueAttr);
|
|
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;
|
|
|
|
|
|
+ encoderYTaskArg.initPinStates = ((HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_11) << 1) | HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_10)) & 0x3;
|
|
|
|
|
|
osThreadAttr_t osThreadAttrEncoderTask = { 0 };
|
|
osThreadAttr_t osThreadAttrEncoderTask = { 0 };
|
|
osThreadAttrEncoderTask.stack_size = configMINIMAL_STACK_SIZE * 2;
|
|
osThreadAttrEncoderTask.stack_size = configMINIMAL_STACK_SIZE * 2;
|
|
@@ -128,24 +132,24 @@ void MeasTasksInit (void) {
|
|
encoderXTaskHandle = osThreadNew (EncoderTask, &encoderXTaskArg, &osThreadAttrEncoderTask);
|
|
encoderXTaskHandle = osThreadNew (EncoderTask, &encoderXTaskArg, &osThreadAttrEncoderTask);
|
|
encoderYTaskHandle = osThreadNew (EncoderTask, &encoderYTaskArg, &osThreadAttrEncoderTask);
|
|
encoderYTaskHandle = osThreadNew (EncoderTask, &encoderYTaskArg, &osThreadAttrEncoderTask);
|
|
#ifdef MOCK_VOLTAGES_AND_CURRENS
|
|
#ifdef MOCK_VOLTAGES_AND_CURRENS
|
|
- GenenarateWaveSamples(325.269, 0, 128, 8, voltageWave[0]);
|
|
|
|
- GenenarateWaveSamples(324.269, 0, 128, 8, voltageWave[1]);
|
|
|
|
- GenenarateWaveSamples(323.269, 0, 128, 8, voltageWave[2]);
|
|
|
|
- GenenarateWaveSamples(1.414213562, 0, 128, 8, currentWave[0]);
|
|
|
|
- GenenarateWaveSamples(1.314213562, 0, 128, 8, currentWave[1]);
|
|
|
|
- GenenarateWaveSamples(1.214213562, 0, 128, 8, currentWave[2]);
|
|
|
|
|
|
+ GenenarateWaveSamples (325.269, 0, 128, 8, voltageWave[0]);
|
|
|
|
+ GenenarateWaveSamples (324.269, 0, 128, 8, voltageWave[1]);
|
|
|
|
+ GenenarateWaveSamples (323.269, 0, 128, 8, voltageWave[2]);
|
|
|
|
+ GenenarateWaveSamples (1.414213562, 0, 128, 8, currentWave[0]);
|
|
|
|
+ GenenarateWaveSamples (1.314213562, 0, 128, 8, currentWave[1]);
|
|
|
|
+ GenenarateWaveSamples (1.214213562, 0, 128, 8, currentWave[2]);
|
|
#endif
|
|
#endif
|
|
-// arm_hanning_f32
|
|
|
|
-// arm_rfft_fast_instance_f32 fft;
|
|
|
|
-// arm_rfft_fast_init_f32(&fft, FFT_Length);
|
|
|
|
-// arm_rfft_fast_f32(&fft, waveOne, fft_output, ifftFlag);
|
|
|
|
-// arm_cmplx_mag_f32(fft_output, fft_power, SAMPLE_BUFFER_LENGTH_HALF);
|
|
|
|
-// float32_t scale = 2.0f/FFT_Length;
|
|
|
|
-// arm_scale_f32(fft_power, scale, fft_power_scaled, SAMPLE_BUFFER_LENGTH_HALF);
|
|
|
|
-// float32_t maxValue;
|
|
|
|
-// uint32_t maxIndex;
|
|
|
|
-// arm_max_f32(fft_power_scaled, SAMPLE_BUFFER_LENGTH_HALF, &maxValue, &maxIndex);
|
|
|
|
-// printf("maxValue %f, index %ld\n", maxValue, maxIndex);
|
|
|
|
|
|
+ // arm_hanning_f32
|
|
|
|
+ // arm_rfft_fast_instance_f32 fft;
|
|
|
|
+ // arm_rfft_fast_init_f32(&fft, FFT_Length);
|
|
|
|
+ // arm_rfft_fast_f32(&fft, waveOne, fft_output, ifftFlag);
|
|
|
|
+ // arm_cmplx_mag_f32(fft_output, fft_power, SAMPLE_BUFFER_LENGTH_HALF);
|
|
|
|
+ // float32_t scale = 2.0f/FFT_Length;
|
|
|
|
+ // arm_scale_f32(fft_power, scale, fft_power_scaled, SAMPLE_BUFFER_LENGTH_HALF);
|
|
|
|
+ // float32_t maxValue;
|
|
|
|
+ // uint32_t maxIndex;
|
|
|
|
+ // arm_max_f32(fft_power_scaled, SAMPLE_BUFFER_LENGTH_HALF, &maxValue, &maxIndex);
|
|
|
|
+ // printf("maxValue %f, index %ld\n", maxValue, maxIndex);
|
|
}
|
|
}
|
|
|
|
|
|
void ADC1MeasTask (void* arg) {
|
|
void ADC1MeasTask (void* arg) {
|
|
@@ -365,7 +369,7 @@ void EncoderTask (void* arg) {
|
|
}
|
|
}
|
|
while (pdTRUE) {
|
|
while (pdTRUE) {
|
|
osMessageQueueGet (encoderTaskArg->dataQueue, &pinStates, 0, osWaitForever);
|
|
osMessageQueueGet (encoderTaskArg->dataQueue, &pinStates, 0, osWaitForever);
|
|
- float encoderValue = *encoderTaskArg->pvEncoder;
|
|
|
|
|
|
+ int32_t encoderValue = *encoderTaskArg->pvEncoder;
|
|
if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
|
|
if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
|
|
if (encoderStates[(step + 1) % 4] == pinStates) {
|
|
if (encoderStates[(step + 1) % 4] == pinStates) {
|
|
step++;
|
|
step++;
|
|
@@ -386,7 +390,7 @@ void EncoderTask (void* arg) {
|
|
step = step % 4;
|
|
step = step % 4;
|
|
// *encoderTaskArg->pvEncoder = fmodf (encoderValue, 360.0);
|
|
// *encoderTaskArg->pvEncoder = fmodf (encoderValue, 360.0);
|
|
*encoderTaskArg->pvEncoder = encoderValue;
|
|
*encoderTaskArg->pvEncoder = encoderValue;
|
|
- *encoderTaskArg->currentPosition = 100 * (*encoderTaskArg->pvEncoder) / MAX_X_AXE_ANGLE;
|
|
|
|
|
|
+ *encoderTaskArg->currentPosition = 100 * (*encoderTaskArg->pvEncoder) / encoderTaskArg->maxAngle;
|
|
osMutexRelease (sensorsInfoMutex);
|
|
osMutexRelease (sensorsInfoMutex);
|
|
}
|
|
}
|
|
DbgLEDToggle (encoderTaskArg->dbgLed);
|
|
DbgLEDToggle (encoderTaskArg->dbgLed);
|