Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ jobs:
run: |
source /opt/ros/jazzy/setup.bash
colcon build
typecheck:
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '22'
- name: pyright (example code is fully annotated)
run: npx --yes pyright -p ros2_tutorial_workspace
8 changes: 4 additions & 4 deletions docs/source/gazebo/custom_nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ name for :program:`Gazebo` to know which entity to set the pose. This name can b

.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
:language: python
:lines: 45-64
:lines: 46-65
:emphasize-lines: 7

The second possibly unfamiliar is the choice of ``rclpy.spin_until_future_complete`` to illustrate calling the service
client only once.

.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
:language: python
:lines: 67-82
:lines: 68-83
:emphasize-lines: 11

.. admonition:: Exercises
Expand Down Expand Up @@ -393,15 +393,15 @@ There is also a simple proportional controller in one dimension.

.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
:language: python
:lines: 68-71
:lines: 68-72

Lastly, in the ``timer_callback``, we use the current coordinate value to compute the control action and send it to
:program:`Gazebo`.

.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
:language: python
:emphasize-lines: 11,13
:lines: 93-114
:lines: 94-115

.. admonition:: Exercises

Expand Down
17 changes: 17 additions & 0 deletions ros2_tutorial_workspace/pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"include": [
"src"
],
"exclude": [
"**/test/**",
"**/build/**",
"**/install/**",
"**/log/**",
"**/resource/**"
],
"reportMissingImports": "none",
"reportMissingModuleSource": "none",
"reportMissingParameterType": "error",
"pythonVersion": "3.12",
"stubPath": "stubs"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from launch_ros.actions import Node


def generate_launch_description():
def generate_launch_description() -> LaunchDescription:

this_package_share_directory = get_package_share_directory('python_package_that_uses_gazebo')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from launch_ros.actions import Node


def generate_launch_description():
def generate_launch_description() -> LaunchDescription:

