Query regarding new deck creation.

Discussions about all things Bitcraze
Post Reply
imranmomtaz
Beginner
Posts: 25
Joined: Tue Mar 17, 2020 7:01 pm

Query regarding new deck creation.

Post by imranmomtaz » Fri May 22, 2020 11:31 pm

Hello,

I want to write a new deck file with the name mlModelDeck. I created a mlModelDeck.c file under deck/driver/src folder as suggested by https://www.bitcraze.io/documentation/r ... ent/howto/. This file has following content:

Code: Select all

#define DEBUG_MODULE "mlModelDeck"
#include "deck.h"
#include "system.h"
#include "commander.h"
#include "range.h"  // get the 6axis distance measurements
#include "log.h"

#include "FreeRTOS.h"
#include "task.h"

#include "debug.h"
#include "sysload.h"
#include "sensors.h"

#define TRUE 1
#define FALSE 0

// These are my variable which will be used in this deck
static float inModelIMU[12] = {0};
static float inModelIMUOld[6] = {0};
static float outModelIMU[6] = {0};
static float errorModelIMU[6] = {0};


static void mlModelDeckTask()
{
	// static setpoint_t setpoint;
	systemWaitStart();
    DEBUG_PRINT("FINISHED\n");

    static sensorData_t sensorData;
    uint32_t tick;
    vTaskDelay(M2T(200));

    while(1){
        // tick = xTaskGetTickCount();

        // This is where I will have following commented out code

        // // Error model input preparation and evaluate
        // // Saving old inputs
        // if (((tick+5) % 20) < 5){
        //   for (int ii=0;ii<6;ii++){
        //     inModelIMUOld[ii] = inModelIMU[ii];
        //   }
        //   inModelIMU[0] = sensorData.gyro.x/150;
        //   inModelIMU[1] = sensorData.gyro.y/150;
        //   inModelIMU[2] = sensorData.gyro.z/150;
        //   inModelIMU[3] = sensorData.acc.x/150;
        //   inModelIMU[4] = sensorData.acc.y/150;
        //   inModelIMU[5] = sensorData.acc.z/150;
        
        //   for (int ii=0;ii<6;ii++){
        //     // Preparing whole input for model
        //     inModelIMU[6+ii] = inModelIMUOld[ii];
        //     outModelIMU[ii] = 0;
        //   }
        //   // DEBUG_PRINT("tick: %d\n",tick);
        //   // DEBUG_PRINT("in_value: %f, %f, %f, %f, %f, %f\n", sensorData.gyro.x, sensorData.gyro.y, sensorData.gyro.z, sensorData.acc.x, sensorData.acc.y, sensorData.acc.z);
        //   // DEBUG_PRINT("in_value: %f, %f, %f, %f, %f, %f\n", inModelIMU[0], inModelIMU[1], inModelIMU[2], inModelIMU[3], inModelIMU[4], inModelIMU[5]);
        //   // get_inference_IMU(&inModelIMU,12/2,&outModelIMU);
        //   // vTaskDelay(M2T(100));
        //   DEBUG_PRINT("ou_value: %f, %f, %f, %f, %f, %f\n", outModelIMU[0], outModelIMU[1], outModelIMU[2], outModelIMU[3], outModelIMU[4], outModelIMU[5]);

        //   errorModelIMU[0] = outModelIMU[0] - sensorData.gyro.x/150;
        //   errorModelIMU[1] = outModelIMU[1] - sensorData.gyro.y/150;
        //   errorModelIMU[2] = outModelIMU[2] - sensorData.gyro.z/150;
        //   errorModelIMU[3] = outModelIMU[3] - sensorData.acc.x/150;
        //   errorModelIMU[4] = outModelIMU[4] - sensorData.acc.y/150;
        //   errorModelIMU[5] = outModelIMU[5] - sensorData.acc.z/150;
        // }
        vTaskDelay(M2T(100));
    }
}

static void init() {
	xTaskCreate(mlModelDeckTask, "mlModelDeckTask",
		1000 /* Stack size in terms of WORDS (usually 4 bytes) */,
		NULL, /*priority*/3, NULL);
}

static bool test() {
	return true;
}

const DeckDriver mlModelDeck = {
	.vid = 0,
	.pid = 0,
	.name = "mlModelDeck",

	.usedGpio = 0,  // FIXME: set the used pins

	.init = init,
	.test = test,
};

DECK_DRIVER(mlModelDeck);

LOG_GROUP_START(stabilizer)
LOG_ADD(LOG_FLOAT, errorModelIMU0, &errorModelIMU[0])
LOG_ADD(LOG_FLOAT, errorModelIMU1, &errorModelIMU[1])
LOG_ADD(LOG_FLOAT, errorModelIMU2, &errorModelIMU[2])
LOG_ADD(LOG_FLOAT, errorModelIMU3, &errorModelIMU[3])
LOG_ADD(LOG_FLOAT, errorModelIMU4, &errorModelIMU[4])
LOG_ADD(LOG_FLOAT, errorModelIMU5, &errorModelIMU[5])
LOG_GROUP_STOP(stabilizer)
I add

Code: Select all

PROJ_OBJ += mlModelDeck.o
at the end of #deck at the makefile and also added

Code: Select all

CFLAGS += -DDECK_FORCE=mlModelDeck
at config.mk file.

After compiling and flushing into the CF2.1, the client is showing 'self-test failure' (continuous red flash at M1 five times continuously).

Please advise what needs to be done to correct this. I went through some other deck program which seems to follow this structure.



kimberly
Bitcraze
Posts: 322
Joined: Fri Jul 06, 2018 11:13 am

Re: Query regarding new deck creation.

Post by kimberly » Mon May 25, 2020 11:14 am

Are you able to connect to the crazyflie through USB immediately after restart in the cfclient and read the console output? There might be an assert triggered and the console output will tell you where this happened.

I can't see what is wrong with the code. You can try to also comment out the logblock as well for a more minimal example.

imranmomtaz
Beginner
Posts: 25
Joined: Tue Mar 17, 2020 7:01 pm

Re: Query regarding new deck creation.

Post by imranmomtaz » Mon May 25, 2020 2:32 pm

Thanks for your reply.
"Are you able to connect to the crazyflie through USB immediately after restart in the cfclient and read the console output? There might be an assert triggered and the console output will tell you where this happened."

- Could you please walk me through this with screenshot if possible? That would be very helpful.
Thanks again.

kimberly
Bitcraze
Posts: 322
Joined: Fri Jul 06, 2018 11:13 am

Re: Query regarding new deck creation.

Post by kimberly » Tue May 26, 2020 6:40 am

There is not really a screenshot that can help you with.... just follow these steps:
  • Connect the crazyflie with an microusb cable to your computer
  • open up the cfclient and find USB0 in the dropdown_menu of 'select an interface' after pressing scan
  • restart the crazyflie with the power button and immediately press connect in the cfclient
  • Openup the console tab (view/tabs/console) and look at the output. There should be an assert error printed out there by the crazyflie
I have a feeling that it might be a logging assert, but the console output should tell you for sure. If you don't know how to read it, please copy paste it in this forum.

Post Reply