@metinburak, did you try to switch to "manual" mode in mid flight using the code above? Maybe I am missing something but the loop (while(ros::ok())) will switch back to offboard, so we may end up switching back and forth between manual and offboard in an infinite loop unless the RC overwrites all other controls received from mavlink (mavros). Can somebody confirm that?
We are using a single board computer, on-board, connected thru USB. Commands are sent over mavros from the computer to pixhawk. One channel on the RC can switch between "manual", "position control" and "offboard" modes. Another RC channel is configured as a kill switch (I hope we will never have to use this). I am so surprised that there is no documentation and clear guide lines on that and we have to guess and try on safety.