Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

How cam I disable GPS in gazebo and use the gps coord from ros?

Hello everyone, hope you are all having a great time.
I'm trying to navigate my quadrotor using GPS coordinates in mavros. my FCU board does not have a GPS sensor, but the offboard has several sensors by which a GPS coordinate is approximated.
For now, I'm generating one GPS coordinate (the origin) in a ros node (given below) and in another node(offboard-node), I intend on using it.
The issue is, it seems whenever I start a gazebo simulation using make px4_sitl gazebo or make px4_sitl gazebo_iris__ksql_airport, the mavros/global_position/global is filled with the world coordinate. it seems something else is also publishing into this topic.
I want to stop this, so that I can see if me publishing gps coordinates from ros, can really navigate the quadrotor to the specified GPS coordinate. How should I go about this ? Thanks a lot in advance

Here are the snippets I use:

#include <limits>
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <mavros_msgs/State.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <sensor_msgs/NavSatFix.h>
#include <geographic_msgs/GeoPoseStamped.h>
#include <mavros_msgs/Altitude.h>
#include <mavros_msgs/GlobalPositionTarget.h>

double latitude, longitude;
bool gps_received = false;

//http://wiki.ros.org/mavros
int main(int argc, char **argv)
{
    ros::init(argc, argv, "offb_node_gps_puber");
    ros::NodeHandle nh;

    //set gps coordinate as if we are the real gps
    ros::Publisher pub_global_gps = nh.advertise<sensor_msgs::NavSatFix>("mavros/global_position/global", 10);
    sensor_msgs::NavSatFix gps_target;

    //the setpoint publishing rate MUST be faster than 2Hz
    ros::Rate rate(20.0);

    // wait for GPS connection
    int i = 0;
    gps_target.longitude = 20;
    while (ros::ok())
    {
        gps_target.header.stamp = ros::Time::now();
        gps_target.header.frame_id = "base_link";
        gps_target.header.seq = i++;
        gps_target.position_covariance_type = gps_target.COVARIANCE_TYPE_DIAGONAL_KNOWN;
        gps_target.position_covariance = {1, 0, 0, 0, 1, 0, 0, 0, 1};
        gps_target.status.status = sensor_msgs::NavSatStatus::STATUS_FIX;
        gps_target.status.service = sensor_msgs::NavSatStatus::SERVICE_GPS;

        gps_target.latitude = 20;
        gps_target.longitude = 20;
        gps_target.altitude = 1;

        pub_global_gps.publish(gps_target);

        ros::spinOnce();
        rate.sleep();
    }
    return 0;
}

How cam I disable GPS in gazebo and use the gps coord from ros?

Hello everyone, hope you are all having a great time.
I'm trying to navigate my quadrotor using GPS coordinates in mavros. my FCU board does not have a GPS sensor, but the offboard has several sensors by which a GPS coordinate is approximated.
For now, I'm generating one GPS coordinate (the origin) in a ros node (given below) and in another node(offboard-node), I intend on using it.
The issue is, it seems whenever I start a gazebo simulation using make px4_sitl gazebo or make px4_sitl gazebo_iris__ksql_airport, the mavros/global_position/global is filled with the world coordinate. it seems something else is also publishing into this topic.
I want to stop this, so that I can see if me publishing gps coordinates from ros, can really navigate the quadrotor to the specified GPS coordinate. How should I go about this ? Thanks a lot in advance

Here are the snippets I use:

#include <limits>
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <mavros_msgs/State.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <sensor_msgs/NavSatFix.h>
#include <geographic_msgs/GeoPoseStamped.h>
#include <mavros_msgs/Altitude.h>
#include <mavros_msgs/GlobalPositionTarget.h>

double latitude, longitude;
bool gps_received = false;

//http://wiki.ros.org/mavros
int main(int argc, char **argv)
{
    ros::init(argc, argv, "offb_node_gps_puber");
    ros::NodeHandle nh;

    //set gps coordinate as if we are the real gps
    ros::Publisher pub_global_gps = nh.advertise<sensor_msgs::NavSatFix>("mavros/global_position/global", 10);
    sensor_msgs::NavSatFix gps_target;

    //the setpoint publishing rate MUST be faster than 2Hz
    ros::Rate rate(20.0);

    // wait for GPS connection
    int i = 0;
    gps_target.longitude = 20;
    while (ros::ok())
    {
        gps_target.header.stamp = ros::Time::now();
        gps_target.header.frame_id = "base_link";
        gps_target.header.seq = i++;
        gps_target.position_covariance_type = gps_target.COVARIANCE_TYPE_DIAGONAL_KNOWN;
        gps_target.position_covariance = {1, 0, 0, 0, 1, 0, 0, 0, 1};
        gps_target.status.status = sensor_msgs::NavSatStatus::STATUS_FIX;
        gps_target.status.service = sensor_msgs::NavSatStatus::SERVICE_GPS;

        gps_target.latitude = 20;
        gps_target.longitude = 20;
        gps_target.altitude = 1;

        pub_global_gps.publish(gps_target);

        ros::spinOnce();
        rate.sleep();
    }
    return 0;
}