ArduPilot / node-mavlink

This project is providing native TypeScript bindings and tools for sending and receiving MavLink messages over a verity of medium
GNU Lesser General Public License v3.0
75 stars 25 forks source link

Sending periodic heartbeats #25

Closed kevdagoat closed 1 year ago

kevdagoat commented 1 year ago

Hi, I have a mavlink compatible gimbal that I am trying to control with typescript and without the use of an autopilot. This particular device requires the periodic mavlink heartbeat packet to be sent in order to establish and maintain communication.

I was originally using gomavlib and this library had a convenient configuration option for periodic heartbeat messages and additionally a way to manually send a heartbeat packet:

node, err := gomavlib.NewNode(gomavlib.NodeConf{
  Endpoints: [...],
  Dialect:                all.Dialect,
  OutVersion:             gomavlib.V1,
  OutSystemID:            10,
  // Periodic heartbeat settings
  HeartbeatDisable:       false,
  HeartbeatPeriod:        1 * time.Second,
  HeartbeatSystemType:    int(all.MAV_TYPE_GROUND_ROVER),
  HeartbeatAutopilotType: int(all.MAV_AUTOPILOT_PX4),
})

I had a look through the source of this library and the mavlink-mappings package however a function for even sending a heartbeat doesn't seem to exist, is this an issue with the auto JS definition generation script? Additionally:

  1. Would you consider implementing this periodic heartbeat functionality as a separate class? (or similar)
    async function main() {
    // constructing a reader that will emit each packet separately
    const reader = port
    .pipe(new MavLinkPacketSplitter())
    .pipe(new MavLinkPacketParser());
    // Send Mavlink heartbeat packets @ 2Hz
    const heartbeat = new MavLinkPeriodicHeartbeat(500, 0, 0) // Interval (msec), SystemType, AutopilotType
    ....
  2. Is there any way currently that allows me to send a heartbeat packet? I looked into creating a custom packet definition but I am a bit confused as to how to pull it off and I'm also not sure if it will conflict with any existing definitions.

Hope that makes sense, thanks!

padcom commented 1 year ago

Yes, all that makes perfect sense. The difference is what level of interface that other library tries to implement and what node-mavlink is for (including the binding).

The library is not for top-level operations such as sending heartbeat periodically. If you'd like to do that you just use the setInterval() function and send whatever you need when you need it. Done. Sending of messages is described in the docs and pretty much every example in the repository does the sending (I use mostly the udp one for playing around)

Good luck with your project!

padcom commented 1 year ago

@kevdagoat I've just completed preliminary work on the heartbeat and ftp services - maybe you'll want to check those out:

https://github.com/padcom/node-mavlink-heartbeat https://github.com/padcom/node-mavlink-ftp

Hope this helps you clean things up :)