Hi,
I’m trying to implement an autonomous driver using java dronevlett.mavlink client library.
I cannot understand the correct set of commands I have to send to PX4 to takeoff.
I’m working on a local windows machine with PX4 and JMAV simulator.
Communication works fine, but I always receive a MAV_RESULT_FAILED.
Here is my simplest example:
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import io.dronefleet.mavlink.;
import io.dronefleet.mavlink.common.;
public class Main {
static MavlinkConnection connection;
public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException {
UdpConnector udp = new UdpConnector(InetAddress.getLocalHost(), 14570, 14550);
connection = MavlinkConnection.create(udp.getInputStream(), udp.getOutputStream());
new Thread() {
@Override
public void run() {
while (true) {
try {
connection.send1(255, 0,
Heartbeat.builder().type(MavType.MAV_TYPE_GCS).autopilot(MavAutopilot.MAV_AUTOPILOT_PX4)
.systemStatus(MavState.MAV_STATE_UNINIT).mavlinkVersion(1).build());
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}.start();
connection.send1(255, 0,
CommandInt.builder().command(MavCmd.MAV_CMD_AQ_REQUEST_VERSION).build());
connection.send1(255, 0,
CommandInt.builder().command(MavCmd.MAV_CMD_ARM_AUTHORIZATION_REQUEST).param1(1).build());
MavlinkMessage message;
while ((message = connection.next()) != null) {
Object p = message.getPayload();
if (p instanceof Heartbeat || p instanceof CommandAck)
System.out.println("" + message.getSequence() + " --> " + p);
}
}
}
Here is a selection of received packes:
128 --> CommandAck{command=EnumValue{value=4, entry=MAV_CMD_AQ_REQUEST_VERSION}, result=EnumValue{value=4, entry=MAV_RESULT_FAILED}, progress=0, resultParam2=0, targetSystem=0, targetComponent=0}
130 --> CommandAck{command=EnumValue{value=3001, entry=MAV_CMD_ARM_AUTHORIZATION_REQUEST}, result=EnumValue{value=4, entry=MAV_RESULT_FAILED}, progress=0, resultParam2=0, targetSystem=0, targetComponent=0}
178 --> Heartbeat{type=EnumValue{value=2, entry=MAV_TYPE_QUADROTOR}, autopilot=EnumValue{value=12, entry=MAV_AUTOPILOT_PX4}, baseMode=EnumValue{value=29, entry=null}, customMode=50593792, systemStatus=EnumValue{value=3, entry=MAV_STATE_STANDBY}, mavlinkVersion=3}
187 --> Heartbeat{type=EnumValue{value=2, entry=MAV_TYPE_QUADROTOR}, autopilot=EnumValue{value=12, entry=MAV_AUTOPILOT_PX4}, baseMode=EnumValue{value=29, entry=null}, customMode=50593792, systemStatus=EnumValue{value=3, entry=MAV_STATE_STANDBY}, mavlinkVersion=3}
cannot understand where is my error and which sequence of commands I have to send to takeoff.
Can anyone help me?
thanks
Mario