Bird
Raised Fist0
Drone Programmingprogramming~10 mins

goto() command for navigation in Drone Programming - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - goto() command for navigation
Start
Call goto(x, y, z)
Calculate path to (x, y, z)
Move drone step-by-step
Check if reached (x, y, z)?
NoContinue moving
Yes
Stop movement
End
The drone receives a goto(x, y, z) command, calculates the path, moves step-by-step, checks if it reached the target, and stops when it arrives.
Execution Sample
Drone Programming
goto(10, 5, 3)
// Drone moves from current position to (10,5,3)
// Stops when it reaches the target
This code moves the drone from its current position to coordinates (10, 5, 3) and stops when it arrives.
Execution Table
StepCurrent Position (x,y,z)Target Position (x,y,z)Distance to TargetActionOutput
1(0,0,0)(10,5,3)CalculatedStart moving towards targetMoving
2(2,1,0.6)(10,5,3)8.7Continue movingMoving
3(5,2.5,1.5)(10,5,3)5.9Continue movingMoving
4(8,4,2.4)(10,5,3)2.4Continue movingMoving
5(10,5,3)(10,5,3)0Reached target, stopStopped
6---End of navigation-
💡 Drone reached target position (10,5,3), distance is zero, navigation stops.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
current_position(0,0,0)(2,1,0.6)(5,2.5,1.5)(8,4,2.4)(10,5,3)(10,5,3)(10,5,3)
distance_to_targetCalculated8.75.92.4000
statusIdleMovingMovingMovingMovingStoppedStopped
Key Moments - 3 Insights
Why does the drone keep moving even when it is close to the target but not exactly there?
Because the distance to target is not zero yet (see execution_table steps 2-4), the drone continues moving until it exactly reaches the target.
What happens when the drone reaches the exact target coordinates?
At step 5 in the execution_table, distance becomes zero, so the drone stops moving and the navigation ends.
Does the drone jump directly to the target position?
No, the drone moves step-by-step towards the target, updating its position gradually as shown in the variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the drone's position at Step 3?
A(2,1,0.6)
B(8,4,2.4)
C(5,2.5,1.5)
D(10,5,3)
💡 Hint
Check the 'Current Position' column at Step 3 in the execution_table.
At which step does the drone stop moving?
AStep 4
BStep 5
CStep 3
DStep 2
💡 Hint
Look for the 'Action' column where it says 'Reached target, stop'.
If the drone started at (1,1,1) instead of (0,0,0), how would the distance at Step 1 change?
AIt would be smaller
BIt would be zero
CIt would be larger
DIt would be the same
💡 Hint
Distance depends on how far the drone is from the target at start, see variable_tracker for distance changes.
Concept Snapshot
goto(x, y, z) moves the drone to the target coordinates.
The drone moves step-by-step, checking distance each time.
When distance is zero, the drone stops.
Useful for precise navigation in 3D space.
Full Transcript
The goto() command tells the drone to move to a specific point in space. The drone calculates the path and moves step-by-step, updating its position and checking how far it is from the target. It keeps moving until it reaches the exact coordinates, then it stops. This process is shown step-by-step in the execution table and variable tracker, helping beginners see how the drone's position and status change over time.

Practice

(1/5)
1. What does the goto(x, y, z, speed) command do in drone programming?
easy
A. Moves the drone to the specified coordinates at the given speed.
B. Starts the drone's camera recording.
C. Lands the drone immediately.
D. Turns the drone around 360 degrees.

Solution

  1. Step 1: Understand the purpose of goto()

    The goto() command is designed to move the drone to a specific location using coordinates.
  2. Step 2: Analyze the parameters

    The parameters x, y, z represent the position in space, and speed controls how fast the drone moves there.
  3. Final Answer:

    Moves the drone to the specified coordinates at the given speed. -> Option A
  4. Quick Check:

    goto() moves drone = A [OK]
Hint: Remember: goto() moves drone to coordinates fast or slow [OK]
Common Mistakes:
  • Confusing goto() with camera or landing commands
  • Ignoring the speed parameter
  • Thinking goto() rotates the drone
