Closed L4ncelot closed 7 years ago
That issue because you included "mavlink/v2.0/common/mavlink_msg_set_attitude_target.h", while libmavconn 0.19 switched to C++11 library with mavros.
You should not include anything else than mavconn/interface.h
- it automatically include MAVLink headers.
Instead of MAVLINK_MSG_ID_SET_ATTITUDE_TARGET
you should use mavlink::common::msg::SET_ATTITUDE_TARGET::MSG_ID
.
Note that serialization done by libmavconn (MAVConnInteface::send_message()
), but deserialization not (done in helper lambda done by PluginBase::make_handler()
).
Anyway why you need to use it outside of mavros?
Oh, I didn't know that. So how could I deserialize attitude_message? Normally I would something like this:
void MavlinkReceiverTest::handle_msg_set_attitude_target(const mavlink_message_t* message) {
mavlink_set_attitude_target_t set_attitude_target;
mavlink_msg_set_attitude_target_decode(message, &set_attitude_target);
}
Is there some example of doing such a thing?
I need to write my own mavlink receiver because I'm developing code for both pixhawk based copters and DJI copters. My program uses MAVROS to communicate with autopilots. The problem is that DJI copter doesn't use MAVLINK as a communication protocol. So I need to write MAVLINK message receiver and use DJI's ROS onboard API for controlling the copter.
Look at make_handler()
, perhaps some sort of that you may need (if you want to automate message handler switch).
Instead of decode you should write:
mavlink::MsgMap map(message);
mavlink::common::msg::SET_ATTITUDE_TARGET s;
s.deserialize(map);
std::cout << s.to_yaml() << std::endl;
Thank you very much for your help. Everything's working fine now.
@vooon The answers here are very useful and not present anywhere else that I've searched. The ros node examples in PX4 stack are not up to date with the libmavconn changes discussed here. So thanks.
MAVROS version and platform
Mavros: 0.19.0 ROS: Kinetic Ubuntu: 16.04
Issue details
Hi,
I'm currently trying to write mavlink message receiver using libmavconn library but unfortunately I cannot compile my code for some reason. Here's my code:
mavlink_receiver_test.h:
mavlink_receiver_test.cpp:
And here's output of catkin_make command:
It seems like some declarations are missing, but if I try to include for example
mavlink.h
ormavlink_types.h
files I get ton of errors during compilation process. Am I missing something? Should I link some libraries against my example? I couldn't find how to use libmavconn library precisely and I'm stuck currently...