Drone Movement
English translation
Learning objectives
Assuming forward and sideways directions stay the same after turning will lead to an incorrect path. First check the coordinate frames through calculation.
Execution conditions
This exercise simulates coordinates. When extending it to actual flight, separately check the provided device's coordinate system, units, and command response behavior.
Check movement command coordinates
Starting conditions
Start at (0,0) m with yaw=0°. Forward is body +x, right is body -y, and yaw is counterclockwise. Use the 5 provided commands.
Procedure
- For each command, record one table row with displacement in the Body Frame, displacement in the World Frame, cumulative position, and yaw.
- Use body_to_world to compare your predicted positions with the code.
- Label the XY path with command sequence numbers and axis units.
Results to retain
- A 5-row command table and 1 XY path.
import math
import numpy as np
import matplotlib.pyplot as plt
# world x: initial forward direction, world y: initial left direction, yaw: counterclockwise in degrees
commands=[('forward',1.),('right',.5),('yaw',90.),('forward',1.),('right',.5)]
pos=np.array([0.,0.]);yaw=0.;trace=[pos.copy()]
def body_to_world(dx,dy,yaw_deg):
a=math.radians(yaw_deg)
return np.array([[math.cos(a),-math.sin(a)],[math.sin(a),math.cos(a)]])@np.array([dx,dy])
# Example: world displacement for 1 m forward at yaw=90
print(body_to_world(1,0,90))
# TODO: Interpret commands in order and record position and yaw.
Record results and self-check
Command:
Displacement in the Body Frame [m]:
Displacement in the World Frame [m]:
Cumulative (x,y) [m]:
yaw [deg]:
Points to check
- Does position remain unchanged when only a yaw command executes?
- Does the displacement vector retain its length after rotation?
Different paths to the same destination
Starting conditions
Use the final position of the first command sequence as the destination and create a new path aligned with the world axes, keeping yaw=0.
Procedure
- Specify the second command sequence you designed.
- Compare the two paths' final position error, total travel distance, and number of turns.
- Explain whether shortest distance and ease of executing actual commands are the same criterion.
Results to retain
- An overlay of the two paths and a comparison table.
# Reuse the destination from the first activity and body_to_world.
route2=[('forward',1.5),('left',.5)]
# TODO: Check the final position from the first activity, then modify route2 to reach the destination.
Record results and self-check
Path:
Final position:
Destination error [m]:
Travel distance [m]:
Number of turns:
Points to check
- Do both paths have the same starting point and destination?
- Have you avoided assuming planar coordinates are identical to the flight SDK's actual coordinate frame?
Paths with command errors
Starting conditions
Add ±5% error to each movement distance. Fix seed=7 and 30 repetitions, and set yaw error to 0.
Procedure
- In each repetition, perturb only distance commands and save the final position.
- Plot the final positions as a scatter plot and calculate the mean and maximum distance error from the destination.
- Compare results with error rates of 0%,5%,10%.
Results to retain
- A position scatter plot, a table for 3 conditions, and a brief interpretation.
rng=np.random.default_rng(7)
length_errors=rng.uniform(-.05,.05,size=(30,4))
# TODO: Apply error only to distance commands, excluding yaw.
Record results and self-check
Error rate:
Repetition count:
Mean position error [m]:
Maximum error [m]:
Points to check
- Did you record the seed and error distribution?
- At 0% error, does the path return to the reference path's destination?