@Jaeyoung-Lim, I checked the ROS link you had given me above and then according to the “command.cpp
” in mavros below, I had written the necessary codes firstly.
Website:
https://github.com/mavlink/mavros/blob/master/mavros/src/plugins/command.cpp
bool vtol_transition_cb(mavros_msgs::CommandVtolTransition::Request &req,
mavros_msgs::CommandVtolTransition::Response &res)
{
using mavlink::common::MAV_CMD;
return send_command_long_and_wait(false,
enum_value(MAV_CMD::DO_VTOL_TRANSITION), false,
req.state,
0, 0, 0, 0, 0, 0,
res.success, res.result);
}
After that, I have defined my extra variables and libraries as like these in my .cpp file:
#include <mavros_msgs/CommandTriggerControl.h>
#include <mavros_msgs/CommandTriggerInterval.h>
#include <mavros_msgs/CommandVtolTransition.h>
mavros_msgs::CommandVtolTransition change_VTOL_flight;
ros::ServiceClient arming_client_VTOL;
arming_client_VTOL = controlnode.serviceClient<mavros_msgs::CommandVtolTransition>("/mavros/cmd/command/vtol_transition");
After that, I have defined a function to see if everything works or not (to communicate with CommandVtolTransition or not). Thus, I have written “ROS_INFO” to see the results first.
int vtol_arming(){
mavros_msgs::CommandVtolTransition arm_cmd_vtol;
arm_cmd_vtol.request.state = true;
while(ros::ok()){
if(arming_client_VTOL.call(arm_cmd_vtol)){
ROS_INFO("VTOL Request - State: %d", arm_cmd_vtol.request.state);
}
if(arming_client_VTOL.call(arm_cmd_vtol)){
ROS_INFO("VTOL Response - Success: %d", arm_cmd_vtol.response.success);
}else{
//ROS_ERROR("Failed to call service CommandVtolTransition");
ROS_INFO("Failed to call service CommandVtolTransition");
}
if(arming_client_VTOL.call(arm_cmd_vtol)){
ROS_INFO("VTOL Response - Result: %d", arm_cmd_vtol.response.result);
}
if(arm_cmd_vtol.response.success){
ROS_INFO("VTOL:Fixed Wing Arming Successful");
//arm_cmd_vtol.request.state = 4;
}else{
//ROS_INFO("VTOL:Fixed Wing Arming failed with %d", arm_cmd_vtol.response.success);
ROS_INFO("VTOL:Quad-Rotor is still ON and VTOL:Fixed Wing is failed: %d", arm_cmd_vtol.response.success);
}
//@returns 1 - mode change successful
//@returns 0 - mode change not successful
if(arming_client_VTOL.call(arm_cmd_vtol) && arm_cmd_vtol.response.success){
ROS_INFO("VTOL:Fixed Wing is Activated: %d", arm_cmd_vtol.response.success);
return 0;
}else{
//ROS_ERROR("VTOL:Fixed Wing Activation is failed!!!");
ROS_INFO("VTOL:Fixed Wing Activation is failed!!!");
return -1;
}
}
}
At the end, I always failed which I couldn’t understand how to activate this “VTOL Transition” with MAVROS in my ROS C++ code which I have confused a lot at the end that I even don’t know where am I doing wrong, or how to do it correctly in coding way.
Apart from the above code, I have tried many ways of writing code but I have failed all the time. Thus, I came here to get you friends’ opinions too.
If it is possible, would you guide me how could we do it? I will be very happy and glad if you would help me to solve this problem, thank you very much.
Note:
@Jaeyoung-Lim friend, I have followed what you said, but I still couldn’t figure out why mu VTOL transition is not working which I still couldn’t understand how to write that “while(condition)” in ROS C++ to activate VTOL transition at will which I have even checked the QgroundControl
codes in its github website which they had written their own way of coding which it didn’t help so much (it was in the “vehicle.h and vehicle.cc
” files).
qgroundcontrol/src/Vehicle/Vehicle.h
qgroundcontrol/src/Vehicle/Vehicle.cc
The above code that I wrote for testing always give me “It is failed / Failed to call service CommandVtolTransition
”. I actually understood better comparing to other day - the way of the code written in mavros and apply it to ROS C++; but I still couldn’t understand the VTOL activation process to write in the while loop process while OFFBOARD mode is active.
@Jaeyoung-Lim friend, if it is possible would you like to give me some hints please? I will be very glad and happy if you would guide me a little more further; because right now I am stuck at this problem and I still couldn’t find any solution so far. I look forward hearing from you, thank you very much.