How to connect to a PX4 SITL? #233
Unanswered
nareshbhatia
asked this question in
Q&A
Replies: 1 comment
-
|
Ok, I got it working. Answering my own questions – please let me know if my understanding is correct.
Here's my final code: package main
import (
"encoding/json"
"log"
"github.com/bluenviron/gomavlib/v3"
"github.com/bluenviron/gomavlib/v3/pkg/dialects/common"
"github.com/flightpath-dev/flightpath/internal/mavlink"
)
func main() {
// Create a node which acts as a GCS, communicating with a UDP endpoint in server mode.
// We use port 14550 because that's where the PX4 broadcasts its messages.
// We use system ID 254 to coexist with QGroundControl (which uses 255).
node := &gomavlib.Node{
Endpoints: []gomavlib.EndpointConf{
gomavlib.EndpointUDPServer{Address: "0.0.0.0:14550"},
},
Dialect: common.Dialect,
OutVersion: gomavlib.V2,
OutSystemID: 254,
}
err := node.Initialize()
if err != nil {
panic(err)
}
defer node.Close()
// Print incoming messages
log.Printf("Waiting for messages...")
for evt := range node.Events() {
if frm, ok := evt.(*gomavlib.EventFrame); ok {
log.Printf("received: id=%d, %+v\n", frm.Message().GetID(), frm.Message())
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am just starting out with
gomavliband wanted some help in connecting my example to a PX4 SITL.Here's my setup:
Headless PX4 SITL running in a docker container
From this I understand that the SITL is broadcasting on UDP port 14550 (as expected) and accepting commands on UDP port 18570. Is this correct?
Test with QGroundControl – Success!
I tested with QGroundControl and everything works fine
Test with gomavlib Example – Doesn't Work
I tried the node-endpoint-udp-broadcast example (slightly modified) and it just sits waiting for messages. I believe that it is binding correctly to port 14550, because I don't see any connection errors.
My Code
My Questions
node-endpoint-udp-broadcast,node-endpoint-udp-client,node-endpoint-udp-server? Which is the correct one for my use case where I am trying to make my example work like a GCS.192.168.7.255:5600as the broadcast address. I was getting an error on that address, so I changed it to192.168.1.255:14550which seems to be the broadcast address on my Mac. At least it is not giving any errors. Is this a good choice?ardupilotmegadialect. I didn't find any px4 dialect, so I switched to thealldialect. Is that a good choice?Beta Was this translation helpful? Give feedback.
All reactions