Exercises
- Submission
- Overview
- Instructions for using the files
- Instruction for running the target tracking simulation
- Deliverable 1 - Complete the Target Tracking MPC Implementation (80 pts)
- Deliverable 2 - Testing and Validation (20 pts)
- Expected Behavior
- Deliverables
Submission
Team
Each group should create a new folder called TEAM_<N> replacing <N> with your team number. For example team 2 will name their folder TEAM_2. Please put the source code of the entire controller_pkg package in the folder TEAM_2. Zip the folder and submit to Canvas.
Each team will only need to submit one TEAM_<N>.zip to Canvas.
For organizing the submission better, please include a single report (PDF format) inside your folder that includes your answers, explanations, video file names and copy of the Python code that you edit/write. Please make sure to include your team member names and IDs in the report.
Deadline: To submit your solution, please upload the corresponding files under Assignment > Lab 4 by Mon, Oct 13 11:59 EST.
Overview
In Lab 4, you will extend the MPC controller from Lab 3 to implement target tracking capabilities. The main difference is that instead of following predefined trajectories, your drone will obtain the position of a target drone in real-time and use the Model Predictive Control (MPC) framework developed in Lab 3 to track the target. We launch two drones in the simulator: cf_1 (the target) and cf_2 (the pursuer). Each drone runs its own instance of the MPC controller. The target drones runs the MPC controller from Lab 3 to track fixed trajectories, whereas cf_2 receives real-time position updates of cf_1 via a ROS2 topic subscription. For this lab, the deliverable includes the new MPC controller node, that tracks a specific target drone. We will use the same simulator for the Crazyflie quadrotor, and also the same controller_pkg ROS2 package that we developed in Lab 3. The new files for Lab 4 are provided in the lab4 folder of the ae740_labs repository.
Instructions for using the files
-
Pull the latest version of
ae740_labsrepository to get the Lab 4 files (is thelab4folder): -
Copy the
target_tracking_mpc.pyfile fromlab4folder to your existingros2_ws/src/controller_pkg/controller_pkg/directory, that we used in Lab 3. This is important as this file is the equivalent for thecrazyflie_mpc.pyfile and also calls thequadrotor_simplified_model.pyandtracking_mpc.pyfiles that you developed in Lab 3. -
Inside the
ros2_ws/src/controller_pkgdirectory, create a new folder calledlaunchand add a new launch filelaunch_lab4_target_tracking.launch..pyprovided in thelab4folder. This launch file will launch two drones – one with thetarget_tracking_mpc.pynode, and the other with thecrazyflie_mpc.pynode. -
Replace the existing
setup.pyfile incontroller_pkgwith the one provided in thelab4folder. This is important as it ensures that the new launch file can be found and executed correctly.
Instruction for running the target tracking simulation
These steps assume you completed the coding part in the target_tracking_mpc.py file.
Terminal 1: Launch Gazebo SITL with 2 drones (inside ae740_crazyflie_sim directory)
cd crazyflie-firmware
bash tools/crazyflie-simulation/simulator_files/gazebo/launch/sitl_target_tracking.sh -t 1 -p 1 -m crazyflie
Terminal 2: Luanch the Crazyswarm2 server
cd ros2_ws/
colcon build --symlink-install # if not already built
source install/setup.bash
ros2 launch crazyflie launch.py backend:=cflib
Terminal 3: Launch MPC controllers for both drones
cd ros2_ws/ && source install/setup.bash
ros2 launch controller_pkg launch_lab4_target_tracking.py
Terminal 4: Commands to takeoff and start the target tracking
# Step 1: Takeoff both drones
ros2 topic pub -t 1 /all/mpc_takeoff std_msgs/msg/Empty
# Step 2: Start the tracking simulation
ros2 topic pub -t 1 /all/mpc_trajectory std_msgs/msg/Empty
Note: Sometimes, rarely though, you might get the warning Empty state message., which is because either position or velocity of one of the drones is not properly initialized on the ROS2 server. To resolve, re-run the main commands on terminals 1 and 2 before attempting again.
Deliverable 1 - Complete the Target Tracking MPC Implementation (80 pts)
The new controller node target_tracking_mpc.py has most of the structure same as crazyflie_mpc.py node used in Lab 3. The key differences are summarized below:
Lab 3 (Basic MPC)
- The main controller node:
crazyflie_mpc.py - Single drone following predefined trajectories
- Static reference generation
- No real-time target information
Lab 4 (Target Tracking MPC)
- The main controller node:
target_tracking_mpc.py - Two drones:
cf_1(target) andcf_2(pursuer/tracker) - Real-time target tracking:
cf_2followscf_1’s position - Dynamic reference generation based on target drone’s pose
- New trajectory type:
'target_tracking' - Additional subscriber: Target drone position subscriber
In the target_tracking_mpc.py file, the comments # [TODO LAB 4] indicate where you need to implement the additions for the target tracking functionality, in contrast to the crazyflie_mpc.py file from Lab 3. You can specifically search for [TODO LAB 4] to find the changes. The starter code include the TODO comments from Lab 3 as well, which you can ignore after finishing the Lab3 exercises.
Similarities with Lab 3:
- Position subscriber for own drone (
cf_2) - Velocity subscriber for own drone (
cf_2) - MPC solution path publisher
- Attitude setpoint command publisher
- Similar structure for initialization, timers, and MPC solver integration
- Target (
cf_1) runs using the basic MPC controller from Lab 3
Additions for Lab 4:
- New variable
target_nameis introduced to specify the target drone. - The target tracking functionality is added by introducing a trajectory type
'target_tracking'in thetrajectory_function(), where the reference position is set to the latest received target drone position. - A new subscriber and callback function is created to listen to the target drone’s position.
Deliverable 2 - Testing and Validation (20 pts)
Add a new trajectory with name lemniscate in the trajectory_function() of crazyflie_mpc.py file. The lemniscate (figure-eight) trajectory can be defined as:
Parameters:
a = 1.0b = 0.5 * tanh(0.1 * t)(for smooth start)
Position:
x_ref(t) = x_start + a * sin(b * t)
y_ref(t) = y_start + a * sin(b * t) * cos(b * t)
z_ref(t) = z_start
Velocity:
vx_ref(t) = a * b * cos(b * t)
vy_ref(t) = a * b * cos(2 * b * t)
vz_ref(t) = 0.0
Expected Behavior
cf_1should follow its predefined trajectory (circle, lemniscate, etc.)cf_2should track and followcf_1’s position- Both drones should maintain stable flight
- The tracking should be smooth without oscillations
Deliverables
- Working code (
target_tracking_mpc.pyfile only) that compiles and runs without errors - Video demonstration (30-60 seconds) showing:
- Both drones taking off
cf_1following a trajectorycf_2successfully trackingcf_1- Two separate videos for
circleandlemniscatetrajectories
- Parameter tuning documentation explaining any changes made to MPC parameters (changes to number of steps, weights, control rate can be needed for stable tracking)