task not working

Firmware/software/electronics/mechanics
Post Reply
SH_Lee
Member
Posts: 51
Joined: Tue Feb 18, 2020 8:48 am

task not working

Post by SH_Lee »

I saw the test example and added a new test.
After uploading the code, there was no response in the result window.
I simply wanted to make sure that the rtos worked internally.
We raised the rots priority from 1 to 4 in the example, but the results were the same.
Did anyone succeed in this example?
Attachments
dd.JPG
d.JPG
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: task not working

Post by kimberly »

You need to be more specific in your forum question. Which example task are you referring to? Provide links to it as well.

Something that I can already see, is that there are no delays in your while loop. Add delays with vTaskDelay().

Also, if you want to test out freertos, you can also experiment with the applayer. We are providing examples in the crazyflie firmware repo as well.
SH_Lee
Member
Posts: 51
Joined: Tue Feb 18, 2020 8:48 am

Re: task not working

Post by SH_Lee »

i
Last edited by SH_Lee on Sun Oct 11, 2020 1:21 pm, edited 1 time in total.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: task not working

Post by kimberly »

Hi! I'm so sorry but I accidentally removed your last post (I wanted to remove the one with the 'i' only). It's very difficult to restore it... was your situation solved? Maybe best if it is another issue to start another thread.

Very sorry about this again.
SH_Lee
Member
Posts: 51
Joined: Tue Feb 18, 2020 8:48 am

Re: task not working

Post by SH_Lee »

Fortunately, I solved the first problem, but I thought it was not a perfect solution, so I asked again.
The new problem is that rtos affects the task of the existing stabilizer.
After adding a new task, the console results show the following:

Code: Select all

ESTKALMAN: State out of bounds, resetting
I think it's because of the delay inside new task.
I used

Code: Select all

vTaskDelay(M2T(160);
but the internal delay time was reduced and the console output cycle became longer.

Q : How long is it not affecting the existing tasks when creating a new task?
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: task not working

Post by kristoffer »

I assume you are referring to this example https://www.bitcraze.io/documentation/r ... ystemtask/
ESTKALMAN: State out of bounds, resetting
Simply means that the position (state) estimator has drifted off to some improbable position and is reset. This happens if there is no good positioning information, for instance if you have a lighthouse deck mounted but no base stations running. It is probably not related to your new task.
We raised the rots priority from 1 to 4 in the example, but the results were the same.
In most cases your task should run at level 1 (of course depending on what you want to achieve), on higher priorities there is a risk you disrupt sensor readings and other time critical functionality. A task on level 1 should get around half of the CPU if you are using the lighthouse system so you should get plenty of execution time.

It is unfortunately hard to provide any help without your code.

A delay in a task is actually a good thing, it means that you hand the CPU back to the system and let other tasks execute. You can read more about FreeRTOS tasks here https://www.freertos.org/taskandcr.html
SH_Lee
Member
Posts: 51
Joined: Tue Feb 18, 2020 8:48 am

Re: task not working

Post by SH_Lee »

Code: Select all


#include "config.h"
#include "debug.h"
#include "FreeRTOS.h"
#include "queue.h"
#include "static_mem.h"
#include "task.h"
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

#include "radiolink.h"
#include "configblock.h"

#include "log.h"

#include "stabilizer_types.h"

static xQueueHandle inputQueue;
STATIC_MEM_QUEUE_ALLOC(inputQueue, 1, sizeof(int));
static void P2PTask(void*);
static void P2PTaskEnqueueInput(int value);
STATIC_MEM_TASK_ALLOC(P2PTask, P2P_TASK_STACKSIZE);
static bool isInit = false;

static P2PPacket Master_state;

void P2PTaskInit() {
  inputQueue = STATIC_MEM_QUEUE_CREATE(inputQueue);
  STATIC_MEM_TASK_CREATE(P2PTask, P2PTask, P2P_TASK_NAME, NULL, P2P_TASK_PRI);
  isInit = true;
}
bool P2PTaskTest() {
  return isInit;
}

void master_com()
{
	Master_state.port=0x00;
	Master_state.data[0] = 1;
	Master_state.data[1] = 2;
	Master_state.data[2] = 3;
	Master_state.size=3;
	radiolinkSendP2PPacketBroadcast(&Master_state);
}


static void P2PTask(void* parameters) {
  DEBUG_PRINT("\nExample task main function is running!\n\n");
 /* Master_state.port=0x00;
  	Master_state.data[0] = 1;
  	Master_state.data[1] = 2;
  	Master_state.data[2] = 3;
  	Master_state.size=3;*/


  while (true) {
    uint16_t input;
    P2PTaskEnqueueInput(input);
    if (pdTRUE == xQueueReceive(inputQueue, &input, portMAX_DELAY)) {
    	master_com();
    }
  }
}
void P2PTaskEnqueueInput(int value) {
  xQueueOverwrite(inputQueue, &value);
}

It's the code that makes me as successful as I can after many tests.
No additional delay was used, and the portMax_Delay of xQueueReceive inside the 'while' phrase is the only delay function.
As a result of P2P communication using this, two drones were able to communicate properly.
I would like to use vTaskDelayUntil to ensure P2P performance while performing additional operations inside this file.
I want to compute data while ensuring the stability of communication because I am aiming for multi-communication of multiple drones and also for flight control through data exchange.
Of course, I don't think the computation process takes a lot of time, but I want to make sure about this, so I leave a question.
Knowing this result will be very helpful not only for my experiment but also for creating other tasks.


Assuming that there is no additional computation, the code above works perfectly and normally. :D
Post Reply