2. Which of the following is the correct syntax to move a drone to position (10, 20, 5) at speed 3 using goto()?
easy
A. goto(10, 20, 3, 5)
B. goto(10, 20, 5, 3)
C. goto(3, 10, 20, 5)
D. goto(5, 3, 10, 20)

Solution

  1. Step 1: Identify parameter order

    The goto() command takes parameters in order: x, y, z, speed.
  2. Step 2: Match values to parameters

    Given position (10, 20, 5) and speed 3, the correct call is goto(10, 20, 5, 3).
  3. Final Answer:

    goto(10, 20, 5, 3) -> Option B
  4. Quick Check:

    Order is x,y,z,speed = C [OK]
Hint: Remember parameter order: x, y, z, then speed [OK]
Common Mistakes:
  • Mixing up speed with coordinate values
  • Changing parameter order
  • Using wrong numbers for coordinates
3. What will be the drone's final position after running this code?
goto(5, 5, 10, 2)
goto(10, 10, 5, 4)
medium
A. (0, 0, 0)
B. (5, 5, 10)
C. (15, 15, 15)
D. (10, 10, 5)

Solution

  1. Step 1: Execute first goto()

    The drone moves to coordinates (5, 5, 10) at speed 2.
  2. Step 2: Execute second goto()

    The drone then moves to (10, 10, 5) at speed 4, which is the final position.
  3. Final Answer:

    (10, 10, 5) -> Option D
  4. Quick Check:

    Last goto() position = A [OK]
Hint: Last goto() sets final position, earlier ones are overwritten [OK]
Common Mistakes:
  • Adding coordinates instead of replacing
  • Ignoring the second goto()
  • Confusing speed with position
4. Identify the error in this code snippet:
goto(10, 20, speed=5, 3)
medium
A. Speed parameter is given before z coordinate.
B. No error; code is correct.
C. Using named argument for speed but position parameters are positional.
D. Missing one coordinate parameter.

Solution

  1. Step 1: Check parameter usage

    The code mixes positional and named arguments incorrectly by placing speed=5 before the last positional argument.
  2. Step 2: Understand Python argument rules

    Positional arguments must come before named arguments; here, 3 is positional after a named argument, causing a syntax error.
  3. Final Answer:

    Using named argument for speed but position parameters are positional. -> Option C
  4. Quick Check:

    Named args after positional = D [OK]
Hint: Named arguments must come after all positional ones [OK]
Common Mistakes:
  • Placing named arguments before positional
  • Assuming order doesn't matter
  • Missing commas between parameters
5. You want the drone to inspect three points in order: (0,0,5), (10,0,5), and (10,10,5), each at speed 2. Which code correctly uses goto() to do this?
hard
A. goto(0, 0, 5, 2) goto(10, 0, 5, 2) goto(10, 10, 5, 2)
B. goto([0,0,5], 2) goto([10,0,5], 2) goto([10,10,5], 2)
C. goto(0, 0, 5) goto(10, 0, 5) goto(10, 10, 5)
D. goto(0, 0, 5, 2, 3) goto(10, 0, 5, 2, 3) goto(10, 10, 5, 2, 3)

Solution

  1. Step 1: Check parameter correctness

    Each goto() call must have four parameters: x, y, z, and speed.
  2. Step 2: Validate each option

    goto(0, 0, 5, 2) goto(10, 0, 5, 2) goto(10, 10, 5, 2) correctly uses four parameters per call. goto([0,0,5], 2) goto([10,0,5], 2) goto([10,10,5], 2) uses lists instead of separate coordinates. goto(0, 0, 5) goto(10, 0, 5) goto(10, 10, 5) misses speed. goto(0, 0, 5, 2, 3) goto(10, 0, 5, 2, 3) goto(10, 10, 5, 2, 3) has an extra parameter.
  3. Final Answer:

    goto(0, 0, 5, 2) goto(10, 0, 5, 2) goto(10, 10, 5, 2) -> Option A
  4. Quick Check:

    Correct parameters and order = B [OK]
Hint: Use four parameters: x, y, z, speed for each goto() [OK]
Common Mistakes:
  • Passing coordinates as a list instead of separate values
  • Omitting speed parameter
  • Adding extra parameters