📖 Scenario: You are programming a simple drone. The drone has four motors: front-left, front-right, back-left, and back-right. Each motor's speed controls how the drone moves in the air.By changing the speed of each motor, the drone can move forward, backward, left, right, or hover in place.
🎯 Goal: You will create a program that sets the speeds of the four motors and then calculates the drone's movement direction based on those speeds.This will help you understand how motor speeds control drone movement.
📋 What You'll Learn
Create a dictionary with the four motors and their speeds
Add a threshold speed variable to decide if the drone moves or hovers
Write logic to determine the drone's movement direction based on motor speeds
Print the movement direction
💡 Why This Matters
🌍 Real World
Understanding how motor speeds affect drone movement helps in programming drones for tasks like delivery, photography, or exploration.
💼 Career
Drone programmers and robotics engineers use motor speed control to make drones move precisely and safely.
Progress0 / 4 steps
1
Set motor speeds
Create a dictionary called motor_speeds with these exact entries: 'front_left': 1000, 'front_right': 1000, 'back_left': 1000, 'back_right': 1000.
Drone Programming
Hint
Use a dictionary with keys as motor names and values as speeds.
2
Add movement threshold
Create a variable called threshold and set it to 1050. This will be the speed above which the drone moves in that motor's direction.
Drone Programming
Hint
Just create a simple variable with the number 1050.
3
Determine movement direction
Write code to set a variable movement to one of these strings based on motor speeds compared to threshold: 'hover', 'forward', 'backward', 'left', or 'right'. Use these rules: - If all motor speeds are below threshold, movement is 'hover'. - If front motors are below threshold and back motors are above or equal, movement is 'forward'. - If back motors are below threshold and front motors are above or equal, movement is 'backward'. - If left motors are below threshold and right motors are above or equal, movement is 'right'. - If right motors are below threshold and left motors are above or equal, movement is 'left'.
Drone Programming
Hint
Use if and elif statements to compare motor speeds with the threshold and assign movement.
4
Print the movement
Write a print statement to display the value of the movement variable.
Drone Programming
Hint
Use print(movement) to show the result.
Practice
(1/5)
1. What happens when all four drone motors run at the same speed?
easy
A. The drone spins rapidly in place
B. The drone hovers or moves straight up or down
C. The drone moves sideways
D. The drone immediately lands
Solution
Step 1: Understand motor speed effect on lift
When all motors run at the same speed, they produce equal lift, balancing the drone.
Step 2: Determine movement from equal lift
Equal lift means the drone either stays in place (hover) or moves straight up/down if speed changes.
Final Answer:
The drone hovers or moves straight up or down -> Option B
Quick Check:
Equal motor speeds = hover/up/down [OK]
Hint: Same speed on all motors means hover or vertical move [OK]
Common Mistakes:
Thinking equal speeds cause spinning
Assuming sideways movement with equal speeds
Confusing motor speed with drone landing
2. Which of the following is the correct way to set motor speeds in code to make the drone hover?
easy
A. setMotorSpeeds(100, 90, 100, 90);
B. setMotorSpeeds(0, 0, 0, 0);
C. setMotorSpeeds(100, 100, 100, 100);
D. setMotorSpeeds(100, 110, 90, 100);
Solution
Step 1: Identify equal motor speeds for hover
Hover requires all motors to run at the same speed to balance lift.
Step 2: Check each option for equal speeds
Only setMotorSpeeds(100, 100, 100, 100); has all motors set to 100, equal speeds for hover.
Final Answer:
setMotorSpeeds(100, 100, 100, 100); -> Option C
Quick Check:
Equal speeds in code = hover [OK]
Hint: Equal values in all motor speed parameters mean hover [OK]
Common Mistakes:
Using different speeds thinking it still hovers
Setting all speeds to zero which stops motors
Mixing up parameter order
3. Given this code snippet:
setMotorSpeeds(120, 100, 120, 100);
What movement will the drone most likely perform?
medium
A. Move forward
B. Hover in place
C. Tilt sideways and move right
D. Rotate clockwise
Solution
Step 1: Analyze motor speed differences
Motors 1 and 3 run faster (120) than motors 2 and 4 (100), creating torque imbalance.
Step 2: Understand effect of torque imbalance
This imbalance causes the drone to rotate (yaw) clockwise due to uneven motor speeds.
Final Answer:
Rotate clockwise -> Option D
Quick Check:
Unequal opposite motors speed = rotation [OK]
Hint: Faster opposite motors cause rotation [OK]
Common Mistakes:
Assuming forward movement from speed difference
Thinking drone hovers with different speeds
Confusing rotation direction
4. This code is intended to make the drone move forward:
setMotorSpeeds(110, 110, 90, 90);
But the drone spins instead. What is the likely error?
medium
A. Left and right motors have different speeds causing spin
B. Front motors are slower than rear motors
C. Motors on opposite sides have same speeds causing rotation
D. All motors have equal speeds causing hover
Solution
Step 1: Identify motor speed pairs
Motors 1 and 2 are 110, motors 3 and 4 are 90; left and right sides differ.
Step 2: Understand effect of left-right speed difference
Different speeds on left vs right cause the drone to spin (yaw), not move forward.
Final Answer:
Left and right motors have different speeds causing spin -> Option A
Quick Check:
Unequal left-right speeds = spin [OK]
Hint: Left-right speed difference causes spin, not forward move [OK]
Common Mistakes:
Thinking front-rear speed difference causes spin
Assuming equal speeds cause spin
Mixing motor numbering sides
5. You want the drone to tilt forward and move forward smoothly. Which motor speed setting is best?
setMotorSpeeds(95, 95, 105, 105);
Why does this work?
hard
A. Front motors slower than rear motors tilt drone forward
B. Rear motors slower than front motors tilt drone backward
C. Left motors faster than right motors cause forward tilt
D. All motors equal speed cause forward movement
Solution
Step 1: Identify motor speed distribution
Motors 1 and 2 (front) run at 95, motors 3 and 4 (rear) at 105; front motors slower than rear.
Step 2: Understand tilt direction from speed difference
Slower front motors provide less lift upfront, tilting the nose down for forward movement.
Final Answer:
Front motors slower than rear motors tilt drone forward -> Option A
Quick Check:
Slower front motors = forward tilt [OK]
Hint: Slower front motors than rear tilt drone forward [OK]
Common Mistakes:
Thinking faster front motors tilt forward
Confusing left-right with front-rear speeds
Assuming equal speeds cause tilt
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.