node = Node(
output='screen',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from launch_ros.actions import Node


def generate_launch_description():
def generate_launch_description() -> LaunchDescription:

node = Node(
output='screen',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ControlShapeThrustNode(Node):
"""A ROS2 Node that controls the thrust of a shape in Gazebo.
It will apply force based on the position of an entity."""

def __init__(self):
def __init__(self) -> None:
super().__init__('control_shape_thurst_node')

# Structured easily to be changed into configurable parameters
Expand Down Expand Up @@ -65,7 +65,8 @@ def __init__(self):
self.timer_period: float = 0.001
self.timer = self.create_timer(self.timer_period, self.timer_callback)

def compute_control_action(self, current, target, proportional_gain:float = 5.0) -> float:
def compute_control_action(self, current: float, target: float,
proportional_gain: float = 5.0) -> float:
"""A simple proportional controller"""
error = current - target
return -proportional_gain * error
Expand All @@ -90,7 +91,7 @@ def send_force_to_gazebo(self, force: tuple[float, float, float] = (0, 0, 0)) ->

self.wrench_publisher.publish(ew)

def timer_callback(self):
def timer_callback(self) -> None:
"""The timer callback will look up the transforms and send the next control action."""

try:
Expand All @@ -114,7 +115,7 @@ def timer_callback(self):
f'Could not get transform from `{self.parent_name}` to `{self.child_name}`: {e}')


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
import rclpy
from rclpy.node import Node
from rclpy.executors import ExternalShutdownException
from rclpy.task import Future

class SendPosesToGazeboNode(Node):
"""A ROS2 Node that sends poses to Gazebo"""

def __init__(self):
def __init__(self) -> None:
super().__init__('send_poses_to_gazebo_node')

self.service_client = self.create_client(
Expand All @@ -42,7 +43,7 @@ def __init__(self):
self.get_logger().info(f'service {self.service_client.srv_name} not available, waiting...')


def send_pose_to_gazebo(self):
def send_pose_to_gazebo(self) -> Future[SetEntityPose.Response]:
"""Sample method sending a pose to and entity in Gazebo."""

request = SetEntityPose.Request()
Expand All @@ -64,7 +65,7 @@ def send_pose_to_gazebo(self):
return self.service_client.call_async(request)


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class SendWrenchesToGazeboNode(Node):
"""A ROS2 Node that sends wrenches to Gazebo."""

def __init__(self):
def __init__(self) -> None:
super().__init__('send_wrenches_to_gazebo_node')

self.publisher = self.create_publisher(
Expand All @@ -43,7 +43,7 @@ def __init__(self):
self.get_logger().info("Waiting for subscriber to be connected...")
time.sleep(1)

def send_wrench_to_gazebo(self):
def send_wrench_to_gazebo(self) -> None:
"""Basic method publishing wrenches to Gazebo."""

ew = EntityWrench()
Expand All @@ -70,7 +70,7 @@ def send_wrench_to_gazebo(self):
self.publisher.publish(ew)


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
class CreateStampedTransformsNode(Node):
"""A ROS2 Node that creates TransformStamped objects."""

def __init__(self):
def __init__(self) -> None:
super().__init__('create_stamped_transforms_node')

def create_and_print_stamped_transform(self):
def create_and_print_stamped_transform(self) -> None:
"""Basic method showing the creation of TransformStamped objects."""

tfs = TransformStamped()
Expand Down Expand Up @@ -62,7 +62,7 @@ def create_and_print_stamped_transform(self):
f"and rotation:"
f" {tfs.transform.rotation}.")

def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class Nav2InitialPosePublisherNode(Node):
"""A ROS2 Node that publishes the initial pose for nav2."""

def __init__(self):
def __init__(self) -> None:
super().__init__('nav2_initial_pose_publisher_node')

self._topic = '/initialpose'
Expand All @@ -48,7 +48,7 @@ def __init__(self):
self.get_logger().info(f"Publisher count is {publisher_count}.")
time.sleep(1)

def send_initial_pose_with_covariance(self):
def send_initial_pose_with_covariance(self) -> None:
"""Method to create the PoseWithCovarianceStamped."""

self.get_logger().info(f"Publishing pose to topic: {self._topic}.")
Expand All @@ -72,7 +72,7 @@ def send_initial_pose_with_covariance(self):

self.publisher.publish(pwcs)

def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
class Nav2NavigateToPoseActionClient(Node):
"""A ROS2 Node with an Action Client for Nav2NavigateToPoseActionClient."""

def __init__(self):
def __init__(self) -> None:
super().__init__('nav2_navigate_to_pose_action_client')

self.action_client = ActionClient(self, NavigateToPose, '/navigate_to_pose')

self.send_goal_future = None # This will be used in `send_goal`
self.get_result_future = None # This will be used in 'goal_response_callback'
self.send_goal_future: Future # This will be used in `send_goal`
self.get_result_future: Future # This will be used in 'goal_response_callback'

def send_goal_async(self, desired_pose: Pose, behaviour_tree: str) -> None:
goal_msg = NavigateToPose.Goal()
Expand Down Expand Up @@ -77,7 +77,7 @@ def action_feedback_callback(self, feedback_msg: NavigateToPose.Feedback) -> Non
self.get_logger().info(f'Received feedback distance: {feedback.distance_remaining}.')


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from geometry_msgs.msg import Quaternion
import marinholab.nottf2 as ntf2

def main():
def main() -> None:
phi: float = pi

r1: Quaternion = ntf2.rx(phi=phi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from launch_ros.actions import Node


def generate_launch_description():
def generate_launch_description() -> LaunchDescription:
return LaunchDescription([
Node(
output='screen',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class AmazingQuoteConfigurablePublisherNode(Node):
"""A configurable ROS2 Node that publishes a configurable amazing quote."""

def __init__(self):
def __init__(self) -> None:
super().__init__('amazing_quote_configurable_publisher_node')

# Periodically-obtained parameters
Expand All @@ -52,7 +52,7 @@ def __init__(self):

self.incremental_id: int = 0

def timer_callback(self):
def timer_callback(self) -> None:
"""Method that is periodically called by the timer."""

quote: str = self.get_parameter('quote').get_parameter_value().string_value
Expand All @@ -68,7 +68,7 @@ def timer_callback(self):
self.incremental_id = self.incremental_id + 1


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class TF2BroadcasterNode(Node):
"""A ROS2 Node that broadcasts a TransformStamped in compliance with `tf2_ros2`."""

def __init__(self):
def __init__(self) -> None:
super().__init__('tf2_broadcaster_node')

# Robot name
Expand All @@ -47,7 +47,7 @@ def __init__(self):
self.timer_elapsed_time: float = 0
self.timer = self.create_timer(self.timer_period, self.timer_callback)

def timer_callback(self):
def timer_callback(self) -> None:
# We define some parameters of our trajectory.
# Let's make the translation be a circle in 2D with radius of 0.2 meters and frequency of 0.1 Hz.
# The rotation will be the robot spinning about the z-axis with the same frequency.
Expand Down Expand Up @@ -84,7 +84,7 @@ def timer_callback(self):
self.timer_elapsed_time += self.timer_period


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class TF2ListenerNode(Node):
"""A ROS2 Node that listens to the `tf` topic in compliance with `tf2_ros2`."""

def __init__(self):
def __init__(self) -> None:
super().__init__('tf2_listener_node')

# Setting up the TransformListener
Expand All @@ -44,7 +44,7 @@ def __init__(self):
self.timer_period: float = 0.1
self.timer = self.create_timer(self.timer_period, self.timer_callback)

def timer_callback(self):
def timer_callback(self) -> None:

try:
tfs = self.transform_listener_buffer.lookup_transform(
Expand All @@ -60,7 +60,7 @@ def timer_callback(self):
f'Could not get transform from `{self.parent_name}` to `{self.child_name}`: {e}')


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
class MoveStraightIn2DActionClientNode(Node):
"""A ROS2 Node with an Action Client for MoveStraightIn2D."""

def __init__(self):
def __init__(self) -> None:
super().__init__('move_straight_in_2d_action_client')

self.action_client = ActionClient(self, MoveStraightIn2D, '/move_straight_in_2d')

self.send_goal_future = None # This will be used in `send_goal`
self.get_result_future = None # This will be used in 'goal_response_callback'
self.send_goal_future: Future # This will be used in `send_goal`
self.get_result_future: Future # This will be used in 'goal_response_callback'

def send_goal_async(self, desired_position: Point) -> None:
goal_msg = MoveStraightIn2D.Goal()
Expand Down Expand Up @@ -74,7 +74,7 @@ def action_feedback_callback(self, feedback_msg: MoveStraightIn2D.Feedback) -> N
self.get_logger().info(f'Received feedback distance: {feedback.distance}.')


def main(args=None):
def main(args: list[str] | None = None) -> None:
"""
The main function.
:param args: Not used directly by the user, but used by ROS2 to configure certain aspects of the Node.
Expand Down
Loading
Loading