From 7e43df14fe78466dee2d67fdba21bfcc3ffd0fea Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Tue, 21 May 2024 15:04:30 +0200 Subject: [PATCH 01/10] Create a driver for the test deck for Brushless --- src/deck/drivers/src/rpm.c | 4 +- src/deck/drivers/src/test/Kbuild | 1 + src/deck/drivers/src/test/exptest_Cf_Bl.c | 207 ++++++++++++++++++++++ 3 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 src/deck/drivers/src/test/exptest_Cf_Bl.c diff --git a/src/deck/drivers/src/rpm.c b/src/deck/drivers/src/rpm.c index 4c9eb19f44..a8dfc831e4 100644 --- a/src/deck/drivers/src/rpm.c +++ b/src/deck/drivers/src/rpm.c @@ -82,7 +82,7 @@ static uint16_t m3rpm; static uint16_t m4rpm; -static void rpmInit(DeckInfo *info) +static void rpmTestInit(DeckInfo *info) { int i; isInit = true; @@ -313,7 +313,7 @@ static const DeckDriver rpm_deck = { .usedGpio = DECK_USING_IO_2 | DECK_USING_IO_3 | DECK_USING_PA2 | DECK_USING_PA3, - .init = rpmInit, + .init = rpmTestInit, }; DECK_DRIVER(rpm_deck); diff --git a/src/deck/drivers/src/test/Kbuild b/src/deck/drivers/src/test/Kbuild index f675beca9c..c9c2478664 100644 --- a/src/deck/drivers/src/test/Kbuild +++ b/src/deck/drivers/src/test/Kbuild @@ -1,3 +1,4 @@ obj-y += exptest.o +obj-y += exptest_Cf_Bl.o obj-y += exptestRR.o obj-y += exptestBolt11.o diff --git a/src/deck/drivers/src/test/exptest_Cf_Bl.c b/src/deck/drivers/src/test/exptest_Cf_Bl.c new file mode 100644 index 0000000000..9cfb78abbb --- /dev/null +++ b/src/deck/drivers/src/test/exptest_Cf_Bl.c @@ -0,0 +1,207 @@ +/* + * || ____ _ __ + * +------+ / __ )(_) /_______________ _____ ___ + * | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ + * +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ + * || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ + * + * Crazyflie control firmware + * + * Copyright (C) 2011-2021 Bitcraze AB + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, in version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * exptest.c - Testing of expansion port. + */ +#define DEBUG_MODULE "ET" + +#include + +#include "stm32fxxx.h" +#include "config.h" +#include "debug.h" +#include "deck.h" +#include "deck_test.h" + +#include "sensors.h" + +//Hardware configuration +#define ET_GPIO_PERIF (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC) + +#define ET_GPIO_PORT_TX1 GPIOC +#define ET_GPIO_PIN_TX1 GPIO_Pin_10 +#define ET_GPIO_PORT_RX1 GPIOC +#define ET_GPIO_PIN_RX1 GPIO_Pin_11 + +#define ET_GPIO_PORT_TX2 GPIOA +#define ET_GPIO_PIN_TX2 GPIO_Pin_2 +#define ET_GPIO_PORT_RX2 GPIOA +#define ET_GPIO_PIN_RX2 GPIO_Pin_3 + +#define ET_GPIO_PORT_SCK GPIOA +#define ET_GPIO_PIN_SCK GPIO_Pin_5 +#define ET_GPIO_PORT_MOSI GPIOA +#define ET_GPIO_PIN_MOSI GPIO_Pin_6 +#define ET_GPIO_PORT_MISO GPIOA +#define ET_GPIO_PIN_MISO GPIO_Pin_7 + +#define ET_GPIO_PORT_SDA GPIOB +#define ET_GPIO_PIN_SDA GPIO_Pin_7 +#define ET_GPIO_PORT_SCL GPIOB +#define ET_GPIO_PIN_SCL GPIO_Pin_6 + +#define ET_GPIO_PORT_IO1 GPIOB +#define ET_GPIO_PIN_IO1 GPIO_Pin_8 +#define ET_GPIO_PORT_IO2 GPIOB +#define ET_GPIO_PIN_IO2 GPIO_Pin_5 +#define ET_GPIO_PORT_IO3 GPIOB +#define ET_GPIO_PIN_IO3 GPIO_Pin_4 +#define ET_GPIO_PORT_IO4 GPIOC +#define ET_GPIO_PIN_IO4 GPIO_Pin_12 + +#define ET_NBR_PINS 11 +#define ET_IO4_PIN (ET_NBR_PINS - 1) + +typedef struct _etGpio { + GPIO_TypeDef *port; + uint16_t pin; + char name[6]; +} EtGpio; + +static EtGpio etGpioIn[ET_NBR_PINS] = { + {ET_GPIO_PORT_TX1, ET_GPIO_PIN_TX1, "TX1"}, + {ET_GPIO_PORT_RX1, ET_GPIO_PIN_RX1, "RX1"}, + {ET_GPIO_PORT_TX2, ET_GPIO_PIN_TX2, "TX2"}, + {ET_GPIO_PORT_RX2, ET_GPIO_PIN_RX2, "RX2"}, + {ET_GPIO_PORT_SCK, ET_GPIO_PIN_SCK, "SCK"}, + {ET_GPIO_PORT_MOSI, ET_GPIO_PIN_MOSI, "MOSI"}, + {ET_GPIO_PORT_MISO, ET_GPIO_PIN_MISO, "MISO"}, + {ET_GPIO_PORT_IO1, ET_GPIO_PIN_IO1, "IO1"}, + {ET_GPIO_PORT_IO2, ET_GPIO_PIN_IO2, "IO2"}, + {ET_GPIO_PORT_IO3, ET_GPIO_PIN_IO3, "IO3"}, + {ET_GPIO_PORT_IO4, ET_GPIO_PIN_IO4, "IO4"} +}; + +static EtGpio etGpioSDA = {ET_GPIO_PORT_SDA, ET_GPIO_PIN_SDA, "SDA"}; +static EtGpio etGpioSCL = {ET_GPIO_PORT_SCL, ET_GPIO_PIN_SCL, "SCL"}; + +static bool isInit; +const DeckDriver *bcRpm = NULL; + +static void expCfBlTestInit(DeckInfo *info) +{ + (void)info; + if (isInit) { + return; + } + + // Initialize the VL53L0 sensor using the zRanger deck driver + bcRpm = deckFindDriverByName("bcRpm"); + isInit = true; +} + +static bool expCfBlTestRun(void) +{ + int i; + volatile int delay; + bool status = true; + GPIO_InitTypeDef GPIO_InitStructure; + GpioRegBuf gpioSaved; + + isInit = true; + + status &= sensorsManufacturingTest(); + + + // Enable GPIOs + RCC_AHB1PeriphClockCmd(ET_GPIO_PERIF, ENABLE); + + decktestSaveGPIOStatesABC(&gpioSaved); + + for (i = 0; i < ET_NBR_PINS; i++) { + //Initialize the pins as inputs + GPIO_InitStructure.GPIO_Pin = etGpioIn[i].pin; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_InitStructure.GPIO_Speed = GPIO_Low_Speed; + GPIO_Init(etGpioIn[i].port, &GPIO_InitStructure); + } + + for (i = 0; i < ET_NBR_PINS && status; i++) { + // Configure pin as output to poke others + GPIO_InitStructure.GPIO_Pin = etGpioIn[i].pin; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Low_Speed; + GPIO_Init(etGpioIn[i].port, &GPIO_InitStructure); + + // Test high + GPIO_SetBits(etGpioIn[i].port, etGpioIn[i].pin); + for (delay = 0; delay < 1000; delay++); + + + // Test low + GPIO_ResetBits(etGpioIn[i].port, etGpioIn[i].pin); + for (delay = 0; delay < 1000; delay++); + + + // Restore + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; + GPIO_Init(etGpioIn[i].port, &GPIO_InitStructure); + } + + decktestRestoreGPIOStatesABC(&gpioSaved); + + //Run rpm test + if(status) { + if(bcRpm->init) { + bcRpm->init(NULL); + } + if(bcRpm != NULL && bcRpm->test != NULL) { + bcRpm->test(); + } + } + + if (status) { + // Configure SDA & SCL to turn on OK leds + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Low_Speed; + GPIO_InitStructure.GPIO_Pin = etGpioSDA.pin; + GPIO_Init(etGpioSDA.port, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = etGpioSCL.pin; + GPIO_Init(etGpioSCL.port, &GPIO_InitStructure); + // Turn on OK LEDs. + GPIO_ResetBits(etGpioSDA.port, etGpioSDA.pin); + GPIO_ResetBits(etGpioSCL.port, etGpioSCL.pin); + } + + return status; +} + + + + +static const DeckDriver expCfBltest_deck = { + .vid = 0xBC, + .pid = 0xFF, + .name = "bcExpTest_Cf_Bl", + + .usedGpio = 0xFFFFFFFF, + + .init = expCfBlTestInit, + .test = expCfBlTestRun +}; + +DECK_DRIVER(expCfBltest_deck); From 81b7ac99345a4b876f050349aa022ddd9e8119c4 Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 22 May 2024 12:53:01 +0200 Subject: [PATCH 02/10] RPM deck driver should be compiled by default on all platforms It is needed for production on CF-BL but it is not any issue of inluding it on other platforms aswell --- src/deck/drivers/src/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deck/drivers/src/Kconfig b/src/deck/drivers/src/Kconfig index 08120fa350..53569e0dd3 100644 --- a/src/deck/drivers/src/Kconfig +++ b/src/deck/drivers/src/Kconfig @@ -485,7 +485,7 @@ config DECK_ACS37800 config DECK_RPM bool "Support the rpm deck" - default n + default y help Enables the rpm deck that can be usfull in testing. From 9b4c68165cc6ad51e14afa6eee8c60ba1081fce5 Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 22 May 2024 13:07:33 +0200 Subject: [PATCH 03/10] Add a propeller RPM test to the rpm.c driver. The limits are not yet decided The test will run for approx 30 sec, and will feed the ESCs with a new PWM signal every 50 msec to prevent it from going asleep. Run one test per motor one at a time. --- src/deck/drivers/src/rpm.c | 57 +++++++++++++++++++++++ src/deck/drivers/src/test/exptest_Cf_Bl.c | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/deck/drivers/src/rpm.c b/src/deck/drivers/src/rpm.c index a8dfc831e4..d5dbd770cf 100644 --- a/src/deck/drivers/src/rpm.c +++ b/src/deck/drivers/src/rpm.c @@ -33,6 +33,11 @@ #include "deck.h" #include "debug.h" #include "log.h" +#include "motors.h" + +//FreeRTOS includes +#include "FreeRTOS.h" +#include "task.h" //Hardware configuration #define ET_GPIO_PERIF (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC) @@ -48,6 +53,11 @@ #define ER_NBR_PINS 4 +#define RPM_TEST_LOWER_LIMIT 10000 +#define MOTOR_TEST_PWM (UINT16_MAX/4) +#define MOTOR_TEST_TIME_MILLIS 30000 +#define MOTOR_FEED_SIGNAL_INTVL 50 + typedef struct _etGpio { GPIO_TypeDef *port; @@ -81,6 +91,31 @@ static uint16_t m2rpm; static uint16_t m3rpm; static uint16_t m4rpm; +static uint16_t getMotorRpm(uint16_t motorIdx) +{ + switch (motorIdx) + { + case MOTOR_M1: + return m1rpm; + break; + + case MOTOR_M2: + return m2rpm; + break; + + case MOTOR_M3: + return m3rpm; + break; + + case MOTOR_M4: + return m4rpm; + break; + + default: + return 0xFF; + break; + } +} static void rpmTestInit(DeckInfo *info) { @@ -153,6 +188,27 @@ static void rpmTestInit(DeckInfo *info) TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE); TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); + + motorsInit(platformConfigGetMotorMapping()); +} + +static bool rpmTestRun(void) +{ + bool passed = false; + for(uint16_t i =0; i< NBR_OF_MOTORS; i++) + { + uint16_t testTime = MOTOR_TEST_TIME_MILLIS; + + while(testTime) { + motorsSetRatio(i, MOTOR_TEST_PWM); + vTaskDelay(M2T(MOTOR_FEED_SIGNAL_INTVL)); + testTime -= MOTOR_FEED_SIGNAL_INTVL; + } + + passed &= (getMotorRpm(i) > RPM_TEST_LOWER_LIMIT); + motorsSetRatio(i, 0); + } + return passed; } static uint16_t calcRPM(uint32_t t1, uint32_t t2) @@ -314,6 +370,7 @@ static const DeckDriver rpm_deck = { .usedGpio = DECK_USING_IO_2 | DECK_USING_IO_3 | DECK_USING_PA2 | DECK_USING_PA3, .init = rpmTestInit, + .test = rpmTestRun }; DECK_DRIVER(rpm_deck); diff --git a/src/deck/drivers/src/test/exptest_Cf_Bl.c b/src/deck/drivers/src/test/exptest_Cf_Bl.c index 9cfb78abbb..4288416886 100644 --- a/src/deck/drivers/src/test/exptest_Cf_Bl.c +++ b/src/deck/drivers/src/test/exptest_Cf_Bl.c @@ -194,7 +194,7 @@ static bool expCfBlTestRun(void) static const DeckDriver expCfBltest_deck = { - .vid = 0xBC, + .vid = 0xFF, .pid = 0xFF, .name = "bcExpTest_Cf_Bl", From e64fa9f4e79968dc3ca06e3f47deb4095d3eb7e4 Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 22 May 2024 13:40:43 +0200 Subject: [PATCH 04/10] Remove vscode settings from repo Keep a local copy instead --- .vscode/settings.json | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 605386e7e4..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "search.exclude": { - "**/generated": true, - "**/node_modules": true, - "**/bower_components": true - }, - "files.associations": { - "bootloader.h": "c" - } -} From d27e2ed14c1a0faedeb9d98739e2a4b25aa4767c Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 22 May 2024 13:59:23 +0200 Subject: [PATCH 05/10] Remove pins connected to reflector sensors from pin test. These pins will be tested indirectly from the rpm test by reading on them. --- src/deck/drivers/src/test/exptest_Cf_Bl.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/deck/drivers/src/test/exptest_Cf_Bl.c b/src/deck/drivers/src/test/exptest_Cf_Bl.c index 4288416886..7e966a4a37 100644 --- a/src/deck/drivers/src/test/exptest_Cf_Bl.c +++ b/src/deck/drivers/src/test/exptest_Cf_Bl.c @@ -81,14 +81,10 @@ typedef struct _etGpio { static EtGpio etGpioIn[ET_NBR_PINS] = { {ET_GPIO_PORT_TX1, ET_GPIO_PIN_TX1, "TX1"}, {ET_GPIO_PORT_RX1, ET_GPIO_PIN_RX1, "RX1"}, - {ET_GPIO_PORT_TX2, ET_GPIO_PIN_TX2, "TX2"}, - {ET_GPIO_PORT_RX2, ET_GPIO_PIN_RX2, "RX2"}, {ET_GPIO_PORT_SCK, ET_GPIO_PIN_SCK, "SCK"}, {ET_GPIO_PORT_MOSI, ET_GPIO_PIN_MOSI, "MOSI"}, {ET_GPIO_PORT_MISO, ET_GPIO_PIN_MISO, "MISO"}, {ET_GPIO_PORT_IO1, ET_GPIO_PIN_IO1, "IO1"}, - {ET_GPIO_PORT_IO2, ET_GPIO_PIN_IO2, "IO2"}, - {ET_GPIO_PORT_IO3, ET_GPIO_PIN_IO3, "IO3"}, {ET_GPIO_PORT_IO4, ET_GPIO_PIN_IO4, "IO4"} }; From dc961e7a9d2385ff75eef4fcdea786548f8f4848 Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 22 May 2024 14:15:49 +0200 Subject: [PATCH 06/10] Tighten pass criteria and log the data --- src/deck/drivers/src/rpm.c | 8 ++++---- src/deck/drivers/src/test/exptest_Cf_Bl.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/deck/drivers/src/rpm.c b/src/deck/drivers/src/rpm.c index d5dbd770cf..55f6a4ea12 100644 --- a/src/deck/drivers/src/rpm.c +++ b/src/deck/drivers/src/rpm.c @@ -53,9 +53,9 @@ #define ER_NBR_PINS 4 -#define RPM_TEST_LOWER_LIMIT 10000 +#define RPM_TEST_LOWER_LIMIT 9300 #define MOTOR_TEST_PWM (UINT16_MAX/4) -#define MOTOR_TEST_TIME_MILLIS 30000 +#define MOTOR_TEST_TIME_MILLIS 3000 #define MOTOR_FEED_SIGNAL_INTVL 50 typedef struct _etGpio @@ -194,7 +194,7 @@ static void rpmTestInit(DeckInfo *info) static bool rpmTestRun(void) { - bool passed = false; + bool passed = true; for(uint16_t i =0; i< NBR_OF_MOTORS; i++) { uint16_t testTime = MOTOR_TEST_TIME_MILLIS; @@ -204,7 +204,7 @@ static bool rpmTestRun(void) vTaskDelay(M2T(MOTOR_FEED_SIGNAL_INTVL)); testTime -= MOTOR_FEED_SIGNAL_INTVL; } - + DEBUG_PRINT("Motor; %d RPM; %d\n", i, getMotorRpm(i)); passed &= (getMotorRpm(i) > RPM_TEST_LOWER_LIMIT); motorsSetRatio(i, 0); } diff --git a/src/deck/drivers/src/test/exptest_Cf_Bl.c b/src/deck/drivers/src/test/exptest_Cf_Bl.c index 7e966a4a37..94b95c7d91 100644 --- a/src/deck/drivers/src/test/exptest_Cf_Bl.c +++ b/src/deck/drivers/src/test/exptest_Cf_Bl.c @@ -165,7 +165,7 @@ static bool expCfBlTestRun(void) bcRpm->init(NULL); } if(bcRpm != NULL && bcRpm->test != NULL) { - bcRpm->test(); + status &= bcRpm->test(); } } From 2d8c67a93c70546288281defc1b92a900951b3f9 Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 22 May 2024 14:28:19 +0200 Subject: [PATCH 07/10] Run all motors in parallell instead --- src/deck/drivers/src/rpm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/deck/drivers/src/rpm.c b/src/deck/drivers/src/rpm.c index 55f6a4ea12..90b58331f1 100644 --- a/src/deck/drivers/src/rpm.c +++ b/src/deck/drivers/src/rpm.c @@ -195,19 +195,23 @@ static void rpmTestInit(DeckInfo *info) static bool rpmTestRun(void) { bool passed = true; - for(uint16_t i =0; i< NBR_OF_MOTORS; i++) - { + uint16_t testTime = MOTOR_TEST_TIME_MILLIS; while(testTime) { - motorsSetRatio(i, MOTOR_TEST_PWM); + for(uint16_t i =0; i< NBR_OF_MOTORS; i++) + { + motorsSetRatio(i, MOTOR_TEST_PWM); + } vTaskDelay(M2T(MOTOR_FEED_SIGNAL_INTVL)); testTime -= MOTOR_FEED_SIGNAL_INTVL; } - DEBUG_PRINT("Motor; %d RPM; %d\n", i, getMotorRpm(i)); - passed &= (getMotorRpm(i) > RPM_TEST_LOWER_LIMIT); - motorsSetRatio(i, 0); - } + for(uint16_t i =0; i< NBR_OF_MOTORS; i++) + { + DEBUG_PRINT("Motor; %d RPM; %d\n", i, getMotorRpm(i)); + passed &= (getMotorRpm(i) > RPM_TEST_LOWER_LIMIT); + motorsSetRatio(i, 0); + } return passed; } From 575f7bc5abd02fcca4b3083761aa0b4091c64735 Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Wed, 29 May 2024 14:29:06 +0200 Subject: [PATCH 08/10] Modify rpm deck driver test to work properly on Brushless motors The ESCs needs to be fed a signal constantly to not go to sleep, however we can not start the test until ESCs are started (which we dont know exactly when that is). To get around this issue we will wait a time, while constantly feeding the ESCs at 1KHz with a 0 PWM signal. After this time we start the test. --- src/deck/drivers/src/rpm.c | 65 ++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/src/deck/drivers/src/rpm.c b/src/deck/drivers/src/rpm.c index 90b58331f1..5da9a43904 100644 --- a/src/deck/drivers/src/rpm.c +++ b/src/deck/drivers/src/rpm.c @@ -34,6 +34,7 @@ #include "debug.h" #include "log.h" #include "motors.h" +#include "platform.h" //FreeRTOS includes #include "FreeRTOS.h" @@ -53,10 +54,11 @@ #define ER_NBR_PINS 4 -#define RPM_TEST_LOWER_LIMIT 9300 -#define MOTOR_TEST_PWM (UINT16_MAX/4) -#define MOTOR_TEST_TIME_MILLIS 3000 -#define MOTOR_FEED_SIGNAL_INTVL 50 +#define RPM_TEST_LOWER_LIMIT 13000 +#define MOTOR_TEST_PWM (UINT16_MAX/2) +#define MOTOR_TEST_TIME_MILLIS 2000 +#define MOTOR_FEED_SIGNAL_INTVL 1 +#define MOTOR_RPM_NBR_SAMPLES (MOTOR_TEST_TIME_MILLIS/MOTOR_FEED_SIGNAL_INTVL) typedef struct _etGpio { @@ -93,8 +95,7 @@ static uint16_t m4rpm; static uint16_t getMotorRpm(uint16_t motorIdx) { - switch (motorIdx) - { + switch (motorIdx) { case MOTOR_M1: return m1rpm; break; @@ -117,6 +118,21 @@ static uint16_t getMotorRpm(uint16_t motorIdx) } } +static void setMotorsPwm(uint32_t pwm) +{ + for (int i = 0; i RPM_TEST_LOWER_LIMIT); - motorsSetRatio(i, 0); + setMotorsPwm(MOTOR_TEST_PWM); + while(testTime) { + runMotors(); + testTime -= MOTOR_FEED_SIGNAL_INTVL; + for (int i = 0; i RPM_TEST_LOWER_LIMIT); + } return passed; } From 2e36e3dafadec400be9b12e35d9ff4a3e698146b Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Mon, 10 Jun 2024 15:25:58 +0200 Subject: [PATCH 09/10] Rename exptestCfBL driver --- src/deck/drivers/src/test/Kbuild | 2 +- src/deck/drivers/src/test/{exptest_Cf_Bl.c => exptestCfBl.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/deck/drivers/src/test/{exptest_Cf_Bl.c => exptestCfBl.c} (100%) diff --git a/src/deck/drivers/src/test/Kbuild b/src/deck/drivers/src/test/Kbuild index c9c2478664..417af412cb 100644 --- a/src/deck/drivers/src/test/Kbuild +++ b/src/deck/drivers/src/test/Kbuild @@ -1,4 +1,4 @@ obj-y += exptest.o -obj-y += exptest_Cf_Bl.o +obj-y += exptestCfBl.o obj-y += exptestRR.o obj-y += exptestBolt11.o diff --git a/src/deck/drivers/src/test/exptest_Cf_Bl.c b/src/deck/drivers/src/test/exptestCfBl.c similarity index 100% rename from src/deck/drivers/src/test/exptest_Cf_Bl.c rename to src/deck/drivers/src/test/exptestCfBl.c From e87e2bad6f963e6e1f990827811dd878969ac4ca Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Mon, 10 Jun 2024 16:17:53 +0200 Subject: [PATCH 10/10] Add all rpm testing logic to exptest driver for BL --- src/deck/drivers/src/rpm.c | 86 +---------------- src/deck/drivers/src/test/exptestCfBl.c | 119 +++++++++++++++++++++--- 2 files changed, 105 insertions(+), 100 deletions(-) diff --git a/src/deck/drivers/src/rpm.c b/src/deck/drivers/src/rpm.c index 5da9a43904..7225c8a9da 100644 --- a/src/deck/drivers/src/rpm.c +++ b/src/deck/drivers/src/rpm.c @@ -33,12 +33,6 @@ #include "deck.h" #include "debug.h" #include "log.h" -#include "motors.h" -#include "platform.h" - -//FreeRTOS includes -#include "FreeRTOS.h" -#include "task.h" //Hardware configuration #define ET_GPIO_PERIF (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC) @@ -54,12 +48,6 @@ #define ER_NBR_PINS 4 -#define RPM_TEST_LOWER_LIMIT 13000 -#define MOTOR_TEST_PWM (UINT16_MAX/2) -#define MOTOR_TEST_TIME_MILLIS 2000 -#define MOTOR_FEED_SIGNAL_INTVL 1 -#define MOTOR_RPM_NBR_SAMPLES (MOTOR_TEST_TIME_MILLIS/MOTOR_FEED_SIGNAL_INTVL) - typedef struct _etGpio { GPIO_TypeDef *port; @@ -93,46 +81,6 @@ static uint16_t m2rpm; static uint16_t m3rpm; static uint16_t m4rpm; -static uint16_t getMotorRpm(uint16_t motorIdx) -{ - switch (motorIdx) { - case MOTOR_M1: - return m1rpm; - break; - - case MOTOR_M2: - return m2rpm; - break; - - case MOTOR_M3: - return m3rpm; - break; - - case MOTOR_M4: - return m4rpm; - break; - - default: - return 0xFF; - break; - } -} - -static void setMotorsPwm(uint32_t pwm) -{ - for (int i = 0; i RPM_TEST_LOWER_LIMIT); - } - return passed; } static uint16_t calcRPM(uint32_t t1, uint32_t t2) @@ -396,8 +313,7 @@ static const DeckDriver rpm_deck = { .usedGpio = DECK_USING_IO_2 | DECK_USING_IO_3 | DECK_USING_PA2 | DECK_USING_PA3, - .init = rpmTestInit, - .test = rpmTestRun + .init = rpmTestInit }; DECK_DRIVER(rpm_deck); diff --git a/src/deck/drivers/src/test/exptestCfBl.c b/src/deck/drivers/src/test/exptestCfBl.c index 94b95c7d91..2ec0121142 100644 --- a/src/deck/drivers/src/test/exptestCfBl.c +++ b/src/deck/drivers/src/test/exptestCfBl.c @@ -32,7 +32,15 @@ #include "debug.h" #include "deck.h" #include "deck_test.h" +#include "motors.h" +#include "platform.h" +//FreeRTOS includes +#include "FreeRTOS.h" +#include "task.h" + +#include "log.h" +#include "param.h" #include "sensors.h" //Hardware configuration @@ -43,11 +51,6 @@ #define ET_GPIO_PORT_RX1 GPIOC #define ET_GPIO_PIN_RX1 GPIO_Pin_11 -#define ET_GPIO_PORT_TX2 GPIOA -#define ET_GPIO_PIN_TX2 GPIO_Pin_2 -#define ET_GPIO_PORT_RX2 GPIOA -#define ET_GPIO_PIN_RX2 GPIO_Pin_3 - #define ET_GPIO_PORT_SCK GPIOA #define ET_GPIO_PIN_SCK GPIO_Pin_5 #define ET_GPIO_PORT_MOSI GPIOA @@ -62,15 +65,16 @@ #define ET_GPIO_PORT_IO1 GPIOB #define ET_GPIO_PIN_IO1 GPIO_Pin_8 -#define ET_GPIO_PORT_IO2 GPIOB -#define ET_GPIO_PIN_IO2 GPIO_Pin_5 -#define ET_GPIO_PORT_IO3 GPIOB -#define ET_GPIO_PIN_IO3 GPIO_Pin_4 #define ET_GPIO_PORT_IO4 GPIOC #define ET_GPIO_PIN_IO4 GPIO_Pin_12 -#define ET_NBR_PINS 11 -#define ET_IO4_PIN (ET_NBR_PINS - 1) +#define ET_NBR_PINS 7 + +#define RPM_TEST_LOWER_LIMIT 12000 +#define MOTOR_TEST_PWM (UINT16_MAX/2) +#define MOTOR_TEST_TIME_MILLIS 2000 +#define MOTOR_FEED_SIGNAL_INTVL 1 +#define MOTOR_RPM_NBR_SAMPLES (MOTOR_TEST_TIME_MILLIS/MOTOR_FEED_SIGNAL_INTVL) typedef struct _etGpio { GPIO_TypeDef *port; @@ -78,6 +82,13 @@ typedef struct _etGpio { char name[6]; } EtGpio; +typedef struct { + logVarId_t m1; + logVarId_t m2; + logVarId_t m3; + logVarId_t m4; +} motorRpmParams_t; + static EtGpio etGpioIn[ET_NBR_PINS] = { {ET_GPIO_PORT_TX1, ET_GPIO_PIN_TX1, "TX1"}, {ET_GPIO_PORT_RX1, ET_GPIO_PIN_RX1, "RX1"}, @@ -93,6 +104,7 @@ static EtGpio etGpioSCL = {ET_GPIO_PORT_SCL, ET_GPIO_PIN_SCL, "SCL"}; static bool isInit; const DeckDriver *bcRpm = NULL; +static motorRpmParams_t motorRpm = {0}; static void expCfBlTestInit(DeckInfo *info) { @@ -103,9 +115,87 @@ static void expCfBlTestInit(DeckInfo *info) // Initialize the VL53L0 sensor using the zRanger deck driver bcRpm = deckFindDriverByName("bcRpm"); + motorsInit(platformConfigGetMotorMapping()); + motorRpm.m1 = logGetVarId("rpm", "m1"); + motorRpm.m2 = logGetVarId("rpm", "m2"); + motorRpm.m3 = logGetVarId("rpm", "m3"); + motorRpm.m4 = logGetVarId("rpm", "m4"); isInit = true; } +static int getMotorRpm(uint16_t motorIdx) +{ + uint16_t ret = 0xFF; + switch (motorIdx) { + case MOTOR_M1: + ret = logGetInt(motorRpm.m1); + break; + + case MOTOR_M2: + ret = logGetInt(motorRpm.m2); + break; + + case MOTOR_M3: + ret = logGetInt(motorRpm.m3); + break; + + case MOTOR_M4: + ret = logGetInt(motorRpm.m4); + break; + + default: + break; + } + return ret; +} + +static void setMotorsPwm(uint32_t pwm) +{ + for (int i = 0; i RPM_TEST_LOWER_LIMIT); + } + return passed; +} + static bool expCfBlTestRun(void) { int i; @@ -164,9 +254,8 @@ static bool expCfBlTestRun(void) if(bcRpm->init) { bcRpm->init(NULL); } - if(bcRpm != NULL && bcRpm->test != NULL) { - status &= bcRpm->test(); - } + + rpmTestRun(); } if (status) { @@ -192,7 +281,7 @@ static bool expCfBlTestRun(void) static const DeckDriver expCfBltest_deck = { .vid = 0xFF, .pid = 0xFF, - .name = "bcExpTest_Cf_Bl", + .name = "bcExpTestCfBl", .usedGpio = 0xFFFFFFFF,