Software

In order to control the Crazyflie drone to accomplish a perching trajectory we needed to first generate a reference trajectory and use Model Predictive Control to accurately track it. We used the TinyMPC library to run MPC onboard the crazyflie drone.

Trajectory Generation

In order to have successful drone perching, we decided to try and generate a dynamically feasible trajectory. We used a pre-made script in Julia: Notebook link that took the dynamics and control parameters of the Crazyflie drone and used the JuMP MPC framework to optimize a reference perching trajectory. This process outputted a time-constrained trajectory with position, orientation, and the corresponding velocities in the global reference frame. Next this trajectory is loaded into a .h header file and uploaded to the drone using the crazyflie-tinympc-firmware

Mobirise Website Builder

In the trajectory generation phase, a perching trajectory is created using the JuMP trajectory optimizer and loaded into a headerfile. This trajectory to loaded to the drone's firmware and flashed onto the Crazyflie.

Running TinyMPC

TinyMPC is a model predictive control framework designed to run on embedded platforms. A preloaded version of TinyMPC is provided to run on the Crazyflie platform here: . Since we were trying to use the lighthouse positioning system we also had to modify the src/deck/drivers/src/Kconfig file to enable support for the lighthouse deck. Afterwards, the examples/controller_tinympc_eigen/src/controller_tinympc.cpp file is the main script that is being ran to execute the MPC trajectory. The .h file generated by the trajectory generation code above can be placed in this directory and enabled in the .cpp script. Here, all of the parameters relating to the control rate and gravity compensation are also set before flashing the drone. Additionally, a max_iters parameter is provided to limit the number of iLQR iterations that are performed during each control loop. Next the drone can be flash by first compiling the tinympc app with `make` and then flashing with `make cload`. Now the drone is ready to run the perching trajectory!

Mobirise Website Builder

System Architecture - The Crazyflie is commanded through the Crazyflie python API and is sent a takeoff command in PID control mode. This allows the drone to takeoff and maintain a hover state. Then the drone is commanded to execute the MPC trajectory by setting the stabilizer.controller parameter. The drone's positioning is provided by the onboard kalman filter which fuses the position and orientation data from the IMU and lighthouses. 

Perching

After the drone has been loaded with the trajectory, we can now command the drone to takeoff, execute the perch and then stop the motors. For this we are using the Crazyflie python API and the PositionCommander module. We start by setting the hover state to 1 meter above the ground and making the stabilizer's controller set to be PID. This allows for the take off procedure to overcome the groundeffect force and be ready to enable MPC. Then we set the stabilizer.controller parameter to 5, indicating that the drone should now use the out of tree controller defined by TinyMPC. This starts execution of the perching trajectory and after 1 second we send a stop cmd to the motors. The drone is now perched! 

    RoboSys Final Project

    Carlo Colizzi
    Krishna Suresh
    Sam Kaplan

    HTML Code Generator