Issues Found
1. 🐛 Global mutable state with no thread safety (main424.py:15-19)
roll_ctrl = 0
pitch_ctrl = 0
throttle_ctrl = 0
yaw_ctrl = 0
These globals are written by key_on_press (in keyboard listener thread) and read by the drone controller (main thread). No lock/mutex protection — classic data race. For a drone control system, corrupted control values could cause dangerous flight behavior.
Fix: Use threading.Lock() or queue.Queue for thread-safe communication.
2. 🐛 Control inputs accumulate without bounds (main424.py:50-62)
pitch_ctrl += key_press_delta # Just keeps adding
roll_ctrl += key_press_delta # No max limit
Holding a key continuously adds to the control value with no upper bound. This could result in extremely large velocity commands sent to the drone.
Fix: Clamp values: pitch_ctrl = min(max_val, pitch_ctrl + delta)
3. 🏗️ Typo in comment (main424.py:15)
# A global variale # should be 'variable'
4. 🧹 Hardcoded file path (main424.py:32)
config.json path is relative — will break if script is run from a different directory.
Issues Found
1. 🐛 Global mutable state with no thread safety (main424.py:15-19)
These globals are written by
key_on_press(in keyboard listener thread) and read by the drone controller (main thread). No lock/mutex protection — classic data race. For a drone control system, corrupted control values could cause dangerous flight behavior.Fix: Use
threading.Lock()orqueue.Queuefor thread-safe communication.2. 🐛 Control inputs accumulate without bounds (main424.py:50-62)
Holding a key continuously adds to the control value with no upper bound. This could result in extremely large velocity commands sent to the drone.
Fix: Clamp values:
pitch_ctrl = min(max_val, pitch_ctrl + delta)3. 🏗️ Typo in comment (main424.py:15)
# A global variale # should be 'variable'4. 🧹 Hardcoded file path (main424.py:32)
config.jsonpath is relative — will break if script is run from a different directory.