Hello,
I'm new to ROS2 but have previously worked with ROS Kinetic. I have built ROS2 Foxy on 64-bit Windows 10 and currently going through tutorials in Tutorial: Using parameters in a class (Python), which involves declaring a parameter and then changing it dynamically via terminal and launch file. The node runs fine with ros2 run python_parameters param_talker
and I can change the parameter in a terminal, but when re-parametering through a launch file, it seems to completely stall and won't output anything via self.get_logger().info()
. That is, until I hit Ctrl+C
, at which point the node spins once with the new parameter before termination.
Output:
C:\dev_ws>ros2 launch python_parameters python_parameters_launch.py
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [param_talker.EXE-1]: process started with pid [3264]
[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[ERROR] [param_talker.EXE-1]: process has died [pid 3264, exit code 3221225786, cmd 'C:\dev_ws\install\lib\python_parameters\param_talker.EXE --ros-args -r __node:=custom_parameter_node --params-file C:\Users\h25902\AppData\Local\Temp\launch_params_c0x3kned'].
[param_talker.EXE-1] [INFO] [1600066038.332151500] [custom_parameter_node]: Hello earth!
Node (\dev_ws\src\python_parameters\python_parameters\python_parameters_node.py
):
import rclpy
import rclpy.node
from rclpy.exceptions import ParameterNotDeclaredException
from rcl_interfaces.msg import ParameterType
class MinimalParam(rclpy.node.Node):
def __init__(self):
super().__init__('minimal_param_node')
timer_period = 2 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.declare_parameter("my_parameter")
def timer_callback(self):
# First get the value parameter "my_parameter" and get its string value
my_param = self.get_parameter("my_parameter").get_parameter_value().string_value
# Send back a hello with the name
self.get_logger().info('Hello %s!' % my_param)
# Then set the parameter "my_parameter" back to string value "world"
my_new_param = rclpy.parameter.Parameter(
"my_parameter",
rclpy.Parameter.Type.STRING,
"world"
)
all_new_parameters = [my_new_param]
self.set_parameters(all_new_parameters)
def main():
rclpy.init()
node = MinimalParam()
rclpy.spin(node)
if __name__ == '__main__':
main()
Setup.py (\dev_ws\src\python_parameters\setup.py
):
from setuptools import setup
import os
from glob import glob
package_name = 'python_parameters'
setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name), glob('launch/*_launch.py'))
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='Todo Todo',
maintainer_email='[email protected]',
description='Python parameter tutorials',
license='TODO: LICENSE DECLARATION',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'param_talker = python_parameters.python_parameters_node:main',
],
},
)
Launch file (\dev_ws\src\python_parameters\launch\python_parameters_launch.py
):
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package="python_parameters",
executable="param_talker",
name="custom_parameter_node",
output="screen",
emulate_tty=True,
parameters=[
{"my_parameter": "earth"}
]
)
])
Does anybody have previous experiences/any reason what's causing this? I tried the C++ version of the tutorial (which works fine), but I'd prefer using Python with ROS2 later on.
Thank you in advance!
EDIT: This appears to be the case for all launch files created in a Python package. Any thoughts?
Originally posted by SSar on ROS Answers with karma: 53 on 2020-09-14
Post score: 0