Skip to content

Instantly share code, notes, and snippets.

@MrVideo
Last active April 11, 2024 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrVideo/41aba5f7e0a2bf230e22e8c0b6df8095 to your computer and use it in GitHub Desktop.
Save MrVideo/41aba5f7e0a2bf230e22e8c0b6df8095 to your computer and use it in GitHub Desktop.
Robotics;Notes (Robotics 2024 @ PoliMi)

Notes on Robotics and ROS

The computation graph

The Computation Graph is the P2P network of ROS processes that are processing data together.

The executable units in ROS are called nodes. They are Python scripts or compiled C++ programs that perform some type of computation.

Nodes exchange information through the Computation Graph thanks to the master, which acts similarly to an event dispatcher in a publish-subscribe architecture.

Topics

ROS is based on a message-oriented middleware where channels are called topics.

Topics implement the publish-subscribe paradigm and provide no guarantee about the delivery of a sent message.

Topics can be set to have a specific message type.

Services

Services in ROS work like Remote Procedure Calls, which implement the client-server architecture.

Requests and responses in ROS services are implemented synchronously: the client waits for the server to complete the execution and to receive the result back before proceeding.

Parameter server

ROS's parameter server is a shared, multivariable dictionary accessible through the network. Nodes use it to store and retrieve parameters at runtime.

The ROS parameter server is connected to and accessed though the master.

Bags

ROS bags are files with the extension .bag made to store and play back messages. They are ROS's primary mechanism for data logging.

Bags can record anything that is exchanged through the Computation Graph.

roscore

roscore is a collection of nodes and programs that act as the foundations for a ROS-based system. It must be running for ROS nodes to be able to communicate.

roscore contains:

  • A ROS master
  • A ROS parameter server
  • A logging node called rosout

ROS commands

Command Description
roscore Starts the main ROS middleware: roscore
roscd package_name[/subdirectory] Change directory within the ROS file system
rospack command [options] [package] Returns information about installed packages
rosnode command Retrieves information about running nodes
rosrun package_name node_name Runs a specific node from a specific package
rostopic command topic_name Gets information about a specific topic
rosmsg command [message] Gets information about messages
rosservice command Calls a service
rosbag command Manages bags
rqt_graph Shows the running nodes and their publications/subscriptions as a graph
rqt_plot data Plots data published by nodes on topics

Catkin commands

Command Description
catkin_create_pkg package_name [dependencies] Creates a new ROS package
catkin_make Recompiles all packages (has to be run in the main Catkin workspace)

Setup to create a custom ROS package

  1. Run the command catkin_create_package in your workspace's src directory:
    catkin_create_package package_name [dependency1] [dependency2] [...]
    
  2. Create the executables in the package/src directory
  3. Create custom message types in the package/msg directory
  4. Create custom services in the package/srv directory
  5. Add the following lines to your CMakeLists.txt depending on what you added to your package:
    1. For every executable:
      add_executable(executable_name path/to/executable.cpp)
      target_link_libraries(executable_name ${catkin_LIBRARIES})
    2. When adding custom messages:
      add_message_files(
          FILES
          CustomMessage1.msg
          CustomMessage2.msg
      )
      
      generate_messages(
          DEPENDENCIES
          std_msgs
          custom_msg_dependency
      )
      
      catkin_package(
          CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
      )
      
      add_dependencies(executable_name executable_name_generate_messages_cpp)
    3. When adding custom services:
      add_service_files(
          FILES
          CustomService1.srv
          CustomService2.srv
      )
  6. Uncomment the following lines in your package.xml file when adding new message types:
    <build_depend>message_generation</build_depend>
    <exec_depend>message_runtime</exec_depend>
  7. Once everything is set up, run catkin_make in your catkin workspace to compile the package

Dynamic reconfigure

In order to dynamically reconfigure parameters, add this functionality to your node by following the tutorial here.

Then, when it's time to change some parameters, run:

rosrun dynamic_reconfigure dynparam set package_name parameter_name parameter_value

You can also make changes via a GUI:

rosrun rqt_reconfigure rqt_reconfigure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment