Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Discussions about all things Bitcraze
Post Reply
kashishdhal
Beginner
Posts: 7
Joined: Sun Apr 12, 2020 10:49 pm

Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Post by kashishdhal »

Hello All,

I want to program the crazyflie MCU by adding custom .c files. The aim is to have a custom algorithms works. Later, I also want to flash FreeRTOS and build my own firmware on the top of it.

Please let me know that how should I go in steps for the same.

Regards,
Kashish Dhal
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Post by kristoffer »

Hi!

it is a very broad question but you could maybe start with the "getting started with development" tutorial https://www.bitcraze.io/documentation/t ... velopment/

You can find the source code for the Crazyflie firmware on github https://github.com/bitcraze/crazyflie-firmware
To add new c files to the project you will have to modify the Makefile in the root of that project

You can read more about FreeRTOS here https://www.freertos.org/index.html
kashishdhal
Beginner
Posts: 7
Joined: Sun Apr 12, 2020 10:49 pm

Re: Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Post by kashishdhal »

Hello,

I followed the link given by you. But the VM does not seem to work. Also, I am not sure, if it is even supported. I created an issue on github regarding this here: https://github.com/bitcraze/bitcraze-vm/issues/47

But if for now I want to skip testing on my PC. I just want to understand how FreeRTOS is implemented on MCU, is there any document for that? If I understand that then I will be able to modify the files accordingly.

I tried to read through the code but I could not understand that how many threads are created in the RTOS. Usually, I create the threads in main.c after hardwareInit but I guess I do not have the expertise to follow the code the way it's implemented here. If someone can help me understand the flow of the code, how all .c files are connected and where the radio is getting and publishing the commands then it would be great!

The main purpose would be to send the motor commands directly from ROS. Also, using the stabilizer in between the time commands are not received so that drone doesn't loose it's stability.

Thanks!

Regards,
Kashish Dhal
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Post by tobias »

If you goal is to send commands from ROS there is already a ROS package for the Crazyflie.

Regarding FreeRTOS tasks you can check the config.h file which defines most of the tasks and priorities.

We have a deck framework to more simply add your own tasks. See howto here.
kashishdhal
Beginner
Posts: 7
Joined: Sun Apr 12, 2020 10:49 pm

Re: Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Post by kashishdhal »

So ROS package doesn't allow you to send the motor commands, from what I am aware of it allows to send cmd_vel (meaning velocity commands). For my application, I will probably need to modify the firmware and/or ROS package. I guess I would first have to track in which variable the radio commands are being received in the firmware. Then later, I will have to use those variables as motor commands in power_distibution_stock.c but I will also need to use on-board controller in between the time, the commands are not received from off-board controller. There will be a modification on ROS side to send motor commands directly instead of cmd_vel (velocity commands).
So if someone can point me how the packets are received in the firmware and in which variables they are stored, it will great!
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Flashing FreeRTOS or Adding custom .c files in Crazyflie MCU

Post by tobias »

There are some parameters that can be set to take over direct motor control, mainly used for testing. This tread is discussing the same thing. Maybe LucasR already implemented it.
Post Reply