ENPM702 Robot Programming: ROS Part 2
48 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the main purpose of spinning a node in ROS?

  • To keep the node responsive and operational (correct)
  • To store data permanently
  • To create a graphical interface
  • To execute background processes only
  • Which programming paradigm is emphasized for writing nodes in the context of more complex structures and functionalities?

  • Procedural Programming
  • Functional Programming
  • Object-Oriented Programming (correct)
  • Logic Programming
  • What does the term 'callback' refer to in ROS?

  • An error handling mechanism
  • A type of data serialization
  • A method to store information temporarily
  • A function that is called in response to an event (correct)
  • What is a key benefit of using a wall timer in ROS?

    <p>To schedule and control task execution</p> Signup and view all the answers

    Which of the following is NOT a learning objective for this lecture on ROS?

    <p>Creating a robot visualization</p> Signup and view all the answers

    What is meant by the term 'node' in the context of ROS?

    <p>A software process that performs computations</p> Signup and view all the answers

    Which programming principle is essential for managing complex structures within ROS nodes?

    <p>Encapsulation</p> Signup and view all the answers

    How can ROS nodes be made more interactive?

    <p>By using message passing and services</p> Signup and view all the answers

    What happens when Ctrl + C is pressed while a node is running?

    <p>A signal is sent to gracefully shut down the node.</p> Signup and view all the answers

    Which function is responsible for keeping the node alive until termination?

    <p>rclcpp::spin()</p> Signup and view all the answers

    What function is called to ensure a clean shutdown of nodes when Ctrl + C is detected?

    <p>rclcpp::shutdown()</p> Signup and view all the answers

    What is a potential consequence of not properly shutting down a ROS 2 node?

    <p>Resource leaks may occur.</p> Signup and view all the answers

    What is the first step when spinning a node in ROS 2?

    <p>Use rclcpp::spin()</p> Signup and view all the answers

    What role does rclcpp::init() play in relation to signal handling?

    <p>It sets up a handler for SIGINT.</p> Signup and view all the answers

    When using an object-oriented programming (OOP) approach to write a node, which functionality is enhanced?

    <p>Data publishing and reception.</p> Signup and view all the answers

    Which command is used to compile the node after implementing it in ROS 2?

    <p>colcon build --packages-select first_package</p> Signup and view all the answers

    What is the purpose of the rcutils logging system in ROS 2?

    <p>To output messages with various severity levels.</p> Signup and view all the answers

    Which macro would you use to log a fatal error message in ROS 2?

    <p>RCLCPP_FATAL</p> Signup and view all the answers

    What is the correct command to build the package in ROS 2 after editing CMakeLists.txt?

    <p>colcon build --packages-select first_package</p> Signup and view all the answers

    What does 'spinning a node' refer to in ROS 2?

    <p>Keeping the node actively running to respond to events.</p> Signup and view all the answers

    Which of the following is NOT a severity level provided by the ROS 2 logging system?

    <p>NOTICE</p> Signup and view all the answers

    What command is used to run the hello node from the first_package in ROS 2?

    <p>ros2 run first_package hello</p> Signup and view all the answers

    What script is generated to set up the environment in ROS 2 after building a package?

    <p>setup.bash</p> Signup and view all the answers

    Which line is crucial for including the logging functionality in a ROS 2 source file?

    <p>#include &lt;rcutils/logging.h&gt;</p> Signup and view all the answers

    What is the purpose of the FirstNode class in the code?

    <p>To create a node that can log messages.</p> Signup and view all the answers

    Which command initiates the building of the package in the provided instructions?

    <p>colcon build --packages-select first_package</p> Signup and view all the answers

    In which file should you instantiate the FirstNode class?

    <p>main.cpp</p> Signup and view all the answers

    What modification is needed in CMakeLists.txt to include the path for header files?

    <p>include_directories(include)</p> Signup and view all the answers

    What does the RCLCPP_INFO_STREAM function do in the FirstNode constructor?

    <p>It confirms node initialization with a message.</p> Signup and view all the answers

    Which command do you run to execute the node after it is built?

    <p>ros2 run first_package hello</p> Signup and view all the answers

    What is the significance of using std::make_shared when creating the FirstNode instance?

    <p>It ensures memory is automatically managed.</p> Signup and view all the answers

    What is the role of the ament_target_dependencies directive in the build process?

    <p>To link the executable with required dependencies.</p> Signup and view all the answers

    What type of wheels does the Turtlebot use for movement?

    <p>Differentially driven wheels</p> Signup and view all the answers

    How is translational velocity expressed for the Turtlebot?

    <p>In meters per second</p> Signup and view all the answers

    Which command is used to install required packages for the Turtlebot?

    <p>sudo apt install 'ros--turtlebot3*'</p> Signup and view all the answers

    Which line should be added to the configuration file to set the Turtlebot model to 'waffle'?

    <p>export TURTLEBOT3_MODEL=waffle</p> Signup and view all the answers

    What command is needed to spawn the Turtlebot in RViz?

    <p>ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py</p> Signup and view all the answers

    Which of the following commands is used to install a package on the Turtlebot?

    <p>sudo apt install ros--turtlebot3-*</p> Signup and view all the answers

    What type of messages must be sent to control the Turtlebot's movement?

    <p>geometry_msgs/msg/Twist</p> Signup and view all the answers

    What does a positive angular velocity on the z axis do to the Turtlebot?

    <p>Rotates it counterclockwise</p> Signup and view all the answers

    What is the purpose of a callback function in programming?

    <p>To provide behavior that can be defined by the user during function execution.</p> Signup and view all the answers

    What command is used to visualize messages published on the topic '/cmd_vel'?

    <p>ros2 interface show</p> Signup and view all the answers

    What is a function pointer in programming?

    <p>A reference to a function that can be used to call the function indirectly.</p> Signup and view all the answers

    When moving the Turtlebot around with the keyboard, which command should be used to launch the Turtlebot?

    <p>ros2 run turtlebot3_fake_node turtlebot3_fake_node.launch.py</p> Signup and view all the answers

    What occurs when you dereference a function pointer?

    <p>You execute the function directly with given arguments.</p> Signup and view all the answers

    Which of the following statements about the function prototype 'return_type (*pointer_name)(parameter_type_1, parameter_type_2,...);' is true?

    <p>It declares a function pointer with specified parameter types.</p> Signup and view all the answers

    What is a potential issue when rendering in RViz for the Turtlebot?

    <p>Known issues in rendering performance.</p> Signup and view all the answers

    What happens when you use the command 'ros2 run turtlebot3_teleop teleop_keyboard'?

    <p>It starts teleoperation to control the robot's movement with the keyboard.</p> Signup and view all the answers

    Study Notes

    Course Information

    • Course: ENPM702, Introductory Robot Programming
    • Topic: 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
      • Question
      • Node
      • Topic
      • Message
    • Syntax
    • Important Notes
    • Best Practices
    • 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 of spinning a node to keep it responsive and operational
    • Writing a Node with OOP: Implement nodes using object-oriented programming principles to handle complex structures and functionalities
    • Publishers: Understand publishers in ROS 2 to create and transmit data through topics
    • Messages and Topics: Gain knowledge about message structures, and data transmission through topics
    • Write a Publisher: Learn to write and implement a publisher in ROS 2 to control robot actions, including publishing specific data types (e.g., geometry_msgs/msg/Twist)

    Node

    • Part I: Nodes
    • A node is a small program (e.g., written in C++) that executes simple tasks or processes.
    • Nodes can publish data, receive data, or do both

    Node - Write a Node

    • Create hello node within first_package to print "Hello" in the terminal
    • Build the executable using CMakeLists.txt
    • Instructions provided for building and installing executable

    Node - ROS Logging

    • ROS 2 logging is handled by the rcutils logging system
    • To output different severity levels, use macros (DEBUG, INFO, WARN, ERROR, and FATAL) to the console

    Node - Spinning a Node

    • Spinning keeps a node running enabling response to events and callbacks
    • rclcpp::spin blocks execution until shutdown or external signal (e.g., Ctrl+C)
    • ROS 2 sets up a SIGINT handler for graceful shutdown

    Node - Write a Node with OOP

    • Complex nodes benefit from Object-Oriented Programming (OOP) approach with attributes and methods
    • Create first_node class and FIRST_NODE instantiation details provided

    Turtlebot

    • Part II: Turtlebot
    • A differential wheeled robot; movement controlled by two separately driven wheels.
    • Resources: Explore the origin of Turtlebot and the term "Turtle" in robotics

    Turtlebot - Velocity

    • Translational velocity (v): Forward (-v backward) movement
    • Angular velocity (w): Counter-clockwise (+w) or clockwise(-w) rotation

    Turtlebot - Packages

    • Install required packages (ros-<distro>-turtlebot3*)
    • Set TURTLEBOT3_MODEL=(burger, waffle, waffle_pi) in .bashrc or .zshrc

    Turtlebot - Spawn

    • Spawn the Turtlebot in RViz
    • Use ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py
    • Spawn in Gazebo using appropriate launch file
    • Optionally start RViz

    Turtlebot - Teleoperation

    • Spawn the Turtlebot in RViz using ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py.
    • Move the robot using keyboard using ros2 run turtlebot3_teleop teleop_keyboard.
    • Visualize messages published on /cmd_vel.

    Callbacks

    • Part III: Callbacks
    • A callback function g is a function passed as an argument to another function f.
    • Callbacks provide flexibility in handling events and asynchronous processing
    • Callables - any entity that can be called with parentheses

    Callbacks - std::function

    • std::function is a polymorphic function wrapper.
    • It allows stores and calls arbitrary callable objects with a specific signature

    Callbacks - Function Pointers

    • A function pointer holds the function's address.
    • It's used to call functions indirectly.

    Callbacks - Functors

    • A functor, or function object, is any callable object treated like a function.
    • Created by overloading the operator()

    Callbacks - Lambda Expressions

    • Anonymous callable entities defined inline.
    • Ideal for short-lived, single-use operations.

    ROS Scheduling

    • Part IV: ROS Scheduling
    • Manages timing and execution of tasks and callbacks within nodes.
    • Critical for applications needing regular updates (sensor data, control loops, logging)

    ROS Scheduling - create_wall_timer

    • ROS scheduling tool using the system clock (not ROS specific time)
    • Triggers a callback at a specified time interval

    ROS Scheduling - Exercise #2

    • Modify first_package to log "Hello, world: " every 500ms to the terminal.
    • Increment counter with each iteration.

    ROS Scheduling - Exercise #3

    • Modify previous code
    • Use 500ms time delay instead of std::chrono::milliseconds(500).
    • Allow choosing the initial counter value different from 0.

    Next Lecture

    • Lecture 11: ROS (Part 3)
    • Quiz on ROS

    Appendix A

    • Examples of higher-order functions from the standard library.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    ENPM702 L10: ROS (Part 2) PDF

    Description

    Test your knowledge on the second part of the ROS (Robot Operating System) course. This quiz covers essential topics such as writing nodes, callbacks, and teleoperation for Turtlebot robots. Perfect for students looking to solidify their understanding of ROS 2 and its applications.

    More Like This

    ROS Technology Quiz
    5 questions

    ROS Technology Quiz

    AmazingGyrolite6890 avatar
    AmazingGyrolite6890
    ROS: Architecture, History, and Usage
    10 questions

    ROS: Architecture, History, and Usage

    UnforgettableIntelligence avatar
    UnforgettableIntelligence
    Ageing Mechanisms (2)
    10 questions

    Ageing Mechanisms (2)

    HearteningEnglishHorn avatar
    HearteningEnglishHorn
    General ROS Overview for Medical Students
    16 questions
    Use Quizgecko on...
    Browser
    Browser