Skip to content

Commit

Permalink
Remove the RPM test from the exp deck driver completely
Browse files Browse the repository at this point in the history
Let the driver initialize the RPM deck so it can be used and then just check pins
  • Loading branch information
ToveRumar committed Nov 1, 2024
1 parent edc877f commit 1e39685
Showing 1 changed file with 7 additions and 95 deletions.
102 changes: 7 additions & 95 deletions src/deck/drivers/src/test/exptestCfBl.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ 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"},
Expand All @@ -101,8 +95,6 @@ static EtGpio etGpioIn[ET_NBR_PINS] = {

static bool isInit;
const DeckDriver *bcRpm = NULL;
static motorRpmParams_t motorRpm = {0};
static uint32_t rpmResult[4] = {0,0,0,0};

static void expCfBlTestInit(DeckInfo *info)
{
Expand All @@ -113,84 +105,11 @@ 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<NBR_OF_MOTORS; i++) {
motorsSetRatio(i, pwm);
}
}

static void runMotors()
{
#ifdef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT
motorsBurstDshot();
#endif
vTaskDelay(MOTOR_FEED_SIGNAL_INTVL);
}



static bool rpmTestRun(void)
{
uint16_t testTime = MOTOR_TEST_TIME_MILLIS;
int32_t waitTime = MOTOR_TEST_TIME_MILLIS;
uint32_t rpmSamples[] = {0,0,0,0};
setMotorsPwm(0);
while (waitTime) { //We need to wait until all ESCs are started. We need to feed a signal continuosly so they dont go to sleep
runMotors();
waitTime -= MOTOR_FEED_SIGNAL_INTVL;
}

setMotorsPwm(MOTOR_TEST_PWM);
while(testTime) {
runMotors();
testTime -= MOTOR_FEED_SIGNAL_INTVL;
for (int i = 0; i<NBR_OF_MOTORS; i++) {
rpmSamples[i] += getMotorRpm(i);
}
}

setMotorsPwm(0);
for (int i = 0; i<NBR_OF_MOTORS; i++) {
uint32_t rpmAvg = rpmSamples[i] / MOTOR_RPM_NBR_SAMPLES;
rpmResult[i] = rpmAvg;
if (bcRpm != NULL) {
isInit = true;
} else {
DEBUG_PRINT("bcRpm driver found\n");
}

return true; //Return True here regardless. This should be checked externally
}

static bool expCfBlTestRun(void)
Expand Down Expand Up @@ -246,13 +165,12 @@ static bool expCfBlTestRun(void)

decktestRestoreGPIOStatesABC(&gpioSaved);

//Run rpm test
if(status) {
if(bcRpm->init) {
bcRpm->init(NULL);
bcRpm->init(NULL);
} else {
status &= false;
}

status = rpmTestRun();
}
return status;
}
Expand All @@ -271,10 +189,4 @@ static const DeckDriver expCfBltest_deck = {
.test = expCfBlTestRun
};

PARAM_GROUP_START(prodTestRpm)
PARAM_ADD(PARAM_UINT32 | PARAM_RONLY, m1, &rpmResult[0])
PARAM_ADD(PARAM_UINT32 | PARAM_RONLY, m2, &rpmResult[1])
PARAM_ADD(PARAM_UINT32 | PARAM_RONLY, m3, &rpmResult[2])
PARAM_ADD(PARAM_UINT32 | PARAM_RONLY, m4, &rpmResult[3])
PARAM_GROUP_STOP(prodTestRpm)
DECK_DRIVER(expCfBltest_deck);

0 comments on commit 1e39685

Please sign in to comment.