4

我试图通过改变速度来移动车辆。我已经能够在 Python 中成功执行该操作,但是对于我的项目我不能使用 Python,所以我正在使用 Android 尝试进行相同的操作。Python 中的工作功能是:

def send_ned_velocity(velocity_x, velocity_y, velocity_z):
"""
Move vehicle in direction based on specified velocity vectors.
"""
msg = vehicle.message_factory.set_position_target_local_ned_encode(
    0,       # time_boot_ms (not used)
    0, 0,    # target system, target component
    mavutil.mavlink.MAV_FRAME_BODY_NED, # frame
    0b0000111111000111, # type_mask (only speeds enabled)
    0, 0, 0, # x, y, z positions (not used)
    velocity_x, velocity_y, velocity_z, # x, y, z velocity in m/s
    0, 0, 0, # x, y, z acceleration (not supported yet, ignored in GCS_Mavlink)
    0, 0)    # yaw, yaw_rate (not supported yet, ignored in GCS_Mavlink)
# send command to vehicle
vehicle.send_mavlink(msg)
vehicle.flush()

我正在尝试做的是Android中的等效代码:

                   // Create the message
                msg_local_position_ned msgMessageInterval = new msg_local_position_ned();
                msgMessageInterval.x = 0;
                msgMessageInterval.y = 0;
                msgMessageInterval.z = 0;
                msgMessageInterval.vx = 10;
                msgMessageInterval.vy = 0;
                msgMessageInterval.vz = 0;
                msgMessageInterval.time_boot_ms = 0;

                MavlinkMessageWrapper mavlinkMessageWrapper = new MavlinkMessageWrapper(msgMessageInterval);

                // Send the message to MavLink
                ExperimentalApi.getApi(drone).sendMavlinkMessage(mavlinkMessageWrapper);

                // Listen for the message received
                drone.addMavlinkObserver(new MavlinkObserver() {
                    @Override
                    public void onMavlinkMessageReceived(MavlinkMessageWrapper mavlinkMessageWrapper) {
                        System.out.println("MESSAGE RECEIVED="+mavlinkMessageWrapper.getMavLinkMessage().toString());
                    }
                });

我错过了什么?任何帮助将不胜感激。

谢谢。

4

2 回答 2

1

我不熟悉 Java MAVLink 实现,但您发送LOCAL_POSITION_NED的消息是遥测消息,而不是控制消息。您需要发送SET_POSITION_TARGET_LOCAL_NED,就像在 Python 中一样。

于 2018-08-20T16:43:14.173 回答
0

[关闭问题]对于必须面对同样问题的未来程序员,这里是我的工作代码:

            msg_set_position_target_local_ned msgMessageVelocity = new msg_set_position_target_local_ned();
        msgMessageVelocity.time_boot_ms = 0;
        msgMessageVelocity.target_system = 0;
        msgMessageVelocity.target_component = 0;
        msgMessageVelocity.coordinate_frame = MAV_FRAME.MAV_FRAME_BODY_NED;
        msgMessageVelocity.type_mask = 0b0000111111000111;
        msgMessageVelocity.x = 0;
        msgMessageVelocity.y = 0;
        msgMessageVelocity.z = 0;
        msgMessageVelocity.vx = _vx * _speed;
        msgMessageVelocity.vy = _vz * _speed;
        msgMessageVelocity.vz = _vy * _speed;
        msgMessageVelocity.afx = 0;
        msgMessageVelocity.afy = 0;
        msgMessageVelocity.afz = 0;
        msgMessageVelocity.yaw = 0;
        msgMessageVelocity.yaw_rate = 0;

        MavlinkMessageWrapper mavlinkMessageWrapper = new MavlinkMessageWrapper(msgMessageVelocity);

        ExperimentalApi.getApi(drone).sendMavlinkMessage(mavlinkMessageWrapper);

        drone.addMavlinkObserver(new MavlinkObserver() {
            @Override
            public void onMavlinkMessageReceived(MavlinkMessageWrapper mavlinkMessageWrapper) {
                System.out.println("MESSAGE RECEIVED="+mavlinkMessageWrapper.getMavLinkMessage().toString());
            }
        });
于 2018-08-23T21:08:36.083 回答