mavlink / mavros

MAVLink to ROS gateway with proxy for Ground Control Station
Other
902 stars 993 forks source link

Simple mavlink message receiver problem #713

Closed L4ncelot closed 7 years ago

L4ncelot commented 7 years ago

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:

#ifndef PROJECT_MAVLINK_RECEIVER_TEST_H
#define PROJECT_MAVLINK_RECEIVER_TEST_H

#include <ros/ros.h>
#include <mavconn/interface.h>
#include <mavlink/v2.0/common/mavlink_msg_set_attitude_target.h>

using mavlink::mavlink_message_t;

class MavlinkReceiverTest {
public:
    MavlinkReceiverTest(const std::string& fcu_url);

protected:
    void handle_message(const mavlink_message_t* message, const mavconn::Framing framing);

    void handle_msg_set_attitude_target(const mavlink_message_t* message);

    mavconn::MAVConnInterface::Ptr link_;
};

#endif //PROJECT_MAVLINK_RECEIVER_TEST_H

mavlink_receiver_test.cpp:

#include "aft_controller/mavlink_receiver_test.h"

MavlinkReceiverTest::MavlinkReceiverTest(const std::string& fcu_url) {
    link_ = mavconn::MAVConnInterface::open_url(fcu_url);

    link_->message_received_cb = std::bind(&MavlinkReceiverTest::handle_message, this, std::placeholders::_1,
                                           std::placeholders::_2);
}

void MavlinkReceiverTest::handle_message(const mavlink_message_t* message, const mavconn::Framing framing) {
    switch (message->msgid) {
        case MAVLINK_MSG_ID_SET_ATTITUDE_TARGET:
            ROS_INFO_STREAM("it's working");
            handle_msg_set_attitude_target(message);
            break;
        default:
            break;
    }
}

void MavlinkReceiverTest::handle_msg_set_attitude_target(const mavlink_message_t* message) {
    (void) message;
}

int main(int argc, char** argv) {
    ros::init(argc, argv, "mavlink_receiver_test");
    ros::NodeHandle nh;

    MavlinkReceiverTest mavlink("udp://localhost:14557@localhost:14565");
    ros::spin();

    return 0;
}

And here's output of catkin_make command:

[  2%] Built target aft_math_tools
[  3%] Built target aft_draw_tools
[  4%] Built target aft_mavros_tools
[  5%] Built target aft_plane
[  5%] Built target std_msgs_generate_messages_eus
[  5%] Built target geometry_msgs_generate_messages_eus
[  6%] Built target aft_bond_tools
[  6%] Built target actionlib_msgs_generate_messages_eus
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionFeedback
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionResult
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionActionResult
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionGoal
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionAction
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognition
[  6%] Built target std_msgs_generate_messages_lisp
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionActionFeedback
[  6%] Built target _aft_image_processing_generate_messages_check_deps_PatternRecognitionActionGoal
[  6%] Built target geometry_msgs_generate_messages_lisp
[  6%] Built target actionlib_msgs_generate_messages_lisp
[  6%] Built target geometry_msgs_generate_messages_cpp
[  6%] Built target actionlib_msgs_generate_messages_cpp
[  6%] Built target std_msgs_generate_messages_cpp
[  6%] Built target geometry_msgs_generate_messages_nodejs
[  6%] Built target std_msgs_generate_messages_nodejs
[  6%] Built target actionlib_msgs_generate_messages_nodejs
[  6%] Built target actionlib_msgs_generate_messages_py
[  6%] Built target geometry_msgs_generate_messages_py
[  6%] Built target std_msgs_generate_messages_py
[  7%] Built target pattern_draw
[  8%] Built target pattern_recognition_test
[ 12%] Built target color_object_tracking
[ 12%] Built target pattern_recognition_real_time
[ 13%] Built target bounding_box
[ 15%] Built target camera_calibration
[ 17%] Built target harris_corner_detection
[ 18%] Built target camera_test
[ 19%] Built target contour
[ 21%] Built target face_recognition
[ 22%] Built target optical_flow
[ 24%] Built target sequential_motion_tracking
[ 25%] Built target image_read
[ 26%] Built target shape_detection
[ 27%] Built target geofencing
[ 28%] Built target system_watchdog_test
[ 29%] Built target mavlink_attitude_publisher
[ 31%] Built target offb_example
[ 33%] Built target attitude_controller_example
[ 34%] Building CXX object aft_copter/aft_controller/CMakeFiles/mavlink_receiver_test.dir/src/mavlink_receiver_test.cpp.o
[ 44%] Built target rc_reader_test
[ 45%] Built target dji_control_test
[ 56%] Built target attitude_controller_test
[ 57%] Built target nofly_vertex_plugin
[ 58%] Built target model_push_plugin
[ 59%] Built target hello_world
[ 65%] Built target aft_image_processing_generate_messages_eus
[ 67%] Built target transform_broadcaster_plugin
[ 72%] Built target aft_image_processing_generate_messages_lisp
[ 77%] Built target aft_image_processing_generate_messages_cpp
[ 80%] Built target grid_size_plugin
[ 86%] Built target aft_image_processing_generate_messages_nodejs
[ 86%] Built target aft_image_processing_gencpp
[ 92%] Built target aft_image_processing_generate_messages_py
[ 96%] Built target pattern_recognition_client
[ 96%] Built target pattern_recognition_action_server
[ 98%] Built target pattern_recognition_server
[ 98%] Built target aft_image_processing_generate_messages
In file included from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:43:0,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:79:102: error: ‘mavlink_message_t’ has not been declared
 static inline uint16_t mavlink_msg_set_attitude_target_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
                                                                                                      ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint16_t mavlink_msg_set_attitude_target_pack(uint8_t, uint8_t, int*, uint32_t, uint8_t, uint8_t, uint8_t, const float*, float, float, float, float)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:84:43: error: ‘_mav_put_uint32_t’ was not declared in this scope
     _mav_put_uint32_t(buf, 0, time_boot_ms);
                                           ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:85:43: error: ‘_mav_put_float’ was not declared in this scope
     _mav_put_float(buf, 20, body_roll_rate);
                                           ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:89:44: error: ‘_mav_put_uint8_t’ was not declared in this scope
     _mav_put_uint8_t(buf, 36, target_system);
                                            ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:92:38: error: ‘_mav_put_float_array’ was not declared in this scope
     _mav_put_float_array(buf, 4, q, 4);
                                      ^
In file included from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../message.hpp:15:0,
                 from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/common.hpp:16,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:23,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../mavlink_types.h:158:56: error: request for member ‘payload64’ in ‘* msg’, which is of non-class type ‘int’
 #define _MAV_PAYLOAD_NON_CONST(msg) ((char *)(&((msg)->payload64[0])))
                                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:93:16: note: in expansion of macro ‘_MAV_PAYLOAD_NON_CONST’
         memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_LEN);
                ^
In file included from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:43:0,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:108:10: error: request for member ‘msgid’ in ‘* msg’, which is of non-class type ‘int’
     msg->msgid = MAVLINK_MSG_ID_SET_ATTITUDE_TARGET;
          ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:109:189: error: ‘mavlink_finalize_message’ was not declared in this scope
     return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_CRC);
                                                                                                                                                                                             ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:109:189: note: suggested alternative:
In file included from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../message.hpp:32:0,
                 from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/common.hpp:16,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:23,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../mavlink_helpers.h:273:25: note:   ‘mavlink::mavlink_finalize_message’
 MAVLINK_HELPER uint16_t mavlink_finalize_message(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id, 
                         ^
In file included from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:43:0,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:130:32: error: ‘mavlink_message_t’ has not been declared
                                mavlink_message_t* msg,
                                ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint16_t mavlink_msg_set_attitude_target_pack_chan(uint8_t, uint8_t, uint8_t, int*, uint32_t, uint8_t, uint8_t, uint8_t, const float*, float, float, float, float)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:135:43: error: ‘_mav_put_uint32_t’ was not declared in this scope
     _mav_put_uint32_t(buf, 0, time_boot_ms);
                                           ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:136:43: error: ‘_mav_put_float’ was not declared in this scope
     _mav_put_float(buf, 20, body_roll_rate);
                                           ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:140:44: error: ‘_mav_put_uint8_t’ was not declared in this scope
     _mav_put_uint8_t(buf, 36, target_system);
                                            ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:143:38: error: ‘_mav_put_float_array’ was not declared in this scope
     _mav_put_float_array(buf, 4, q, 4);
                                      ^
In file included from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../message.hpp:15:0,
                 from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/common.hpp:16,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:23,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../mavlink_types.h:158:56: error: request for member ‘payload64’ in ‘* msg’, which is of non-class type ‘int’
 #define _MAV_PAYLOAD_NON_CONST(msg) ((char *)(&((msg)->payload64[0])))
                                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:144:16: note: in expansion of macro ‘_MAV_PAYLOAD_NON_CONST’
         memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_LEN);
                ^
In file included from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:43:0,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:159:10: error: request for member ‘msgid’ in ‘* msg’, which is of non-class type ‘int’
     msg->msgid = MAVLINK_MSG_ID_SET_ATTITUDE_TARGET;
          ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:160:200: error: ‘mavlink_finalize_message_chan’ was not declared in this scope
     return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_SET_ATTITUDE_TARGET_CRC);
                                                                                                                                                                                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:160:200: note: suggested alternative:
In file included from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../message.hpp:32:0,
                 from /home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/common.hpp:16,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:23,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/../mavlink_helpers.h:263:25: note:   ‘mavlink::mavlink_finalize_message_chan’
 MAVLINK_HELPER uint16_t mavlink_finalize_message_chan(mavlink_message_t* msg, uint8_t system_id, uint8_t component_id,
                         ^
In file included from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/mavlink_dialect.h:43:0,
                 from /home/l4ncelot/mavros/src/mavros/libmavconn/include/mavconn/interface.h:37,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/include/aft_controller/mavlink_receiver_test.h:9,
                 from /home/l4ncelot/aft_copter/src/aft_copter/aft_controller/src/mavlink_receiver_test.cpp:5:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:171:104: error: ‘mavlink_message_t’ has not been declared
 static inline uint16_t mavlink_msg_set_attitude_target_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_set_attitude_target_t* set_attitude_target)
                                                                                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:185:123: error: ‘mavlink_message_t’ has not been declared
 static inline uint16_t mavlink_msg_set_attitude_target_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_set_attitude_target_t* set_attitude_target)
                                                                                                                           ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:297:79: error: ‘mavlink_message_t’ does not name a type
 static inline uint32_t mavlink_msg_set_attitude_target_get_time_boot_ms(const mavlink_message_t* msg)
                                                                               ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint32_t mavlink_msg_set_attitude_target_get_time_boot_ms(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:299:40: error: ‘_MAV_RETURN_uint32_t’ was not declared in this scope
     return _MAV_RETURN_uint32_t(msg,  0);
                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:307:79: error: ‘mavlink_message_t’ does not name a type
 static inline uint8_t mavlink_msg_set_attitude_target_get_target_system(const mavlink_message_t* msg)
                                                                               ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint8_t mavlink_msg_set_attitude_target_get_target_system(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:309:40: error: ‘_MAV_RETURN_uint8_t’ was not declared in this scope
     return _MAV_RETURN_uint8_t(msg,  36);
                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:317:82: error: ‘mavlink_message_t’ does not name a type
 static inline uint8_t mavlink_msg_set_attitude_target_get_target_component(const mavlink_message_t* msg)
                                                                                  ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint8_t mavlink_msg_set_attitude_target_get_target_component(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:319:40: error: ‘_MAV_RETURN_uint8_t’ was not declared in this scope
     return _MAV_RETURN_uint8_t(msg,  37);
                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:327:75: error: ‘mavlink_message_t’ does not name a type
 static inline uint8_t mavlink_msg_set_attitude_target_get_type_mask(const mavlink_message_t* msg)
                                                                           ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint8_t mavlink_msg_set_attitude_target_get_type_mask(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:329:40: error: ‘_MAV_RETURN_uint8_t’ was not declared in this scope
     return _MAV_RETURN_uint8_t(msg,  38);
                                        ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:337:68: error: ‘mavlink_message_t’ does not name a type
 static inline uint16_t mavlink_msg_set_attitude_target_get_q(const mavlink_message_t* msg, float *q)
                                                                    ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘uint16_t mavlink_msg_set_attitude_target_get_q(const int*, float*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:339:49: error: ‘_MAV_RETURN_float_array’ was not declared in this scope
     return _MAV_RETURN_float_array(msg, q, 4,  4);
                                                 ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:347:78: error: ‘mavlink_message_t’ does not name a type
 static inline float mavlink_msg_set_attitude_target_get_body_roll_rate(const mavlink_message_t* msg)
                                                                              ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘float mavlink_msg_set_attitude_target_get_body_roll_rate(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:349:38: error: ‘_MAV_RETURN_float’ was not declared in this scope
     return _MAV_RETURN_float(msg,  20);
                                      ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:357:79: error: ‘mavlink_message_t’ does not name a type
 static inline float mavlink_msg_set_attitude_target_get_body_pitch_rate(const mavlink_message_t* msg)
                                                                               ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘float mavlink_msg_set_attitude_target_get_body_pitch_rate(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:359:38: error: ‘_MAV_RETURN_float’ was not declared in this scope
     return _MAV_RETURN_float(msg,  24);
                                      ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:367:77: error: ‘mavlink_message_t’ does not name a type
 static inline float mavlink_msg_set_attitude_target_get_body_yaw_rate(const mavlink_message_t* msg)
                                                                             ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘float mavlink_msg_set_attitude_target_get_body_yaw_rate(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:369:38: error: ‘_MAV_RETURN_float’ was not declared in this scope
     return _MAV_RETURN_float(msg,  28);
                                      ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:377:70: error: ‘mavlink_message_t’ does not name a type
 static inline float mavlink_msg_set_attitude_target_get_thrust(const mavlink_message_t* msg)
                                                                      ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: In function ‘float mavlink_msg_set_attitude_target_get_thrust(const int*)’:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:379:38: error: ‘_MAV_RETURN_float’ was not declared in this scope
     return _MAV_RETURN_float(msg,  32);
                                      ^
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h: At global scope:
/home/l4ncelot/mavros/devel/include/mavlink/v2.0/common/mavlink_msg_set_attitude_target.h:388:65: error: ‘mavlink_message_t’ does not name a type
 static inline void mavlink_msg_set_attitude_target_decode(const mavlink_message_t* msg, mavlink_set_attitude_target_t* set_attitude_target)
                                                                 ^
aft_copter/aft_controller/CMakeFiles/mavlink_receiver_test.dir/build.make:62: recipe for target 'aft_copter/aft_controller/CMakeFiles/mavlink_receiver_test.dir/src/mavlink_receiver_test.cpp.o' failed
make[2]: *** [aft_copter/aft_controller/CMakeFiles/mavlink_receiver_test.dir/src/mavlink_receiver_test.cpp.o] Error 1
CMakeFiles/Makefile2:4837: recipe for target 'aft_copter/aft_controller/CMakeFiles/mavlink_receiver_test.dir/all' failed
make[1]: *** [aft_copter/aft_controller/CMakeFiles/mavlink_receiver_test.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Base path: /home/l4ncelot/aft_copter
Source space: /home/l4ncelot/aft_copter/src
Build space: /home/l4ncelot/aft_copter/build
Devel space: /home/l4ncelot/aft_copter/devel
Install space: /home/l4ncelot/aft_copter/install
####
#### Running command: "make cmake_check_build_system" in "/home/l4ncelot/aft_copter/build"
####
####
#### Running command: "make -j4 -l4" in "/home/l4ncelot/aft_copter/build"
####
Invoking "make -j4 -l4" failed

It seems like some declarations are missing, but if I try to include for example mavlink.h or mavlink_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...

vooon commented 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?

L4ncelot commented 7 years ago

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.

vooon commented 7 years ago

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;
L4ncelot commented 7 years ago

Thank you very much for your help. Everything's working fine now.

alsaibie commented 6 years ago

@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.