Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't connect my device that works on Ubuntu 20.04 to QGC version 4.2.9 via mavlink #1223

Open
hilaelb opened this issue Jun 26, 2024 · 10 comments

Comments

@hilaelb
Copy link

hilaelb commented Jun 26, 2024

I have a simple code that I wrote on ubuntu 20.04. my goal is to connect to QGC and to see "Ready to fly" in the main screen.
my ip in the computer that qgc works on is 192.168.168.95 and my device ip is 192.168.168.5, when I run my device I can see in wireshark that there is communication between my device and qgc but still on the main screen it says "Disconnected"
this is my code on the device:

import rclpy
from rclpy.node import Node
from pymavlink import mavutil

class QGCcommNode(Node):
def init(self):
super().init("qgc_comm")
# Connect to the MAVLink instance
self.master = mavutil.mavlink_connection('udpout:192.168.168.95:14570', source_system =1,source_component=1 )
self.the_connection = mavutil.mavlink_connection('udpin:192.168.168.5:14575')
self.timer = self.create_timer(1, self.send_heartbeat)

# Function to send a heartbeat message
def send_heartbeat(self):
    try:
        self.master.mav.heartbeat_send(
            type=mavutil.mavlink.MAV_TYPE_GENERIC,
            autopilot=mavutil.mavlink.MAV_AUTOPILOT_GENERIC,
            base_mode=0,
            custom_mode=0,
            system_status=mavutil.mavlink.MAV_STATE_ACTIVE
        )

        # Wait for a heartbeat
        msg = self.the_connection.recv_match(type='HEARTBEAT', blocking=True, timeout=1)
        if msg:
            self.get_logger().info("Heartbeat received from system")
        else:
            self.get_logger().warning("No heartbeat received")
    except Exception as e:
        self.get_logger().error(f"Error in send_heartbeat1: {str(e)}")

def main(args=None):

rclpy.init(args=args)
node = QGCcommNode() 
rclpy.spin(node)
rclpy.shutdown()   

when I run this code I get the "Heartbeat received from system" but yet the qgc is not connecting. in addition when I enter the Analyze Tools --> Mavlink Inspector this is the message that the qgc sends:

c53425a4-d357-42ca-8013-824bdff1e5e7

I would love if someone wil help me :)
image

@epkeefe123
Copy link

epkeefe123 commented Jun 26, 2024

try connecting to it on port 1472 for the second port i had this struggle too its because the port is already taken by the script

@hilaelb
Copy link
Author

hilaelb commented Jun 26, 2024

try connecting to it on port 1472 for the second port i had this struggle too its because the port is already taken by the script

what do you mean when you said "for the second port" ? where i need to change the port in QGC or in the device code?

@epkeefe123
Copy link

so you are using dronekit right? you should just be able to put in the first four port numbers followed by a 2 so in your case it would be 14572 drone kit opens a second port from my experience you just need to connect to it first then it opens a second and third port with the numbers 1472 and 1473

@epkeefe123
Copy link

i think

@hilaelb
Copy link
Author

hilaelb commented Jun 26, 2024

i don't use dronekit- i only use in what i wrote in the code

@hamishwillee
Copy link
Contributor

So basically you're code is trying to pretend to be a flight stack and you want QGC to connect right?

QGC probably expects a stream of heartbeats - that's what "connected" means.

@hilaelb
Copy link
Author

hilaelb commented Jun 27, 2024

Exactly ! ok, so i will try what you suggested

@hilaelb
Copy link
Author

hilaelb commented Jun 27, 2024

So basically you're code is trying to pretend to be a flight stack and you want QGC to connect right?

QGC probably expects a stream of heartbeats - that's what "connected" means.

how do i sends a strem of HEARTBEAT? because i already sends a heartbeat message every second and still it does not work.

@hamishwillee
Copy link
Contributor

If you are already doing it this becomes a QGC question "what do you require for a connection to be established with a generic autopilot" You should ask in the QGC forums.

@hilaelb
Copy link
Author

hilaelb commented Jun 29, 2024

If you are already doing it this becomes a QGC question "what do you require for a connection to be established with a generic autopilot" You should ask in the QGC forums.

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants