Fields2Cover / fields2cover_ros

A ROS interface of Fields2Cover
BSD 3-Clause "New" or "Revised" License
44 stars 19 forks source link

Support for Json file along with xml file #8

Closed RamanaBotta closed 1 year ago

RamanaBotta commented 1 year ago

Hi Team, I am not much familiar with XML format that you guys kept in this project, Can you Please add support for Geojson file, You guys are already having the utility to read from JSON in Fields2Cover.

Gonzalo-Mier commented 1 year ago

Hi @RamanaBotta, It's already there. You can import a GeoJson field in C++ or Python in a few lines.

RamanaBotta commented 1 year ago

I have changed the init_VisualizerNode function to as below, but still no success Error is : [ WARN] [1673261794.229063390]: Reconfigure callback failed with exception Coordinate system empty:

I have attached JSON file(zipped) also can you please help me with this.

  void VisualizerNode::init_VisualizerNode() {
    field_polygon_publisher_ = public_node_handle_.advertise<geometry_msgs::PolygonStamped>("/field/border", 1, true);
    field_no_headlands_publisher_ = public_node_handle_.advertise<geometry_msgs::PolygonStamped>("/field/no_headlands", 1, true);
    field_gps_publisher_ = public_node_handle_.advertise<sensor_msgs::NavSatFix>("/gps/fix", 1, true);
    field_swaths_publisher_ = public_node_handle_.advertise<visualization_msgs::Marker>("/field/swaths", 1, true);

    std::string field_file;
    private_node_handle_.getParam(
        "field_file", field_file);

    // f2c::Parser::importGml(field_file, fields_);
    f2c::Parser::importJson(field_file, fields_);
    auto field = fields_[0]; 
    field.setEPSGCoordSystem(4326);
    // f2c::Transform::transform(field, "UTM:32U");
    f2c::Transform::transform(field, "UTM:32U");
    robot_.cruise_speed = 2.0;
    robot_.setMinRadius(2.0);
    double headland_width = 3.0*robot_.op_width;
  }

test_2_cell.zip

launch file changes

 <launch>
<node pkg="fields2cover_ros" type="visualizer_node" name="visualizer" output="screen">
  <!-- <param name="field_file" type="string" value="$(find fields2cover_ros)/data/example1.xml"/> -->
  <param name="field_file" type="string" value="$(find fields2cover_ros)/data/test_2_cell.json"/>

</node>
<node pkg="rviz" type="rviz" name="rviz" args="-d $(find fields2cover_ros)/launch/demo.rviz"/>
<node pkg="rqt_reconfigure" type="rqt_reconfigure" name="rqt_reconfigure"/>
<node pkg="tf2_ros" type="static_transform_publisher" name="static_tf_fake" args="0 0 0 0.015 0 0 map base_link" />

</launch>
Gonzalo-Mier commented 1 year ago

Really weird. I'm able to read it fine. The error that you got comes from the transform, but you have set the coordinate system correctly. I would recommend you to add std::cerr<<"Error 1"<<std::endl; on several places to check where exactly it crash.

RamanaBotta commented 1 year ago

Okay, do you think it's worth adding geojson support to this project? If yes can you please add support for it?

Gonzalo-Mier commented 1 year ago

Hi @RamanaBotta, GeoJson is already supported by the project. There's no need to do anything else about that.

RamanaBotta commented 1 year ago

Okay, Thank you.