Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtcm messages unidentical with mavsdk::rtk.h #2510

Open
Wenz922 opened this issue Feb 12, 2025 · 13 comments
Open

rtcm messages unidentical with mavsdk::rtk.h #2510

Wenz922 opened this issue Feb 12, 2025 · 13 comments

Comments

@Wenz922
Copy link

Wenz922 commented Feb 12, 2025

I am using mavsdk::rtk.h to send rtcm messages to a Pixhawk 6C. Here is a part of code:

`void subscribe_to_rtcm() {
rtcm_subscription_ = this->create_subscription<std_msgs::msg::String>(
rtcm_topic_, 10,
[this](const std_msgs::msg::String::SharedPtr msg) {
forward_to_pixhawk(msg->data);
});
}

void forward_to_pixhawk(const std::string& rtcm_data_str) {
    mavsdk::Rtk::RtcmData rtcm_data;
    rtcm_data.data = rtcm_data_str;

    // Send RTCM data using the RTK plugin
    Rtk::Result result = rtk_plugin_->send_rtcm_data(rtcm_data);
    if (result == Rtk::Result::Success) {
        RCLCPP_INFO(this->get_logger(), "RTCM data forwarded to Pixhawk: %zu bytes", rtcm_data_str.size());
    } else {
        RCLCPP_WARN(this->get_logger(), "Failed to forward RTCM data: %d", static_cast<int>(result));
    }
}`

But in logging the rtcm data size is not identical, What is the problem?
[INFO] [1739119220.793310883] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119220.893626373] [rtcm_base_node]: Published RTCM data of length: 27 bytes
[INFO] [1739119221.075379546] [rtcm_base_node]: Published RTCM data of length: 144 bytes
[INFO] [1739119221.093328974] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119221.193289930] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119221.293425000] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119221.393339313] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119221.493329355] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119221.593762593] [rtcm_base_node]: Published RTCM data of length: 256 bytes
[INFO] [1739119221.693307979] [rtcm_base_node]: Published RTCM data of length: 256 bytes

[INFO] [1739119210.293539628] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 256 bytes
[INFO] [1739119210.393929978] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 256 bytes
[INFO] [1739119210.493808059] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 168 bytes
[INFO] [1739119210.593585514] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 57 bytes
[INFO] [1739119210.693704616] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 15 bytes
[INFO] [1739119210.793863885] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 101 bytes
[INFO] [1739119210.893734223] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 1 bytes
[INFO] [1739119210.993963822] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 44 bytes
[INFO] [1739119211.093535019] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 0 bytes
[INFO] [1739119211.193466552] [rtcm_rover_node]: RTCM data forwarded to Pixhawk: 256 bytes

@reedev
Copy link

reedev commented Feb 12, 2025

Hi, based on this small snippet (so no context): do you realize that rtcm is a stream of data? As long as the whole stream contains the same content, it is ok. Packets are sent in chunks.

Have you checked the whole stream for missing bytes?

Please correct me if I am wrong but this is my understanding at the moment.

@julianoes
Copy link
Collaborator

@Wenz922 are you using v2 or v3? With v3 the rtcm data needs to be supplied base64 encoded.

@Wenz922
Copy link
Author

Wenz922 commented Feb 12, 2025

@julianoes i am using v2.12.2.
According to the MAVSDK API rtk.h documentation, RTCM data should be sent as raw binary (std::string), not base64 encoded or?
Btw. i tried before base64 encoded to verify the whole rtcm message with CRC while using MavlinkPassthrough, and it had similar problem.

@julianoes
Copy link
Collaborator

Correct, no base64 with v2.

And so are corrections not working at all? Can you share any other information about your setup? E.g. PX4 or ArduPilot? And what versions?

@Wenz922
Copy link
Author

Wenz922 commented Feb 13, 2025

@julianoes There are only partial RTCM messages that are received, so that the correction doesn't work. I am using PX4 version1.15.2.
Here is main part code: thank you a lot ;)(the layout might look strange, i tried my best..)

