Ask Your Question
0

Beginner Tutorial Procedure [closed]

asked 2018-01-05 08:41:02 -0600

finch1 gravatar image

updated 2018-01-05 12:26:51 -0600

jayess gravatar image

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 <ros/ros.h>

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

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see http://wiki.ros.org/Support for more details. by finch1
close date 2018-01-05 09:51:17.529327

Comments

This is not a question. I'm confused, what do you want help with?

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-01-05 09:01:36 -0600 )edit

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.

finch1 gravatar imagefinch1 ( 2018-01-05 09:37:22 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-01-05 10:53:15 -0600

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.

edit flag offensive delete link more

Comments

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...

finch1 gravatar imagefinch1 ( 2018-01-05 11:00:41 -0600 )edit

... this as is, in case it helps the next one.

finch1 gravatar imagefinch1 ( 2018-01-05 11:00:59 -0600 )edit

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.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2018-01-05 11:07:01 -0600 )edit

Thanks for the reminder, and thanks again for the explanation.

finch1 gravatar imagefinch1 ( 2018-01-05 11:21:29 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-01-05 08:41:02 -0600

Seen: 117 times

Last updated: Jan 05 '18