You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to arm a drone by sending the MAV_CMD_COMPONENT_ARM_DISARM command with Param1 set to 1. However, the command doesn't seem to be working with QGroundControl. The code runs without errors, but the drone doesn't arm and there's no response received from QGroundControl.
Here's the relevant code snippet:
// DroneCommander handles MAVLink communication with the dronetypeDroneCommanderstruct {
node*gomavlib.Node
}
// NewDroneCommander creates a new instance of DroneCommanderfuncNewDroneCommander() (*DroneCommander, error) {
node, err:=gomavlib.NewNode(gomavlib.NodeConf{
Endpoints: []gomavlib.EndpointConf{
gomavlib.EndpointTCPClient{"localhost:port"},
},
Dialect: ardupilotmega.Dialect,
OutVersion: gomavlib.V2,
OutSystemID: 10,
})
iferr!=nil {
returnnil, err
}
return&DroneCommander{
node: node,
}, nil
}
func (dc*DroneCommander) Arm(targetSystemuint8, targetComponentuint8) error {
msg:=&ardupilotmega.MessageCommandLong{
TargetSystem: targetSystem,
TargetComponent: targetComponent,
Command: common.MAV_CMD_COMPONENT_ARM_DISARM,
Param1: 1, // Arming flag (1 for arm)
}
returndc.node.WriteMessageAll(msg)
}
// Close closes the MAVLink connectionfunc (dc*DroneCommander) Close() {
ifdc.node!=nil {
dc.node.Close()
}
}
funcmain() {
// Create new drone commanderdc, err:=NewDroneCommander()
iferr!=nil {
log.Fatalf("Failed to create drone commander: %v", err)
}
deferdc.Close()
targetSystem:=uint8(1) // Usually 1 for a single vehicletargetComponent:=uint8(1) // Usually 1 for the autopilotlog.Println("Sending arm command...")
// Send arm command in a separate goroutine with retriesgofunc() {
for {
err:=dc.Arm(targetSystem, targetComponent)
iferr==nil {
return// Exit the loop on successful arm command
}
log.Printf("Failed to send arm command: %v, retrying...\n", err)
time.Sleep(1*time.Second)
}
}()
// Monitor incoming messages in the main threadforevt:=rangedc.node.Events() {
iffrm, ok:=evt.(*gomavlib.EventFrame); ok {
ifack, ok:=frm.Message().(*common.MessageCommandAck); ok {
fmt.Printf("COMMAND_ACK: Command=%s, Result=%s\n", ack.Command.String(), ack.Result.String())
}
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to arm a drone by sending the MAV_CMD_COMPONENT_ARM_DISARM command with Param1 set to 1. However, the command doesn't seem to be working with QGroundControl. The code runs without errors, but the drone doesn't arm and there's no response received from QGroundControl.
Here's the relevant code snippet:
Beta Was this translation helpful? Give feedback.
All reactions