ros-navigation / navigation2_tutorials

Tutorial code referenced in https://docs.nav2.org/
180 stars 124 forks source link

Compile error nav2_straightline_planner #55

Closed LMManto closed 1 year ago

LMManto commented 2 years ago

Hello to everybody,

I am trying to build the _nav2_straightlineplanner package following the navigation2 Planner plugin tutorial.

When I compile:

colcon build --packages-select nav2_straightline_planner

I get the following error:

Starting >>> nav2_straightline_planner
--- stderr: nav2_straightline_planner                             
In file included from /home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/src/straight_line_planner.cpp:46:
/home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/include/nav2_straightline_planner/straight_line_planner.hpp:67:8: error: ‘void nav2_straightline_planner::StraightLine::configure(const WeakPtr&, std::string, std::shared_ptr<tf2_ros::Buffer>, std::shared_ptr<nav2_costmap_2d::Costmap2DROS>)’ marked ‘override’, but does not override
   67 |   void configure(
      |        ^~~~~~~~~
In file included from /opt/ros/foxy/include/class_loader/class_loader_core.hpp:57,
                 from /opt/ros/foxy/include/class_loader/class_loader.hpp:55,
                 from /opt/ros/foxy/include/class_loader/multi_library_class_loader.hpp:52,
                 from /opt/ros/foxy/include/pluginlib/class_loader.hpp:58,
                 from /home/srl/Documents/Github/nav_ws/install/nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_ros.hpp:53,
                 from /home/srl/Documents/Github/nav_ws/install/nav2_core/include/nav2_core/global_planner.hpp:21,
                 from /home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/include/nav2_straightline_planner/straight_line_planner.hpp:51,
                 from /home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/src/straight_line_planner.cpp:46:
/opt/ros/foxy/include/class_loader/meta_object.hpp: In instantiation of ‘B* class_loader::impl::MetaObject<C, B>::create() const [with C = nav2_straightline_planner::StraightLine; B = nav2_core::GlobalPlanner]’:
/opt/ros/foxy/include/class_loader/meta_object.hpp:216:7:   required from here
/opt/ros/foxy/include/class_loader/meta_object.hpp:218:12: error: invalid new-expression of abstract class type ‘nav2_straightline_planner::StraightLine’
  218 |     return new C;
      |            ^~~~~
In file included from /home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/src/straight_line_planner.cpp:46:
/home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/include/nav2_straightline_planner/straight_line_planner.hpp:60:7: note:   because the following virtual functions are pure within ‘nav2_straightline_planner::StraightLine’:
   60 | class StraightLine : public nav2_core::GlobalPlanner
      |       ^~~~~~~~~~~~
In file included from /home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/include/nav2_straightline_planner/straight_line_planner.hpp:51,
                 from /home/srl/Documents/Github/nav_ws/src/navigation2/nav2_straightline_planner/src/straight_line_planner.cpp:46:
/home/srl/Documents/Github/nav_ws/install/nav2_core/include/nav2_core/global_planner.hpp:50:16: note:   ‘virtual void nav2_core::GlobalPlanner::configure(rclcpp_lifecycle::LifecycleNode::SharedPtr, std::string, std::shared_ptr<tf2_ros::Buffer>, std::shared_ptr<nav2_costmap_2d::Costmap2DROS>)’
   50 |   virtual void configure(
      |                ^~~~~~~~~
make[2]: *** [CMakeFiles/nav2_straightline_planner_plugin.dir/build.make:63: CMakeFiles/nav2_straightline_planner_plugin.dir/src/straight_line_planner.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/nav2_straightline_planner_plugin.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< nav2_straightline_planner [3.64s, exited with code 2]

Summary: 0 packages finished [3.94s]
  1 package failed: nav2_straightline_planner
  1 package had stderr output: nav2_straightline_planner

I saw there was a closed issue related to this, but it was closed without writing the solution, and the one proposed by Philison doesn't work for me.

Can anyone help me?

Thank you very much

SteveMacenski commented 2 years ago

The API of these plugins have changed over time due to changes in the interfaces as we've continued to develop the stack.

If you have an older distribution, you may need to change the newer API in the tutorial code to match them. If you have a new distribution and its not working, it may have been that we didn't update them here to reflect the current API. What distribution are you on?

See https://github.com/ros-planning/navigation2/blob/main/nav2_core/include/nav2_core/global_planner.hpp (check out the right branch based on your distribution to see the API)

SteveMacenski commented 2 years ago

Looks like the current master of both are in line, so you're maybe running Foxy where you have to update the API?

LMManto commented 2 years ago

Dear @SteveMacenski

Thank you for your kind reply.

At the end I figured out how to compile it, because I found out some errors in the straightline plugin code. I am going to write them here, in the case someone has the same issue.

All the problems are related to the configure() function. In the _nav2_straightline_planner/src/straight_lineplanner.cpp file, the function:

void StraightLine::configure(
  const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
  std::string name, std::shared_ptr<tf2_ros::Buffer> tf,
  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros)

Should be replaced with:

void StraightLine::configure(
  rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
  std::string name, std::shared_ptr<tf2_ros::Buffer> tf,
  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros)

The problem is related to the first parameter of the funcion, the parent argument. It should be _rclcpplifecycle::LifecycleNode::SharedPtr parent type, not _const rclcpplifecycle::LifecycleNode::WeakPtr & parent, because this function derives from the _nav2core::GlobalPlanner configure() function (since the StraightLine class inherits from the GlobalPlanner one: _class StraightLine : public nav2core::GlobalPlanner).

In fact, in the _globalplanner.hpp file, the function is like this:

virtual void configure(
  rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
  std::string name, std::shared_ptr<tf2_ros::Buffer> tf,
  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) = 0;

Another error is related to the first line of the void StraightLine::configure() function, the one related to the parent argument, that was:

node_ = parent.lock();

Now it should be replaced simply with:

node_ = parent;

That's because this parent parameter has changed, and now it hasn't the .lock method.

Of course, it is necessary to update the configure() function in the _nav2_straightline_planner/include/nav2_straightline_planner/straight_lineplanner.hpp file:

  void configure(
    rclcpp_lifecycle::LifecycleNode::SharedPtr parent,
    std::string name, std::shared_ptr<tf2_ros::Buffer> tf,
    std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) override;

Now, my problem: I can compile successfully the package:

source /opt/ros/foxy/setup.bash

colcon build --symlink-install

And I have changed the _nav2params.yaml file (_src/navigation2/nav2_bringup/bringup/params/nav2params.yaml):

 planner_server:
   ros__parameters:
     expected_planner_frequency: 20.0
     use_sim_time: True
     planner_plugins: ["GridBased"]
     GridBased:
       plugin: "nav2_straightline_planner/StraightLine"
       interpolation_resolution: 0.1

But when I run the simulator, using:

source /opt/ros/foxy/setup.bash
export TURTLEBOT3_MODEL=waffle
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/foxy/share/turtlebot3_gazebo/models

ros2 launch nav2_bringup tb3_simulation_launch.py params_file:=/home/srl/Documents/Github/nav_ws/src/navigation2/nav2_bringup/bringup/params/nav2_params.yaml

I get the following error:

[planner_server-9] [FATAL] [1655722824.154346143] [planner_server]: Failed to create global planner. Exception: According to the loaded plugin descriptions the class nav2_straightline_planner/StraightLine with base class type nav2_core::GlobalPlanner does not exist. Declared types are  nav2_navfn_planner/NavfnPlanner smac_planner/SmacPlanner smac_planner/SmacPlanner2D

[lifecycle_manager-13] [ERROR] [1655722824.154701256] [lifecycle_manager_navigation]: Failed to change state for node: planner_server

[lifecycle_manager-13] [ERROR] [1655722824.154726900] [lifecycle_manager_navigation]: Failed to bring up all requested nodes. Aborting bringup.

[rviz2-4] Start navigation
[rviz2-4] [ERROR] [1655722916.989770691] [rviz2]: FollowWaypoints action server is not available. Is the initial pose set?

So it seems that the nav2_straightline_planner::StraightLine plugin class is not between the declared types for the _nav2core::GlobalPlanner.

Can you think of any solution to this problem?

Thank you very much Best regards

SteveMacenski commented 2 years ago

The tutorial is correct for the current status of rolling which all tutorials target. The changes you made are w.r.t. Foxy distribution use.

You probably just need to re-source your workspace's install space. When you successfully built the plugin package, it adds a file for the plugin index that you need to re-source so your system is aware of it.

LMManto commented 1 year ago

I close this issue since it wasn't possible for us to integrate these tutorials using ROS2 Foxy version, so we are trying to do it using ROS2 Humble.