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?
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?
What is the purpose of a callback in a ROS Node?
What is the purpose of a callback in a ROS Node?
What does the term 'create_wall_timer' in ROS refer to?
What does the term 'create_wall_timer' in ROS refer to?
Signup and view all the answers
Which option best describes a Node in the context of ROS?
Which option best describes a Node in the context of ROS?
Signup and view all the answers
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?
Signup and view all the answers
In ROS, which component primarily enables nodes to send and receive messages?
In ROS, which component primarily enables nodes to send and receive messages?
Signup and view all the answers
What does the schedule function in ROS primarily help to achieve?
What does the schedule function in ROS primarily help to achieve?
Signup and view all the answers
What is the purpose of the class FirstNode in the given code?
What is the purpose of the class FirstNode in the given code?
Signup and view all the answers
What method is called to initialize the ROS2 environment in main.cpp?
What method is called to initialize the ROS2 environment in main.cpp?
Signup and view all the answers
What does the RCLCPP_INFO_STREAM() function do in the FirstNode constructor?
What does the RCLCPP_INFO_STREAM() function do in the FirstNode constructor?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
Which command is used to build a ROS 2 package?
Which command is used to build a ROS 2 package?
Signup and view all the answers
In CMakeLists.txt, what does 'include_directories(include)' specify?
In CMakeLists.txt, what does 'include_directories(include)' specify?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
Which statement about the current FirstNode class is true?
Which statement about the current FirstNode class is true?
Signup and view all the answers
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?
Signup and view all the answers
What does 'spinning a node' refer to in ROS 2?
What does 'spinning a node' refer to in ROS 2?
Signup and view all the answers
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?
Signup and view all the answers
Which severity level in logging would be appropriate for general informational messages?
Which severity level in logging would be appropriate for general informational messages?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What is the primary role of a node in ROS 2?
What is the primary role of a node in ROS 2?
Signup and view all the answers
What is the purpose of the rclcpp::init(argc, argv)
function?
What is the purpose of the rclcpp::init(argc, argv)
function?
Signup and view all the answers
What happens when rclcpp::spin() is called in a ROS 2 node?
What happens when rclcpp::spin() is called in a ROS 2 node?
Signup and view all the answers
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?
Signup and view all the answers
What does the statement RCLCPP_INFO_STREAM(node->get_logger(), 'Hello');
achieve?
What does the statement RCLCPP_INFO_STREAM(node->get_logger(), 'Hello');
achieve?
Signup and view all the answers
What signal is handled when Ctrl + C is pressed?
What signal is handled when Ctrl + C is pressed?
Signup and view all the answers
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?
Signup and view all the answers
What is the significance of the rclcpp::shutdown()
function?
What is the significance of the rclcpp::shutdown()
function?
Signup and view all the answers
Which of the following statements about publishers in ROS 2 is true?
Which of the following statements about publishers in ROS 2 is true?
Signup and view all the answers
What is the main purpose of calling rclcpp::shutdown()?
What is the main purpose of calling rclcpp::shutdown()?
Signup and view all the answers
Which command compiles a specific ROS 2 package?
Which command compiles a specific ROS 2 package?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
What is a callback function used for in programming?
What is a callback function used for in programming?
Signup and view all the answers
What command is used to visualize messages published to /cmd_vel?
What command is used to visualize messages published to /cmd_vel?
Signup and view all the answers
What is the primary purpose of a function pointer?
What is the primary purpose of a function pointer?
Signup and view all the answers
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'?
Signup and view all the answers
What issue might be encountered when spawning the Turtlebot in RViz?
What issue might be encountered when spawning the Turtlebot in RViz?
Signup and view all the answers
Which function is used to move the robot around using the keyboard?
Which function is used to move the robot around using the keyboard?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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.