Random values when sendding mode switch in SITL

I’m currently in the process of setting up a ROS2 environment to communicate with Pixhawk 6x. For the moment, I’m using SITL to test things before going to HW. So far, the AP_DDS works apart from the ROS2 services.

Arm Motors works (arm throttle SUCCESS), but result is ever sent back after the request.
Mode Switch has a very weird behavior. When sending an integer mode, let’s say 4 ROVER_MODE_GUIDED, the message will arrive , but a complete random number and it will fail because that (random) mode does not exist.

I have tested this both with python and cpp ROS2 nodes. Bellow you cna find my cpp node nipet for the request.

void call_mode_switch() {
        if (!mode_switch_client_->wait_for_service(std::chrono::seconds(1))) {
            RCLCPP_INFO(this->get_logger(), "Service not available, waiting again...");
            return;
        }

        auto request = std::make_shared<ardupilot_msgs::srv::ModeSwitch::Request>();
        uint8_t mode = 4;
        request->mode = mode;

        auto result_future = mode_switch_client_->async_send_request(request);
    }

No idea about ROS, but the tags say Rover while the command you’re sending is Copter. Wouldn’t ROVER_MODE_GUIDED be the correct command to use?

Thanks for the reply. I corrected the post, though the problem happens regardless. Input integer arrives with random value.

Hi @jvzacchi,

Thanks for the post. We probably need input from @rhys or @rfriedman.

1 Like

Yea, this seems like a bug. Can you file an issue and tag me (ryanf55) on github?

1 Like

Done :wink: Thanks a lo!