class RTCMMAVSDKToPixhawk : public rclcpp::Node {
public:
    RTCMMAVSDKToPixhawk()
        : Node("rtcm_fcu_mavsdk_node") {
        // Declare and get parameters
        this->declare_parameter<std::string>("serial_port", "/dev/ttyAMA2");
        this->declare_parameter<int>("baud_rate", 57600);
        this->declare_parameter<std::string>("rtcm_topic", "/rtcm_data");`

        serial_port_ = this->get_parameter("serial_port").as_string();
        baud_rate_ = this->get_parameter("baud_rate").as_int();
        rtcm_topic_ = this->get_parameter("rtcm_topic").as_string();

        // Initialize MAVSDK
        setup_mavsdk();
    }

private:
    void setup_mavsdk() {
        // Initialize MAVSDK with Companion Computer configuration
        mavsdk_ = std::make_shared<Mavsdk>(Mavsdk::Configuration{Mavsdk::ComponentType::CompanionComputer});
        ConnectionResult connection_result = mavsdk_->add_serial_connection(serial_port_, baud_rate_);

        if (connection_result != ConnectionResult::Success) {
            RCLCPP_ERROR(this->get_logger(), "Failed to connect to Pixhawk: %s", connection_result_to_string(connection_result).c_str());
            schedule_mavsdk_reconnection();
            return;
        }

        RCLCPP_INFO(this->get_logger(), "Connecting to Pixhawk...");
        wait_for_system();
    }

    void wait_for_system() {
        // Wait for the system to connect
        while (mavsdk_->systems().empty()) {
            RCLCPP_INFO(this->get_logger(), "Waiting for Pixhawk system...");
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }

        // Get connected system
        system_ = mavsdk_->systems().at(0);
        rtk_plugin_ = std::make_shared<Rtk>(system_);

        if (!rtk_plugin_) {
            RCLCPP_ERROR(this->get_logger(), "Failed to initialize RTK plugin.");
            schedule_mavsdk_reconnection();
            return;
        }

        RCLCPP_INFO(this->get_logger(), "Pixhawk system connected. RTK plugin initialized.");

        // Subscribe to RTCM topic
        subscribe_to_rtcm();
    }

    void subscribe_to_rtcm() {
        rtcm_subscription_ = this->create_subscription<std_msgs::msg::String>(
            rtcm_topic_, 10,
            [this](const std_msgs::msg::String::SharedPtr msg) {
                forward_to_pixhawk(msg->data);
            });
    }

    void forward_to_pixhawk(const std::string& rtcm_data_str) {
        mavsdk::Rtk::RtcmData rtcm_data;
        rtcm_data.data = rtcm_data_str;

        // Send RTCM data using the RTK plugin
        Rtk::Result result = rtk_plugin_->send_rtcm_data(rtcm_data);
        if (result == Rtk::Result::Success) {
            RCLCPP_INFO(this->get_logger(), "RTCM data forwarded to Pixhawk: %zu bytes", rtcm_data_str.size());
        } else {
            RCLCPP_WARN(this->get_logger(), "Failed to forward RTCM data: %d", static_cast<int>(result));
        }
    }

    void schedule_mavsdk_reconnection() {
    if (!mavsdk_reconnect_timer_) {
        mavsdk_reconnect_timer_ = this->create_wall_timer(
            std::chrono::seconds(5), // Explicitly specify duration as 5 seconds
            [this]() {
                RCLCPP_INFO(this->get_logger(), "Attempting to reconnect to Pixhawk...");
                setup_mavsdk();
            });
        }
    }

@Wenz922
Copy link
Author

Wenz922 commented Feb 16, 2025

Hi @julianoes , i have checked the version of MAVSDK and PX4 which i used. And the RTK devices are two H-RTK ZED-F9P Helical, one as Base and another one as Rover. Configuration is as followed : https://docs.holybro.com/gps-and-rtk-system/zed-f9p-h-rtk-series/portable-rtk-base-station-setup. It works well directly with holybro telemtry radio. Is it probably the reason of holybro telemtry with baudrate 57600?

@julianoes
Copy link
Collaborator

I will have to create a C++ example and test that myself.

@Wenz922
Copy link
Author

Wenz922 commented Feb 16, 2025

@julianoes that will be great! thanks a lot, stay updated ;)

@reedev
Copy link

reedev commented Feb 16, 2025

Hi, fwiw, I will double check my setup with MAVSDK v3.0.0 since I have used my setup successfully with MAVSDK v2

@Wenz922
Copy link
Author

Wenz922 commented Feb 16, 2025

@reedev would you mind to share more detail, for example the code part of library rtk.h?

@reedev
Copy link

reedev commented Feb 17, 2025

As I said, I will check MAVSDK v3 with rtk, to see if it still works as expected as with v2. We know that v2 was working ok so I suggest to make your setup with v2 first.

I don't see that you tried your setup with a different setup, are you sure your equipment, server etc are working properly?

@Wenz922
Copy link
Author

Wenz922 commented Feb 17, 2025

Sorry, @reedev i don't really understand what kind of setup do you mean here, could you explain a bit more?
What i have tried: setup Base & Rover, communication with (1) holybro telemtry without MAVSDK; (2) TCP; (3) pixhawk 6c with MAVSDK. The results are: (1)and(2) work greatly with RTK, (3) doesn't work so far.

@reedev
Copy link

reedev commented Feb 17, 2025

Aha sorry, I missed that part of your story. In that case I can't help you much further since my equipment and setup is completely different. I will test MAVSDK v3 to make sure that the MAVSDK is working ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants