Course materials · Robot Basic Lab

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

  1. For each command, record one table row with displacement in the Body Frame, displacement in the World Frame, cumulative position, and yaw.
  2. Use body_to_world to compare your predicted positions with the code.
  3. Label the XY path with command sequence numbers and axis units.

Results to retain

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

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

  1. Specify the second command sequence you designed.
  2. Compare the two paths' final position error, total travel distance, and number of turns.
  3. Explain whether shortest distance and ease of executing actual commands are the same criterion.

Results to retain

# 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

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

  1. In each repetition, perturb only distance commands and save the final position.
  2. Plot the final positions as a scatter plot and calculate the mean and maximum distance error from the destination.
  3. Compare results with error rates of 0%,5%,10%.

Results to retain

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

Official examples and data