simulink_quadcopter_simulation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
simulink_quadcopter_simulation [2025/04/26 17:58] – yehyun | simulink_quadcopter_simulation [2025/04/26 22:21] (current) – yehyun | ||
---|---|---|---|
Line 5: | Line 5: | ||
**Date:** Last modified on < | **Date:** Last modified on < | ||
\\ | \\ | ||
- | **Keywords: | + | **Keywords: |
\\ | \\ | ||
\\ | \\ | ||
Line 22: | Line 22: | ||
* Deploy algorithms to a real Parrot Minidrone | * Deploy algorithms to a real Parrot Minidrone | ||
* Validate the results using motion capture data | * Validate the results using motion capture data | ||
- | * Modify the simulation for new drone specifications | ||
\\ | \\ | ||
---- | ---- | ||
Line 181: | Line 180: | ||
===== 5. Validating with Motion Capture ===== | ===== 5. Validating with Motion Capture ===== | ||
+ | In this section, we will apply the simulation to a real drone (Parrot Mambo) and collect flight data using a motion capture system. | ||
+ | By doing this, we can verify whether the drone moves as intended based on the input commands given in Simulink. | ||
+ | \\ | ||
+ | \\ | ||
==== 5.1 Deploying the Model to the Parrot Mambo Drone ==== | ==== 5.1 Deploying the Model to the Parrot Mambo Drone ==== | ||
Line 222: | Line 225: | ||
The drone will take off and follow the pre-programmed input commands. | The drone will take off and follow the pre-programmed input commands. | ||
After the flight is completed, the interface will show additional options to download the Flight Log and MAT File containing recorded flight data. | After the flight is completed, the interface will show additional options to download the Flight Log and MAT File containing recorded flight data. | ||
+ | \\ | ||
+ | \\ | ||
==== 5.2 Collecting Motion Capture Data for Drone Flight ==== | ==== 5.2 Collecting Motion Capture Data for Drone Flight ==== | ||
+ | Now that the drone is flying, we want to measure its actual movement using the motion capture (Mocap) system. | ||
+ | |||
+ | **- Preparing the Motion Capture System** | ||
+ | \\ Before collecting data, you need a working motion capture setup. | ||
+ | Detailed setup procedures, including hardware calibration and scene creation, are already available in the [[optitrack_motion_capture_system_setup_guide|Optitrack Motion Capture System Setup Guide]]. | ||
+ | |||
+ | * Complete the basic calibration and scene setup following the motion capture tutorial. | ||
+ | * Make sure that a rigid body for the drone is created. (In our example, the rigid body name is lego_drone, but you can choose any name as long as it matches later.) | ||
+ | |||
+ | **- Setting Up ROS to Collect Data** | ||
+ | \\ Once the motion capture environment is ready and the drone is flying, you can record its motion data in real-time using a Python script. | ||
+ | |||
+ | We will subscribe to the <color # | ||
+ | |||
+ | Here’s the full step-by-step process: | ||
+ | \\ 1. Open a terminal and run: | ||
+ | roscore | ||
+ | 2. Open another terminal and launch the VRPN client node: | ||
+ | rosrun vrpn_client_ros vrpn_client_node _server: | ||
+ | | ||
+ | example: | ||
+ | rosrun vrpn_client_ros vrpn_client_node _server: | ||
+ | |||
+ | * Make sure: | ||
+ | * < | ||
+ | * < | ||
+ | |||
+ | 3. Open a third terminal and navigate to the following directory: | ||
+ | cd ~/ | ||
+ | 4. Then run the Python script: | ||
+ | python3 mambo_drone.py | ||
+ | | ||
+ | {{ : | ||
+ | |||
+ | **Python Script to Collect Motion Capture Data** | ||
+ | \\ Below is the complete script that collects the drone’s position and saves it into a .csv file. | ||
+ | # | ||
+ | | ||
+ | import rospy | ||
+ | import csv | ||
+ | from geometry_msgs.msg import TransformStamped | ||
+ | | ||
+ | # Define the callback function to process incoming messages | ||
+ | def callback(msg): | ||
+ | # Extract the XYZ data from the TransformStamped message | ||
+ | x = msg.transform.translation.x | ||
+ | y = msg.transform.translation.y | ||
+ | z = msg.transform.translation.z | ||
+ | print(f" | ||
+ | | ||
+ | # Write the data to a CSV file | ||
+ | with open(' | ||
+ | writer = csv.writer(file) | ||
+ | # Write the header if the file is empty | ||
+ | if file.tell() == 0: | ||
+ | writer.writerow([" | ||
+ | # Write the data | ||
+ | writer.writerow([rospy.get_time(), | ||
+ | | ||
+ | def listener(): | ||
+ | # Initialize the ROS node | ||
+ | rospy.init_node(' | ||
+ | | ||
+ | # Subscribe to the estimated transform topic | ||
+ | rospy.Subscriber('/ | ||
+ | | ||
+ | # Keep the node running | ||
+ | rospy.spin() | ||
+ | | ||
+ | if __name__ == ' | ||
+ | try: | ||
+ | listener() | ||
+ | except rospy.ROSInterruptException: | ||
+ | pass | ||
+ | |||
+ | ==== 5.3 Validation through Mocap Experiment ==== | ||
+ | |||
+ | After deploying the controller and executing flight tests in the motion capture environment, | ||
+ | |||
+ | The following video shows the experimental setup. The Parrot Mambo drone, loaded with the deployed controller, was flown in the motion capture space while the flight data was simultaneously collected using mocap tracking: | ||
+ | {{youtube> | ||
+ | |||
+ | In this experiment, a step input was applied to the Z-axis command to observe the altitude control performance. Two different scenarios were tested: | ||
+ | |||
+ | **Scenario 1: Default Drone Weight** | ||
+ | \\ A step input commanding a rise from approximately 0.6 meters to 1.1 meters was given. The comparison between the simulation and real flight data is shown below: | ||
+ | {{ : | ||
+ | |||
+ | The blue solid and dashed lines represent the simulator and real-world Z positions, respectively. The results demonstrate that the real drone altitude closely followed the simulation prediction, validating the accuracy of the simulated model under nominal conditions. | ||
+ | |||
+ | **Scenario 2: Additional Payload** | ||
+ | \\ In this test, a 5g weight was attached to the drone to assess the robustness of the controller and the simulator under additional load conditions. The results are shown below: | ||
+ | |||
+ | Despite the added weight, the actual drone flight trajectory remained highly consistent with the simulator' | ||
+ | Overall, the close match between the simulated and actual flight data confirms the effectiveness and credibility of the developed quadcopter simulator. This validation provides confidence that the simulation environment can be used to predict real-world quadcopter behavior accurately. | ||
- | [[optitrack_motion_capture_system_setup_guide|Optitrack Motion Capture System Setup Guide]] | + | |
simulink_quadcopter_simulation.1745715498.txt.gz · Last modified: by yehyun