This project contains three Python files that work together on the Jetson Orin Nano with an IMX477 camera and a Pixhawk 6C. The system detects an X-shaped target, shows it on a connected monitor, gives alignment guidance, and can trigger the motors through Pixhawk when the X is visible.
X_5.py is the base script for detecting the X target using a trained YOLO model (best_22.pt). Its main purpose is to open the camera, run detection on live frames, and display the results on the monitor connected to the Jetson.
This file is used to verify that:
- the camera is working
- the YOLO model is loading correctly
- the X target is being detected
- the detection is shown live on screen
The script loads a custom YOLO model from best_22.pt. If the file is missing, the program exits.
It uses a GStreamer pipeline to read video from the Jetson camera. The script supports two modes:
4k1080p
Although the display window is smaller, the important point is that inference is done on a full 1920×1080 frame, because the model was trained on full-resolution images.
For every frame:
- the frame is captured from the camera
- YOLO runs inference on the full-resolution frame
- bounding boxes and labels are generated for detected objects
- the frame is resized for display
- the result is shown on screen
The script draws:
- a green bounding box around the detected X
- a label showing class name and confidence
- FPS information
- number of detections
This is the default mode. It opens a display window and shows the live detection results on the monitor.
This mode does not open a video window. Instead, it prints detection results in the terminal such as:
- confidence
- center coordinates
- bounding box coordinates
- FPS
This is useful when running over SSH.
This mode captures one frame, runs detection once, draws the result, and saves the image to disk.
X_5.py is the basic vision script. It answers this question:
Can the Jetson detect the X and show it on the connected monitor?
The answer is yes. This file is only for detection and display. It does not guide centering and does not control the motors.
x_detect_guide.py builds on the first script. It not only detects the X, but also calculates where the X is located relative to the center of the camera frame. This helps the user understand how to move the camera or drone so the X becomes centered.
This file is used to:
- detect the X
- find the center of the X
- compare that center with the frame center
- show guidance for alignment
No. This script does not directly move the camera or the drone.
What it does is compute and display movement guidance such as:
- move left
- move right
- move up
- move down
- centered
So this file is used to tell how to move so the X comes to the center of the drone camera view.
The script supports two methods:
This method takes the midpoint of the YOLO bounding box. It is simple and fast.
This method looks inside the detected bounding box, segments green pixels in HSV color space, and calculates the centroid of the green region. This is meant to estimate the crossing point of the X more accurately.
If the refined method cannot find enough green pixels, it falls back to the bounding-box center.
The script calculates:
dx = cx - frame_center_xdy = cy - frame_center_y
Where:
cx, cy= center of the detected Xframe_center_x, frame_center_y= center of the camera frame
Interpretation:
dx < 0means the X is left of centerdx > 0means the X is right of centerdy < 0means the X is above centerdy > 0means the X is below center
A configurable deadzone is used. If the X center is within the deadzone, the target is treated as centered.
This script displays:
- bounding box around the X
- crosshair at the frame center
- colored dot at the X center
- line connecting the X center to the frame center
- offset values
- guidance text such as
LEFT,RIGHT,UP,DOWN, orCENTERED
It also prints movement guidance in the terminal, for example:
- searching for X
- move left
- move right
- centered
Shows the annotated camera feed on the monitor and prints guidance in the terminal.
Runs without a display window and only prints guidance text in the terminal.
Captures one frame, computes the center and guidance, draws the annotations, and saves the result.
x_detect_guide.py is the guidance script. It answers this question:
How should the drone or camera move so the X is in the center?
So yes, this file is used to tell whether the X is left, right, above, or below the center, and whether alignment is correct.
It does not control motors. It only gives visual and terminal guidance.
x_detect_motor.py is the action script. It connects the Jetson vision system to the Pixhawk using pymavlink. When the X is detected, it triggers motor activity.
This file is used to:
- detect the X
- connect Jetson to Pixhawk
- arm the flight controller
- spin the motors
- stop and disarm after a fixed duration
This script includes a strong safety warning:
REMOVE PROPS FOR TESTING
That warning is critical because this script can actually command the motors.
Like the other files, this script captures frames from the camera and runs YOLO inference using best_22.pt.
The script connects to Pixhawk through a serial port such as:
/dev/ttyACM0
It uses a baud rate such as:
115200
It waits for a MAVLink heartbeat before proceeding.
If at least one X is detected and the motors are not already running, the script treats that as the trigger event.
When triggered, the script:
- force-arms the Pixhawk
- sends
MAV_CMD_DO_MOTOR_TESTto motors 1, 2, 3, and 4 - runs them at the requested throttle percentage
- keeps them running for the configured duration
- force-disarms afterward
The file supports configurable settings such as:
- confidence threshold
- serial device
- baud rate
- throttle percentage
- motor duration
A very useful safety feature is --dry-run.
In dry-run mode:
- the camera and detection still run
- the system behaves as though it detected the X
- but it does not connect to Pixhawk or spin the motors
This is useful for testing the logic safely.
The monitor shows:
- live video
- bounding boxes
- center points of detections
- FPS
- status text
When motors are active, the display also shows:
- red border
- motor active status
- remaining time
x_detect_motor.py is the control script. It answers this question:
Can Jetson detect the X and tell Pixhawk to start the motors?
Yes. This file is the one that connects visual detection with Pixhawk motor commands.
These three files represent three stages of the system:
See the X
- detects the X
- shows the result on the monitor
- useful for basic model testing
Center the X
- detects the X
- finds the X center
- compares it to frame center
- tells how to move so the X becomes centered
React to the X
- detects the X
- communicates with Pixhawk
- arms and runs motors when the X is visible
This project is structured in a progressive way:
X_5.pyverifies X detection and live displayx_detect_guide.pyadds alignment and centering guidancex_detect_motor.pyadds Pixhawk motor control based on X visibility
In simple words:
X_5.py= detect and show the Xx_detect_guide.py= guide movement to center the Xx_detect_motor.py= trigger motors when the X is detected
This makes the system suitable for target detection, alignment assistance, and hardware triggering in a Jetson + Pixhawk workflow.