[英]Change velocity with message to Mavlink
I'm trying to move a vehicle by changing the velocity. 我试图通过改变速度来移动车辆。 I've been able to perform the operation successfully in Python, but for my project I can not use Python, so I'm using Android to try to make the same operation.
我已经能够在Python中成功执行该操作,但是对于我的项目,我无法使用Python,因此我正在使用Android尝试进行相同的操作。 The working functionality in Python is:
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()
What I'm trying to do is the equivalent code in Android: 我想做的是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());
}
});
What am I missing? 我想念什么? Any help would be greatly appreciated.
任何帮助将不胜感激。
Thanks. 谢谢。
I'm not familiar with Java MAVLink implementations, but you are sending LOCAL_POSITION_NED
messages which are telemetry message, not the control one. 我不熟悉Java MAVLink实现,但是您正在发送
LOCAL_POSITION_NED
消息,它们是遥测消息,而不是控件消息。 You need to send SET_POSITION_TARGET_LOCAL_NED
instead, like you do in Python. 您需要发送
SET_POSITION_TARGET_LOCAL_NED
,就像在Python中一样。
[Closing the issue] For the future programmers who have to face the same problem here is my working code: [解决问题]对于将来不得不面对相同问题的程序员,我的工作代码是:
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());
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.