Podcast
Questions and Answers
What is a key aspect of spinning a Node in ROS?
What is a key aspect of spinning a Node in ROS?
- It allows the node to send messages to multiple topics
- It makes the node run in the background without interruptions
- It keeps the node responsive and operational (correct)
- It prevents resource conflicts with other nodes
Which programming paradigm is emphasized when writing a Node with OOP in ROS?
Which programming paradigm is emphasized when writing a Node with OOP in ROS?
- Object-oriented programming (correct)
- Event-driven programming
- Functional programming
- Procedural programming
What is the purpose of a callback in a ROS Node?
What is the purpose of a callback in a ROS Node?
- To schedule new tasks for the node
- To shut down the Node gracefully
- To handle incoming messages or events (correct)
- To initialize the Node
What does the term 'create_wall_timer' in ROS refer to?
What does the term 'create_wall_timer' in ROS refer to?
Which option best describes a Node in the context of ROS?
Which option best describes a Node in the context of ROS?
Why is it important to understand how to write a basic ROS Node?
Why is it important to understand how to write a basic ROS Node?
In ROS, which component primarily enables nodes to send and receive messages?
In ROS, which component primarily enables nodes to send and receive messages?
What does the schedule function in ROS primarily help to achieve?
What does the schedule function in ROS primarily help to achieve?
What is the purpose of the class FirstNode in the given code?
What is the purpose of the class FirstNode in the given code?
What method is called to initialize the ROS2 environment in main.cpp?
What method is called to initialize the ROS2 environment in main.cpp?
What does the RCLCPP_INFO_STREAM() function do in the FirstNode constructor?
What does the RCLCPP_INFO_STREAM() function do in the FirstNode constructor?
Which command is used to build and install the executable for the first_package?
Which command is used to build and install the executable for the first_package?
What is the primary purpose of the rcutils logging system in ROS 2?
What is the primary purpose of the rcutils logging system in ROS 2?
Which command is used to build a ROS 2 package?
Which command is used to build a ROS 2 package?
In CMakeLists.txt, what does 'include_directories(include)' specify?
In CMakeLists.txt, what does 'include_directories(include)' specify?
Which logging macro would you use to report a critical issue that must be addressed immediately?
Which logging macro would you use to report a critical issue that must be addressed immediately?
What is the purpose of the 'ament_target_dependencies()' function in CMakeLists.txt?
What is the purpose of the 'ament_target_dependencies()' function in CMakeLists.txt?
Which statement about the current FirstNode class is true?
Which statement about the current FirstNode class is true?
What is the effect of calling rclcpp::init(argc, argv)
in a ROS 2 program?
What is the effect of calling rclcpp::init(argc, argv)
in a ROS 2 program?
What does 'spinning a node' refer to in ROS 2?
What does 'spinning a node' refer to in ROS 2?
What would happen if you forget to call 'rclcpp::shutdown()' in main.cpp?
What would happen if you forget to call 'rclcpp::shutdown()' in main.cpp?
Which severity level in logging would be appropriate for general informational messages?
Which severity level in logging would be appropriate for general informational messages?
Which line in CMakeLists.txt correctly adds an executable for building in ROS 2?
Which line in CMakeLists.txt correctly adds an executable for building in ROS 2?
In a ROS 2 program, after editing CMakeLists.txt, what must you do next to complete the build?
In a ROS 2 program, after editing CMakeLists.txt, what must you do next to complete the build?
What is the primary role of a node in ROS 2?
What is the primary role of a node in ROS 2?
What is the purpose of the rclcpp::init(argc, argv)
function?
What is the purpose of the rclcpp::init(argc, argv)
function?
What happens when rclcpp::spin() is called in a ROS 2 node?
What happens when rclcpp::spin() is called in a ROS 2 node?
What command is used to run the node after it has been built?
What command is used to run the node after it has been built?
What does the statement RCLCPP_INFO_STREAM(node->get_logger(), 'Hello');
achieve?
What does the statement RCLCPP_INFO_STREAM(node->get_logger(), 'Hello');
achieve?
What signal is handled when Ctrl + C is pressed?
What signal is handled when Ctrl + C is pressed?
Which function is automatically called to perform cleanup when Ctrl + C is detected?
Which function is automatically called to perform cleanup when Ctrl + C is detected?
What is the significance of the rclcpp::shutdown()
function?
What is the significance of the rclcpp::shutdown()
function?
Which of the following statements about publishers in ROS 2 is true?
Which of the following statements about publishers in ROS 2 is true?
What is the main purpose of calling rclcpp::shutdown()?
What is the main purpose of calling rclcpp::shutdown()?
Which command compiles a specific ROS 2 package?
Which command compiles a specific ROS 2 package?
When writing a publisher in ROS 2, what kind of message structure is typically used?
When writing a publisher in ROS 2, what kind of message structure is typically used?
What is a crucial aspect of object-oriented programming (OOP) in developing complex ROS 2 nodes?
What is a crucial aspect of object-oriented programming (OOP) in developing complex ROS 2 nodes?
Which of the following steps is NOT part of the process to spin a node?
Which of the following steps is NOT part of the process to spin a node?
What does spinning a node with rclcpp::spin() achieve in a ROS 2 application?
What does spinning a node with rclcpp::spin() achieve in a ROS 2 application?
What is a callback function used for in programming?
What is a callback function used for in programming?
What command is used to visualize messages published to /cmd_vel?
What command is used to visualize messages published to /cmd_vel?
What is the primary purpose of a function pointer?
What is the primary purpose of a function pointer?
In the example provided, how is the function 'add' invoked through the pointer 'ptr'?
In the example provided, how is the function 'add' invoked through the pointer 'ptr'?
What issue might be encountered when spawning the Turtlebot in RViz?
What issue might be encountered when spawning the Turtlebot in RViz?
Which function is used to move the robot around using the keyboard?
Which function is used to move the robot around using the keyboard?
In the example provided, what will the line 'int result_direct = ptr(5, 10);' accomplish?
In the example provided, what will the line 'int result_direct = ptr(5, 10);' accomplish?
What type of argument is typically passed to a function in a callback?
What type of argument is typically passed to a function in a callback?
Flashcards
ROS 2 Node
ROS 2 Node
A ROS 2 component that performs a specific task and publishes/subscribes to ROS topics.
Spinning a Node
Spinning a Node
The process of keeping a ROS 2 node active and responsive to incoming messages and calls.
Object-Oriented Programming (in Nodes)
Object-Oriented Programming (in Nodes)
A way to structure nodes in ROS 2 using objects, improving organization and re-usability.
ROS Topic
ROS Topic
Signup and view all the flashcards
Callback
Callback
Signup and view all the flashcards
ROS Scheduler
ROS Scheduler
Signup and view all the flashcards
Node Creation
Node Creation
Signup and view all the flashcards
Node Functionality
Node Functionality
Signup and view all the flashcards
Publisher Node
Publisher Node
Signup and view all the flashcards
Subscriber Node
Subscriber Node
Signup and view all the flashcards
Message
Message
Signup and view all the flashcards
rclcpp::init()
rclcpp::init()
Signup and view all the flashcards
rclcpp::shutdown()
rclcpp::shutdown()
Signup and view all the flashcards
std::make_shared()
std::make_shared()
Signup and view all the flashcards
What does RCLCPP_INFO
do?
What does RCLCPP_INFO
do?
Signup and view all the flashcards
Why use logging in ROS?
Why use logging in ROS?
Signup and view all the flashcards
rclcpp::init(argc, argv)
rclcpp::init(argc, argv)
Signup and view all the flashcards
What is spinning a node?
What is spinning a node?
Signup and view all the flashcards
What's a callback function?
What's a callback function?
Signup and view all the flashcards
What's the purpose of ament_target_dependencies
?
What's the purpose of ament_target_dependencies
?
Signup and view all the flashcards
How do you run a node?
How do you run a node?
Signup and view all the flashcards
add_executable
in CMake
add_executable
in CMake
Signup and view all the flashcards
SIGINT (Signal Interrupt)
SIGINT (Signal Interrupt)
Signup and view all the flashcards
Node spinning stopped
Node spinning stopped
Signup and view all the flashcards
Resource release
Resource release
Signup and view all the flashcards
ROS 2 context shutdown
ROS 2 context shutdown
Signup and view all the flashcards
Object-Oriented Programming (OOP) for complex nodes
Object-Oriented Programming (OOP) for complex nodes
Signup and view all the flashcards
What is the purpose of 'include_directories(include)' in CMakeLists.txt?
What is the purpose of 'include_directories(include)' in CMakeLists.txt?
Signup and view all the flashcards
What is 'add_executable(hello src/main.cpp src/first_node.cpp)' in CMakeLists.txt doing?
What is 'add_executable(hello src/main.cpp src/first_node.cpp)' in CMakeLists.txt doing?
Signup and view all the flashcards
Why is 'ament_target_dependencies(hello rclcpp)' included in CMakeLists.txt?
Why is 'ament_target_dependencies(hello rclcpp)' included in CMakeLists.txt?
Signup and view all the flashcards
What is the purpose of 'install(TARGETS hello DESTINATION lib/${PROJECT_NAME})' in CMakeLists.txt?
What is the purpose of 'install(TARGETS hello DESTINATION lib/${PROJECT_NAME})' in CMakeLists.txt?
Signup and view all the flashcards
What is the role of 'rclcpp::init(argc, argv)' in main.cpp
?
What is the role of 'rclcpp::init(argc, argv)' in main.cpp
?
Signup and view all the flashcards
What does 'rclcpp::spin(node)' do?
What does 'rclcpp::spin(node)' do?
Signup and view all the flashcards
What is 'rclcpp::shutdown()' for?
What is 'rclcpp::shutdown()' for?
Signup and view all the flashcards
What is the purpose of 'std::make_shared()' in main.cpp
?
What is the purpose of 'std::make_shared()' in main.cpp
?
Signup and view all the flashcards
Teleoperation
Teleoperation
Signup and view all the flashcards
ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py
ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py
Signup and view all the flashcards
ros2 run turtlebot3_teleop teleop_keyboard
ros2 run turtlebot3_teleop teleop_keyboard
Signup and view all the flashcards
What is a Callback?
What is a Callback?
Signup and view all the flashcards
Function Pointer
Function Pointer
Signup and view all the flashcards
std::function in C++
std::function in C++
Signup and view all the flashcards
Callable in C++
Callable in C++
Signup and view all the flashcards
Study Notes
ENPM702: Introductory Robot Programming L10: ROS (Part 2)
- Course: ENPM702, Introductory Robot Programming
- Section: L10, ROS (Part 2)
- Version: 2.0
- Lecturer: Z. Kootbally
- School: University of Maryland
- Semester/Year: Fall 2024
- Date: 2024/11/12
Table of Contents
- Learning Objectives
- Node
- Writing a Node
- Spinning a Node
- Writing a Node with OOP
- Turtlebot
- Velocity
- Packages
- Spawn
- Teleoperation
- Callbacks
- Callables
- ROS Scheduling
- create_wall_timer
- Next Class
- Appendix A
Changelog
- v2.0: Added sections on callbacks and ROS scheduler.
- v1.0: Original version.
Convention
- General
- ROS
- File
- Folder
- Link
- Command
- Example
- Terminology
- Syntax
- Important notes
- Best practices
- Question
- Node
- Topic
- Message
- Warning
- Summary
- Tips
Learning Objectives
- Write a Node: Understand how to create a basic ROS 2 node and implement it in code.
- Spinning a Node: Learn the importance and process of spinning a node to keep it responsive and operational.
- Write a Node with OOP: Implement nodes using object-oriented programming principles to manage more complex structures and functionalities.
- Publishers: Understand the concept of publishers in ROS 2 and how to create them
- Messages and Topics: Gain knowledge about message structures and how data is transmitted through topics.
- Write a Publisher: Learn to write and implement a publisher in ROS 2 to control robot actions, including publishing specific data types like geometry_msgs/msg/Twist.
Node - Part I
- A node is a small program that executes a simple task or process.
- Nodes can publish data (publishers), receive data (subscribers), or do both (publishers/subscribers).
Node - Write a Node
- Create a node in
first_package/src/main.cpp
that prints "Hello" to the terminal. - Using CMakeLists.txt to build and install the executable.
cd ~/ros702_ws
colcon build --packages-select first_package
source ~/ros702_ws/install/setup.bash
- Run the code:
ros2 run first_package hello
Node - ROS Logging
- In ROS 2, logging is handled by the rcutils logging system.
- Include the rclcpp logging header in the source file.
- Use the rclcpp logging macros to log messages at different severity levels (DEBUG, INFO, WARN, ERROR, FATAL).
Node - Spinning a Node
- Spinning a node keeps it actively running to respond to events and execute callbacks.
- This is done using an execution loop,
rclcpp::spin()
. - When Ctrl+C is pressed, ROS gracefully shuts down nodes.
- Rclcpp handles signal interrupt (SIGINT).
rclcpp::shutdown()
is called automatically during graceful shutdown.
Node - Write a Node with OOP
- Complex nodes often require intricate structures and methods.
- OOP approach is useful.
- Create the class
FirstNode
infirst_package/include/
and implementation infirst_package/src/
. - Instantiate
FirstNode
infirst_package/src/main.cpp
.- Edit
CMakeLists.txt
to build. - Run
ros2 run first_package hello
.
- Edit
Turtlebot - Part II
- The Turtlebot is a differential wheeled robot.
- Movement depends on two separately driven wheels.
Turtlebot - Resources
- Read about the origin of the Turtlebot.
- Read about the origin of "turtle" in robotics.
Turtlebot - Velocity
- Translational velocity (+v for forward, -v for backward).
- Angular velocity (+w for counter-clockwise, -w for clockwise rotation).
Turtlebot - Packages
- Install packages needed:
sudo apt install 'ros-<distro>-turtlebot3*'
- Add one of these lines in
.bashrc
or.zshrc
, source it:export TURTLEBOT3_MODEL=burger
export TURTLEBOT3_MODEL=waffle
export TURTLEBOT3_MODEL=waffle_pi
Turtlebot - Spawn
- Spawn the robot in RViz:
ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py
. - Spawn in Gazebo:
ros2 launch turtlebot3_gazebo <launch file>
. - Optional: Start RViz.
ros2 launch turtlebot3_fake_node rviz2.launch.py
.
Turtlebot - Teleoperation
- Spawn Turtlebot in RViz.
- Move the robot around using keyboard.
ros2 run turtlebot3_teleop teleop_keyboard
.
- Visualize messages published on
/cmd_vel
. - Use
ros2 interface show
.
Callbacks - Part III
- A callback is a function passed to another function.
- Used for event handling and asynchronous processing.
Callables
- A callable is any entity that can be called with parentheses in C++.
std::function
std::function
is a general-purpose polymorphic function wrapper.- It stores callable targets and provides a unified interface.
- It uses type erasure to manage different callable types.
Callbacks - Types
- Function Pointers
- Functions
- Lambda functions
- Functors/Function Objects
Callbacks - Example
- Show an example of function pointer callback.
- Show an example for creating a callback using
std::function
. - Use examples with functors (function objects).
ROS Scheduling - Part IV
- Scheduling manages timing and execution of tasks/callbacks within ROS nodes.
ROS Scheduling - create_wall_timer
- Tool for creating wall timers in ROS 2.
create_wall_timer()
function generates a callback at a specified interval based on real-time (wall clock).- Example of using a wall timer to invoke a function at a specified interval.
Exercise #2
- Modify
first_package
to logHello, world: <n >
to the terminal every 500ms. - Increment
n
with each iteration.
Exercise #3
- Modify the previous code to use 500ms instead of a different duration.
- Start the counter with a chosen value instead of always starting at 0.
Next Lecture
- Lecture 11: ROS (Part 3).
- Quiz on ROS.
Appendix A
- Examples of higher-order functions from Standard Library.
std::sort
std::find_if
andstd::find_not
std::remove_if
std::erase_if
std::accumulate
std::all_of
,std::any_of
,std::none_of
std::for_each
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge on ROS programming as covered in Lecture 10 of the ENPM702 course. This quiz will cover topics such as writing nodes, spinning nodes, and callbacks within the Robot Operating System. Dive into the practical aspects of programming for robotics and assess your understanding of the course material.