Skip to content

shr-eyas/ROS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

A personal guide to refer while working on ROS Noetic and ROS2 Humble

ROS Humble

Note

For Auto Completion

cd /usr/share/colcon_argcomplete/hook
add "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" in gedit ~/.bashrc

A. Create a ROS Workspace

  1. Create a new workspace:
    mkdir -p workspace_name/src
    cd workspace_name

Important

Next two steps to be done from the root of your workspace

  1. Resolve dependencies:

    cd ..
    rosdep install -i --from-path src --rosdistro humble -y
  2. Build the workspace with colcon:

    colcon build

B. Create a ROS Package

ROS Noetic

A. Manage your Environment

First, source the ROS Noetic environment setup file. It's recommended to add this to your .bashrc file for automatic sourcing:

echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

Tip

Alternatively, you can choose to run this command on every new shell you open to have access to the ROS commands. This process allows you to install several ROS distributions (e.g. indigo and kinetic) on the same computer and switch between them.

source /opt/ros/kinetic/setup.bash

B. Create a ROS Workspace

  1. Create a new workspace:

    mkdir -p workspace_name/src
    cd workspace_name
    catkin_make
  2. Source the workspace setup file:

    source devel/setup.bash

C. Create a ROS Package

  1. Navigate to the src directory within your workspace:

    cd src
  2. Create a new package:

    catkin_create_pkg package_name std_msgs rospy roscpp
  3. Build the workspace:

    cd ..
    catkin_make
  4. Source the setup file again:

    source devel/setup.bash
  5. You can view first-order dependencies in package.xml:

    <build_depend>roscpp</build_depend>
    <build_depend>rospy</build_depend>
    <build_depend>std_msgs</build_depend>

Note

Your workspace structure should look like this:

 workspace_folder/        
   src/                  
     CMakeLists.txt      
     package_1/
       include
       src
       CMakeLists.txt    
       package.xml        
     ...
     package_n/
       include
       src
       CMakeLists.txt     
       package.xml       

D. Create a ROS Node

  1. Inside your package, create a scripts directory:

    cd src/package_name
    mkdir scripts
    cd scripts
  2. Create a new Python node:

    touch node_name.py
    chmod +x node_name.py
  3. Add additional dependencies to package.xml:

    <build_depend>opencv</build_depend>
    <build_depend>python3-numpy</build_depend>
    <build_export_depend>opencv</build_export_depend>
    <build_export_depend>python3-numpy</build_export_depend>
    <exec_depend>opencv</exec_depend>
    <exec_depend>python3-numpy</exec_depend>
  4. Modify CMakeLists.txt to install the Python node:

    catkin_package(
      CATKIN_DEPENDS roscpp rospy std_msgs
    )
    
    catkin_install_python(PROGRAMS
      scripts/node_name.py
      DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
  5. Go to the workspace and build it:

    cd ../../..
    catkin_make

E. Run ROS Node

  1. Make sure that a roscore is up and running:

    roscore
  2. Source the workspace's setup.sh file

    cd workspace_name
    source devel/setup.bash
  3. Run the node!

    rosrun package_name node_name.py 

Important

roscore is the first thing you should run when using ROS.

roscore

About

A personal guide to refer while working on ROS and ROS2, feel free to refer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published