A Message from Pi to QGC

Hello, i am planning control DC motor through Raspberry Pi zero 2 W, which is connected to the Pixhawk 6C via Telem2 port. I am using PX4. I have established the connection and the plan is to control the DC motor movement (forward or backward) via RC9 switch, which i am able to send from Pixhawk to Pi.

#!/usr/bin/env python3
from pymavlink import mavutil
import time

def pwm_to_distance(pwm: int) → int:
if 900 <= pwm <= 1100:
return 50
elif 1400 <= pwm <= 1600:
return 100
elif pwm > 1900:
return 150
else:
return 0

master = mavutil.mavlink_connection(‘/dev/serial0’, baud=57600)

master.wait_heartbeat()
print(“Connected to PX4, system ID:”, master.target_system)

master.mav.statustext_send(

mavutil.mavlink.MAV_SEVERITY_CRITICAL,

‘PI Connected‘.encode
)

while True:
# Get RC_CHANNELS_RAW messages
msg = master.recv_match(type=‘RC_CHANNELS’, blocking=True)
if msg is not None:
rc9_pwm = msg.chan9_raw
stepper_dist = pwm_to_distance(rc9_pwm)

status_message = f"RC9 PWM: {rc9_pwm} → Stepper target: {stepper_dist} cm"
print(f"status_message: {status_message} at {time.time()}")

master.mav.statustext_send(

mavutil.mavlink.MAV_SEVERITY_INFO,

status_message.encode
)

time.sleep(0.5)

i have this code and it runs without any error, but i don’t see any message anywhere. There are no messages in speaker icon (in Fly view) nor in MAVLink Inspector. i don’t even see the STATUSTEXT tab under MAVLink Inspector.

MAV_1_MODE = onboard
MAV_1_CONFIG = TELEM2

The connection is properly established between Pi and PX4, when i flick the switch on remote control, it prints different messages on Pi screen.

Could some guide me on how to send message to QGC via this channel?

Format your code block so they’ll show as code blocks, easier for everyone to read.

Use search option and Google, this question (or similar) is repeated every once in a while.

Also try to enable forwarding. Please comment what solved your issue.

If you want to see the message only in MAVLink inspector, you must switch from system 1 to system 245 manually from top right corner. (this won’t show messages in vehicle message in fly panel)

master = mavutil.mavlink_connection(‘/dev/serial0’, baud=57600, source_system = 245)

if you want to show message in vehicle message in fly panel, change source_system = 1.

Other option is to change to code of QGC so it will show system 245 messages in vehicle message as well.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.