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?