c++visual-studio-coderos

VSCode C++ Extension cannot locate "physics::ModelPtr" from gazebo library


I am trying to use VSCode to write ROS program. However, the C++ Extension seems to have trouble finding the physics::ModelPtr. Does anyone know how to fix this?

Here is my code:

#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <ros/ros.h>
#include <geometry_msgs/Pose.h>

namespace gazebo
{
  class camera_pose_control : public ModelPlugin
  {
    private: physics::ModelPtr model;
    private: ros::NodeHandle nh;
    private: ros::Subscriber poseSub;

    public: void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
    {
      std::cout << "Loading Camera Pose Control Plugin\n" << std::endl;
      this->model = _model;

      // ROS Node and Subscriber
      int argc = 0;
      char **argv = NULL;
      ros::init(argc, argv, "gazebo_client", ros::init_options::NoSigintHandler);
      ROS_INFO("ROS node initialized within Gazebo Plugin");
      poseSub = nh.subscribe("camera/pose", 10, &camera_pose_control::OnPoseReceived, this);
    }

    // Callback function to set the model pose
    public: void OnPoseReceived(const geometry_msgs::PoseConstPtr &msg)
    {
      ignition::math::Pose3d newPose(msg->position.x, msg->position.y, msg->position.z,
                                     msg->orientation.w, msg->orientation.x, msg->orientation.y, msg->orientation.z);
      this->model->SetWorldPose(newPose);
    }
  };
  GZ_REGISTER_MODEL_PLUGIN(camera_pose_control)
}

Here is my c_cpp_properties.json:

{
    "configurations": [
        {
            "browse": {
                "databaseFilename": "${default}",
                "limitSymbolsToIncludedHeaders": false
            },
            "includePath": [
                "/opt/ros/noetic/include/**",
                "/root/ml_project_ws/src/ml_project/include/**",
                "/usr/include/**",
                "/usr/lib/x86_64-linux-gnu/gazebo-11/**"
            ],
            "name": "ROS",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "c++14"
        }
    ],
    "version": 4
}

Solution

  • I've had the same problem and has been rather frustrating but I've managed to fix it on my machine. Hopefully this will work for others. Go to your C++ Configurations and change the C++ standard to at least C++17. After changing this, intellisense started working and I could locate all files.

    TLDR Change C++ standard to C++17