![]() Exclude irrelevant folders from indexing to speed up CLion.Building, Running, and Debugging within CLion.That about concludes this short introduction to debugging ROS C++ code. ![]() Expand this in the bottom right tab and you should be able to browse around the variables and inspect their numbers. Afterwards, you should get brought up to line 86 which is the beginning of the int CanInterface::loop() functionĬlick Step over a couple of more times and you should accumulate some variables to inspect. ![]() Use Step over several times until the text editor highlights that line and then click Step into. Let’s say we are interested in ros_can.loop(). Step into - if you are currently at a function call, step into will go inside the function (potentially into another file).Step over - continues to the next line of code in the program you are currently in.Now we can continue navigating the code using the debugger navigation controls above the bottom right tab. The bottom left tab shows you the variables currently in scope along with their values.The bottom right tab shows you the callback stack.The text editing bit has highlighted the code line on which you are currently.Your layout should change to something like this: Press the green bug icon on the top right corner. Now we’re finally ready to start debugging. You should see a message saying Simulating CAN data. From there you can do all of your normal ROS commands so let’s do a roslaunch! ![]() On the bottom of the CLion window, you should see a Terminal tab which is simply a normal terminal that you can use directly from CLion. Let’s now launch ros_can with a testing launch file and see. Click next to line 442 and a red dot should appear like in the picture below. You can set a breakpoint by clicking on the right-hand side of the line number. A breakpoint tells the debugger when to interrupt the code execution and give you command of it. For this example, let’s set a breakpoint at the beginning of the main. Then the setupCANbus function initialises the CAN connection and finally the while loop just runs at a predefined rate and calls ros_can.loop() where all of the magic happens. Without going into too much detail, the first 3 lines start up the ROS node. After you build the packages make sure you source your workspace and then open CLion the same way we did before: Not that you also need to have ROS sourced for this. You can do that by just doing catkin_make. To fix this issue, we need to close CLion, get back to the terminal and build both eufs_msgs and ros_can. Depending on your setup CLion might have found the ROS libraries but it definitely shouldn’t have found eufs_msgs. In different words, CLion doesn’t know of ROS and doesn’t know where to find its binaries. That is because we actually haven’t sourced ROS in the terminal from which we opened CLion. The issue is that it can’t find the ROS build system. Hold on a moment, what is the big red text down below? That is your CMake window which tells you how CLion is reading the CMakeLists file of the project. Once registered, you’ll see this screenĬlick on Open and navigate to the ros_can package. Since this is the first time you’ve opened it, you’ll need to set up a profile and start your free trial. However, I’d suggest putting it into your root space. There is no installing per-say, you just have to unarchive it and run the executable. So let’s dive straight into ROS debugging with CLion! Setupĭownload CLion with a free 30-day trial. Personally I like CLion the most as it works out of the box and is feature-rich, albeit not free and a bit heavy on memory. Here’s a shortlist of IDEs that support it natively: In many ways, we are limited by the ROS build system which uses CMake. Luckily, there are IDEs which offer graphical interfaces to the power of GDB! What is the right tool? The most popular debugger for C++ is GDB but its command-line nature has a steep learning curve. It is a tool that allows you to stop your program mid-execution and inspect important information such as where are you in the call stack, existing variables and their values, memory usage and probably most importantly, why did the program crash again? In this short article, I’ll show you the basics of how to get started and get your hands dirty with some code! What is a debugger? Well, debugging ROS is surprisingly easy, useful and very satisfying. Reasons vary from “debuggers are useless when you run real robots” to “there are no good tools for that”. Throughout my time in robotics, I have noticed that not many people use debuggers when developing C++ for ROS.
0 Comments
Leave a Reply. |