ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Is it possible to create a VS Studio 2019 (IDE) Project for ROS2?

asked 2022-03-14 10:13:45 -0500

alberto gravatar image

Hi all,

I'm learning ROS2 on Windows. I manage to install ROS2 foxy and it's working fine. Now I have to start my project, I tried to write a simple publisher including:

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

If I open it with VS, intellisense doesn't work. For example I don't have any highlighting on:

rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;

Searching on Google I found 2 way to have the Intellisense suggestions:

  1. Use VS Code with the ROS extension.
  2. Create a VS (IDE) project and to setup the VC++ directories path, in Project Options.

Since I have VS 2019 already installed, I would like to use the second one, but I don't understand if it's possible. I mean: if I create a VS studio project containing all the ros package files (CMakeLists, package.xml ecc.), can I still build my package with colcon build? How should I build it? I have the feeling that .vcxproj file is something "incomprehensible" for the ros ws.

Is it better/easier to use VS Code to write the code, and then keep doing colcon build and ros2 run .. with the prompt command?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-14 12:17:36 -0500

alberto gravatar image

updated 2022-03-15 08:30:53 -0500

Regarding VS IDE, I noticed that colcon build creates some .vcxproj files in the build folder, but I think I should't touch them (!SEE EDIT!).

So I was tired of searching and I decided to install VS Code. Then, in order to make Intellisense work, I added into c_cpp_properties.json includePath the include folder of rclcpp.hpp and any other libraries I need. There are a lot of tutorial about it on Google.

I didn't install the ROS extension since I'm fine using the prompt to build and run the package.

VS Code seems to work as I expect, so for me this is the solution. If you have more knowledge or if I missed something, feel free to answer.

EDIT: I was wrong! Visual Studio project is always created!

The whole question was badly asked. I thought that first I had to create a VS project, where I would put the entire ros package; and then build it with ros command (and I couldn't understand how). The reality is that I only need to create a ros package with some source .cpp file, with whatever editor I want; and then setup CMakeLists. This way, when I build the code with colcon build, it automatically creates some VS project (in build folder). One of them has the same name of my node and has the project properties I specified in the CMakeLists. Moreover, I can edit the .cpp file of that project directly from Visual Studio. Regarding Intellisense, I have no more red squiggles in Visual Studio because now I imported all I need.

So in the end:

  • You can freely use Visual Studio (IDE) + command prompt to build and run the nodes
  • You set all dependecies through CMakeLists, and they will be set automatically for the visual studio project after the build.

Sorry if all of these things may seem obvious, but they weren't so clear to me. I leave the post here, maybe it could help someone in the future.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-03-14 10:13:45 -0500

Seen: 323 times

Last updated: Mar 15 '22