gui.d
October 29, 2023, 5:00pm
1
In this course, we are suggested to use the ‘utilities folder’ to work. So I did try. However when I try to compile, the compiler can’t find the path to included headers.
Here I tried to compile the solution of exercise 2.1 which I copied in the file named 'unit2_exercise21.cpp" in the folder ‘utilities’.
So I tried adding the path in the script. And it was not better.
#include "../rosbot_control/include/rosbot_control/rosbot_class.h"
I tried other combination without success.
I tried to look online, but I am not sure of what I am doing.
Could someone be kind other to help me out ?
Thank you
Just tried in the course it seems to work. So steps to reproduce:
You nee dto place the code inside the /home/user/catkin_ws/src/cpp_course_repo/c_scripts/src/unit2_exercise.cpp
The code is
#include “rosbot_control/rosbot_class.h”
#include <ros/ros.h>
int main(int argc, char **argv) {
ros::init(argc, argv, “rosbot_node”);
RosbotClass rosbot;
rosbot.move_forward(5.0);
float X_limit = 10.0;
float x = rosbot.get_position(1);
ROS_INFO_STREAM("X reached: " << x);
if (x >= X_limit) {
rosbot.stop_moving();
} else {
rosbot.move_backwards(5.0);
rosbot.stop_moving();
}
return 0;
}
You have to catkin make like so:
cd ~/catkin_ws
catkin_make
rosrun rosrun c_scripts unit2_exercise
The robot should go forwards and then backwards
Please elaborate if this didn’t work
1 Like
gui.d
October 30, 2023, 2:19pm
3
Thank you for your quick answer
Yes I can follow the courses’ steps but what if I wanted to work in ‘utilities’ ?
I want to organise my folder my own way in utilities without having to call catkin_make but compiled the code with ‘g++…’ and run with ./code_compiled
How could I do that ?
ralves
October 31, 2023, 12:15pm
4
Hi @gui.d ,
I’m happy to see that you want to know the inner details of compiling a program, which shows that you are aiming for perfect stature when it comes to understanding C++.
I just created a main.cpp file with the following content:
#include "geometry_msgs/Twist.h"
#include <stdio.h>
int main() {
printf("The Construct: Where Your Robotics Career Happens \n");
return 0;
}
In order to compile it, I just had to pass the -I parameter.
According to the docs :
-I dir
Add the directory dir to the list of directories to be searched for header files.
The final command in my case was:
g++ -std=c++11 main.cpp -I /opt/ros/noetic/include/ -o compiled
As you can see, I told g++ to search for geometry_msgs at /opt/ros/noetic/include/ .
Please let me know us know if you have more questions.
gui.d
November 1, 2023, 4:33pm
5
Hi @ralves ,
Thank you for your help.
As you explained, I added the -I in the command, along side with the directory, which gives me the follwoing command line:
g++ -std=c++11 unit2_exercise21.cpp -I /catkin_ws/src/cpp_course_repo/rosbot_control/include/ -o compiled
My folder having the follwing architecture:
The line of command was unsuccessful (I tried a few variations for the path, here is one)
What did I do wrong ?
Thank you for your time
ralves
November 1, 2023, 6:45pm
6
Hi @gui.d ,
the path to catkin_ws is wrong.
Rather than
/catkin_ws/src/cpp_course_repo/rosbot_control/include/
You have to use either:
~/catkin_ws/src/cpp_course_repo/rosbot_control/include/
or
/home/user/catkin_ws/src/cpp_course_repo/rosbot_control/include/
If you don’t understand this point, please take the Linux course that is freely available in our platform.
system
Closed
November 6, 2023, 6:45pm
7
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.