0
$\begingroup$

Rosanswers logo

If possible I'd like for experienced users to post their suggestions whether this is the correct way, and explain the commands commented as 'black magic' please.

Putting together the initial bit:

1. Install ROS

follow instructions on wiki ROS tutorial.

2. Create WorkSpace

mkdir -p ~/catkin_ws/src creates src folder inside workspace folder

cd ~/catkin_ws/src change directory to src folder

catkin_init_workspace creates symlink (not sure what this is). creates SMakeLists in src folder

cd ~/catkin_ws/ change directory to workspace folder

source opt/ros/indigo/setup.bash black magic

catkin_make always exectue command in the workspace folder. creates build folder and devel folder with files inside

source devel/setup.bash black magic

echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc black magic

3. Create Package

cd ~/catkin_ws/src change directory to src folder, where package folder must be created

catkin_create_pkg my_pkg roscpp name the package and specify dependency. this creates the package folder. inside it, include folder, src folder, CMakeLists file and package file are created

4. Add the code

add code inside the src folder inside the package folder. save as hello.cpp

#include int main(int argc, char** argv){ ros::init(argc, argv, "hello_ros"); ros::NodeHandle nh; ROS_INFO_STREAM("Hello, ROS!"); }

5. Fix the CMakeLists inside the package folder

cmake_minimum_required(VERSION 2.8.3) 
project(book_pkg)

find_package(catkin REQUIRED COMPONENTS   roscpp  )    

catkin_package( )

include_directories( include  ${catkin_INCLUDE_DIRS})

add_executable(hello src/hello.cpp) 
target_link_libraries(hello ${catkin_LIBRARIES})

6. Build and run (run the package that is)

cd ~/catkin_ws back to workspace folder

catkin_make catkin specific command to build and make package

once build is successful, open new terminal, type: roscore open another terminal, type: rosrun my_pkg hello


Originally posted by finch1 on ROS Answers with karma: 9 on 2018-01-05

Post score: 0


Original comments

Comment by PeteBlackerThe3rd on 2018-01-05:
This is not a question. I'm confused, what do you want help with?

Comment by finch1 on 2018-01-05:
I am having issues understanding the ROS procedure. The one above worked, only after weeks of trial though. If possible I'd like for experienced users to post their suggestions whether this is the correct way, and explain the commands commented as 'black magic' please.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I feel your pain on this one, it's a lot of stuff to get your head around all at the same time when you're starting out. I'll explain exactly what is going on with the three 'black magic' commands you highlighted in your question.

source opt/ros/indigo/setup.bash This command executes the bash script 'opt/ros/indigo/setup.bash' which sets the envrionment variables needed for the ros command line tools to work and means the packages installed with ros can be found.

source devel/setup.bash Similar to the command above this executed the bash script 'devel/setup.bash' within the current working directory. This adds the paths for this package to the ros envrionment variables so you can find and execute the assets of packages in this workspace, for example with rosrun or roslaunch.

echo "source ~/catkin_ws/devel/setup.bash" >> ¬/.bashrc This command appends the line 'source ~/catkin_ws/devel/setup.bash' to the end of the .bashrc file in your home folder. Why would you want to do this you ask, well the .bashrc file is another bash script that is automatically run every time you start a new terminal. So by adding this line the environment variables will automatically setup to use the packages in the catkin_ws workspace every time you open a new terminal.

Hope this explains a bit more of what's going on for you.


Originally posted by PeteBlackerThe3rd with karma: 9529 on 2018-01-05

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by finch1 on 2018-01-05:
Hello Peter, helps a lot, big thanks for this. I tried to remove this question, its not clear, as you said. Am trying to put a tutorial together for other beginners. I'm noticing a lot getting really stuck too, especially in the beginning. Info is pretty much scattered as well. I guess I'll leave...

Comment by finch1 on 2018-01-05:
... this as is, in case it helps the next one.

Comment by PeteBlackerThe3rd on 2018-01-05:
no problem, glad it helped. if you can accept this answer then it will help other people who might have the same questions later. Thanks.

Comment by finch1 on 2018-01-05:
Thanks for the reminder, and thanks again for the explanation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.