Replies: 1 comment
|
You're right that removing Your node does all its work in Rule of thumb: Here's a corrected version that keeps the one-shot structure and cleans up properly: import rclpy
from rclpy.node import Node
import os
class EnvironmentChecker(Node):
def __init__(self):
super().__init__('environment_checker')
# Read ROS_DISTRO from the actual environment, with the parameter as a fallback
self.declare_parameter('ros_distro', 'humble')
param_distro = self.get_parameter('ros_distro').value
env_distro = os.environ.get('ROS_DISTRO', param_distro)
self.get_logger().info(f"ros_distro: {env_distro}")
# Verify workspace sourcing via AMENT_PREFIX_PATH
ament_prefix = os.environ.get('AMENT_PREFIX_PATH')
if ament_prefix:
self.get_logger().info("Workspace appears to be sourced.")
else:
self.get_logger().warn("AMENT_PREFIX_PATH not set — workspace may not be sourced.")
def main(args=None):
rclpy.init(args=args)
node = EnvironmentChecker()
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()Two things worth noting beyond the spin issue:
If the grader wants the parameter name and value printed in a specific format, keep the log line matching what it expects ( |
Uh oh!
There was an error while loading. Please reload this page.
How do you correctly solve this problem
my solution to the problem was
import rclpy from rclpy.node import Node import os class EnvironmentChecker(Node): def __init__(self): super().__init__('environment_checker') # TODO: Check for ROS_DISTRO environment variable self.declare_parameter('ros_distro','humble') # TODO: Log ROS2 distribution name ros_distro=self.get_parameter('ros_distro') self.get_logger().info(f"{ros_distro.name}:{ros_distro.value}") # TODO: Verify workspace sourcing # pass def main(args=None): rclpy.init(args=args) node = EnvironmentChecker() rclpy.spin(node) node.destroy_node() rclpy.shutdown() if __name__ == '__main__': main()but it gave error :
to solve this eeror
i simply removed the spin node line
and then it worked.
But something feels off. I am complete newbie therefore would like to learn the correct way
All reactions