Looking at this thread to use mavros_msgs’s CommandHome service.
However I have dificulty using the service, the rosservice call also fails so I’d really appreciate any help on this.
I tried to use the service like this as I belive since there is already a request for home position, I cant use a service client, as I do not want to request anything, I want to send the response, so here I define a server for this
ros::ServiceServer server = nh.advertiseService("mavros/cmd/set_home", request_handler);
//or
ros::ServiceServer server = nh.advertiseService<mavros_msgs::CommandHomeRequest, mavros_msgs::CommandHomeResponse>("mavros/cmd/set_home", request_handler);
Now when it comes to the request handler, I get confused, as how to provide the required data.
based on the rosservice info /mavros/cmd/set_home output which is as follows:
Node: /mavros
URI: rosrpc://localhost:33449
Type: mavros_msgs/CommandHome
Args: current_gps yaw latitude longitude altitude
my handler should be using CommandHome type, in which case I would be having :
bool request_handler(mavros_msgs::CommandHome& cmd)
{
auto request = cmd.request;
auto response = cmd.response;
//what to do now?
return true;
}
or have to separate arguments like this :
bool request_handler(mavros_msgs::CommandHomeRequest& request, mavros_msgs::CommandHomeResponse& response)
{
//.?!
return true;
}
Now, the thing is, there is nothing in response object to fill in, except a result and status attribute while
request contains all information concerning gps such s lat, lon, alt,yaw, and current_gps which is bool.
I also tried the service client like this :
ros::ServiceClient set_home_pos_client = nh.serviceClient<mavros_msgs::CommandHome>("mavros/cmd/set_home");
mavros_msgs::CommandHome request;
request.request.altitude = 0;
request.request.current_gps = true;
request.request.latitude=20.0;
request.request.longitude=20.0;
request.request.yaw=0;
if (set_home_pos_client.call(request))
{
ROS_INFO("Request processed successfully with response: %d status: %d", request.response.result, request.response.success);
}
else
{
ROS_INFO("Request failed!");
return 1;
}
and got :
Request processed successfully with response: 1 status: 0
yet, I still keep getting this :
[ INFO] [1647084882.119085314]: IMU: High resolution IMU detected!
[ INFO] [1647084883.106619128]: GF: Using MISSION_ITEM_INT
[ INFO] [1647084883.106703983]: RP: Using MISSION_ITEM_INT
[ INFO] [1647084883.106789902]: WP: Using MISSION_ITEM_INT
[ INFO] [1647084883.106863086]: VER: 1.1: Capabilities 0x000000000000e4ef
[ INFO] [1647084883.106907620]: VER: 1.1: Flight software: 010d0040 (31545f85fb000000)
[ INFO] [1647084883.106973228]: VER: 1.1: Middleware software: 010d0040 (31545f85fb000000)
[ INFO] [1647084883.107100870]: VER: 1.1: OS software: 050d00ff (8660572a3c69e0e2)
[ INFO] [1647084883.107140673]: VER: 1.1: Board hardware: 00000001
[ INFO] [1647084883.107183444]: VER: 1.1: VID/PID: 0000:0000
[ INFO] [1647084883.107211555]: VER: 1.1: UID: 4954414c44494e4f
[ WARN] [1647084883.108537423]: CMD: Unexpected command 520, result 0
[ INFO] [1647084892.104266753]: HP: requesting home position
[ INFO] [1647084897.104353469]: GF: mission received
[ INFO] [1647084897.105102390]: RP: mission received
[ INFO] [1647084897.105265952]: WP: mission received
[ INFO] [1647084902.104458881]: HP: requesting home position
[ INFO] [1647084912.104236629]: HP: requesting home position
Now how should I be sending the information?
All I want to do is, when the flight wants to start, I send a gps position for the robots home/starting position which is requested at initialization phase.
Am I even in the right track?
Update 1:
based on this issue seems I must use fake_gps plugin
Use
fake_gpsplugin and send local position estimation as GPS data;
now, my question is, how am I supposed to do this?
There was a link (this one) to px4_config.yaml, by which one can configure PX4 to use fake_gps, however, there is no enable/disable option, so I guess checking mocap/vision would enable or disable it.
the problem is, I dont have a mocap, and I am not going to use mocap, I have no idea how vision is used,
so what should I change, so that I can send random/arbitrary gps point simulating real gps coordinates, so the ros navigation system can use it and basically navigate the drone?