Bird
Raised Fist0
Drone Programmingprogramming~10 mins

Forward, backward, lateral movement in Drone Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Forward, backward, lateral movement
Start
↓
Receive Command
↓
Check Direction
↓
Forward
↓
Move Forward
↓
Update Position
↓
End/Wait
The drone receives a movement command, checks the direction, moves accordingly (forward, backward, or sideways), then updates its position.
Execution Sample
Drone Programming
move('forward', 5)
move('backward', 3)
move('left', 2)
Moves the drone forward 5 units, backward 3 units, then left 2 units.
Execution Table
StepCommandDirection CheckedAction TakenPosition ChangeOutput
1move('forward', 5)forwardMove forwardPosition +5 forwardPosition updated to +5 forward
2move('backward', 3)backwardMove backwardPosition -3 forwardPosition updated to +2 forward
3move('left', 2)lateral (left)Move leftPosition +2 leftPosition updated to +2 forward, +2 left
4EndN/AN/AFinal position recordedPosition: +2 forward, +2 left
💡 All commands executed, drone position updated accordingly.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
position_forward05222
position_backward00000
position_left_right00022
Key Moments - 2 Insights
Why does the forward position decrease after moving backward?
Because moving backward subtracts from the forward position, as shown in step 2 of the execution_table where position changes from +5 to +2 forward.
How is lateral movement different from forward/backward in position tracking?
Lateral movement affects a separate position variable (left/right), not the forward/backward position, as seen in step 3 where position_left_right changes.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the drone's forward position after moving backward?
A2
B5
C-3
D0
💡 Hint
Check the 'Position Change' and 'Output' columns at step 2 in the execution_table.
At which step does the drone move laterally?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for 'lateral' or 'left/right' in the 'Direction Checked' column in the execution_table.
If the drone moved right instead of left in step 3, how would position_left_right change?
AIt would decrease by 2
BIt would increase by 2
CIt would stay 0
DIt would become -2
💡 Hint
Lateral movement to the right increases the left/right position value, as shown in variable_tracker.
Concept Snapshot
move(direction, distance):
- direction: 'forward', 'backward', 'left', or 'right'
- distance: units to move
Forward/backward affect forward position
Left/right affect lateral position
Update position after each move
Full Transcript
This visual trace shows how a drone moves forward, backward, and laterally. The drone receives commands one by one. It checks the direction, moves accordingly, and updates its position. Forward and backward moves change the forward position value, while lateral moves change the left/right position. The execution table tracks each step, showing how the position changes. The variable tracker records position values after each move. Key moments clarify why backward movement reduces forward position and how lateral movement uses a separate position variable. The quiz tests understanding of position changes and movement directions.

Practice

(1/5)
1. Which command moves the drone forward by 5 meters?
easy
A. move_right(5)
B. move_forward(5)
C. move_left(5)
D. move_backward(5)

Solution

  1. Step 1: Understand the direction commands

    The command move_forward(distance) moves the drone forward by the given distance.
  2. Step 2: Match the distance and direction

    Since we want to move forward by 5 meters, move_forward(5) is the correct command.
  3. Final Answer:

    move_forward(5) -> Option B
  4. Quick Check:

    Forward move = move_forward(5) [OK]
Hint: Forward means move_forward with distance [OK]
Common Mistakes:
  • Confusing forward with backward commands
  • Using lateral move commands instead of forward
  • Mixing up distance units
2. Which of these is the correct syntax to move the drone 3 meters to the left?
easy
A. move_left(3)
B. moveLeft(3)
C. move_left 3
D. move_left(three)

Solution

  1. Step 1: Identify correct function syntax

    The correct syntax uses the function name followed by parentheses enclosing the distance number.
  2. Step 2: Check parameter type and spelling

    move_left(3) uses move_left(3) which is correct. moveLeft(3) uses camelCase which is incorrect here. move_left 3 misses parentheses. move_left(three) uses a word instead of a number.
  3. Final Answer:

    move_left(3) -> Option A
  4. Quick Check:

    Function call with number in parentheses [OK]
Hint: Use function_name(number) with parentheses and digits [OK]
Common Mistakes:
  • Omitting parentheses in function call
  • Using wrong case in function name
  • Passing string instead of number
3. What is the final position of the drone after these commands starting at (0,0)?
move_forward(4)
move_right(3)
move_backward(2)
move_left(1)
medium
A. (3, 4)
B. (3, 2)
C. (2, 2)
D. (2, 3)

Solution

  1. Step 1: Track vertical (forward/backward) movement

    Start at (0,0). move_forward(4) moves y from 0 to 4. move_backward(2) moves y from 4 to 2.
  2. Step 2: Track horizontal (left/right) movement

    move_right(3) moves x from 0 to 3. move_left(1) moves x from 3 to 2.
  3. Step 3: Calculate final coordinates

    Final position is (2, 2).
  4. Final Answer:

    (2, 2) -> Option C
  5. Quick Check:

    Horizontal = 3-1=2, Vertical = 4-2=2 [OK]
Hint: Add forward/backward to Y, left/right to X [OK]
Common Mistakes:
  • Mixing X and Y axes
  • Forgetting backward subtracts from Y
  • Ignoring left movement subtracts from X
4. Identify the error in this drone movement code:
move_forward(5)
move_left(2)
move_backward()
move_right(3)
medium
A. Missing distance argument in move_backward()
B. move_left should be move_right
C. move_forward cannot be called first
D. move_right has wrong syntax

Solution

  1. Step 1: Check each function call for required arguments

    All move commands require a distance number. move_backward() is missing the distance argument.
  2. Step 2: Verify other commands

    move_left(2), move_forward(5), and move_right(3) all have correct syntax and arguments.
  3. Final Answer:

    Missing distance argument in move_backward() -> Option A
  4. Quick Check:

    Functions need distance parameter [OK]
Hint: All move commands need a number inside parentheses [OK]
Common Mistakes:
  • Calling move functions without distance
  • Confusing left and right commands
  • Assuming order of commands matters for syntax
5. You want the drone to move in a square path of 4 meters each side starting at (0,0). Which sequence of commands achieves this?
hard
A. move_right(4) move_forward(4) move_left(4) move_forward(4)
B. move_forward(4) move_left(4) move_backward(4) move_left(4)
C. move_forward(4) move_right(4) move_right(4) move_backward(4)
D. move_forward(4) move_right(4) move_backward(4) move_left(4)

Solution

  1. Step 1: Understand square path directions

    A square path means moving forward, then right, then backward, then left, each by the same distance.
  2. Step 2: Check each option's sequence

    move_forward(4) move_right(4) move_backward(4) move_left(4) follows forward, right, backward, left by 4 meters each, completing a square back to start.
  3. Step 3: Verify final position

    After these moves, the drone returns to (0,0), confirming a square path.
  4. Final Answer:

    move_forward(4) move_right(4) move_backward(4) move_left(4) -> Option D
  5. Quick Check:

    Square path = forward, right, backward, left [OK]
Hint: Square path: forward, right, backward, left same distance [OK]
Common Mistakes:
  • Mixing left and right order
  • Not returning to start point
  • Using different distances for sides
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard