mavlink / mavros

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

Can't use "#include <mavlink/v2.0/common/mavlink.h>" #1981

Open brain0071 opened 2 months ago

brain0071 commented 2 months ago

Issue details

I want to parse mavlink messages in mavros source code

mavros/src/lib/mavros.cpp

For example:

mavlink_manual_control_t

And then get some value:

packet.x = x; packet.y = y; packet.z = z; packet.r = r

I think I need use this function:mavlink_msg_manual_control_get_x", so I add this line

#include <mavlink/v2.0/common/mavlink.h>

in mavros.cpp. but when I use catkin_make, a Error appear like this:

/opt/ros/noetic/include/mavlink/v2.0/common/common.h:2695:6: error: token ""2024.6.6"" is not valid in preprocessor expressions
 2695 | #if (MAVLINK_VERSION == 0)
      |      ^~~~~~~~~~~~~~~

and when I add this line

#undef MAVLINK_VERSION
#define MAVLINK_VERSION 2  // Replace with the correct integer version
#include <mavlink/v2.0/common/mavlink.h>"

I got a new Error:

error: ‘mavlink_message_t’ does not name a type
   85 | static inline uint16_t mavlink_msg_get_send_buffer_length(const mavlink_message_t* msg)
      |                                                                 ^~~~~~~~~~~~~~~~~
/opt/ros/noetic/include/mavlink/v2.0/protocol.h: In function ‘uint16_t mavlink_msg_get_send_buffer_length(const int*)’:
/opt/ros/noetic/include/mavlink/v2.0/protocol.h:87:11: error: request for member ‘magic’ in ‘* msg’, which is of non-class type ‘const int’
   87 |  if (msg->magic == MAVLINK_STX_MAVLINK1) {
      |           ^~~~~
/opt/ros/noetic/include/mavlink/v2.0/protocol.h:88:15: error: request for member ‘len’ in ‘* msg’, which is of non-class type ‘const int’
   88 |   return msg->len + MAVLINK_CORE_HEADER_MAVLINK1_LEN+1 + 2;
      |               ^~~
/opt/ros/noetic/include/mavlink/v2.0/protocol.h:90:37: error: request for member ‘incompat_flags’ in ‘* msg’, which is of non-class type ‘const int’
   90 |      uint16_t signature_len = (msg->incompat_flags & MAVLINK_IFLAG_SIGNED)?MAVLINK_SIGNATURE_BLOCK_LEN:0;
      |                                     ^~~~~~~~~~~~~~

MAVROS version and platform

ROS: Noetic Ubuntu: 22.04

vooon commented 2 months ago

https://github.com/mavlink/mavros/blob/ros2/libmavconn/include/mavconn/mavlink_dialect.hpp.em

Mavros uses C++ library, not C one.