ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 11 week HW (2) Parameter programming
    ROS2 Study 2021. 11. 16. 12:59
    728x90
    반응형

    review

    https://needs-searcher.tistory.com/181

     

    6 week HW Parameter control using turtlesim node

    Experiment of ROS2 parameter, RQt, and ROS2 package installation 1. parameter 2. ROS2 tools - Command Line Tools https://github.com/ubuntu-robotics/ros2_cheats_sheet/blob/master/cli/cli_cheats_shee..

    needs-searcher.tistory.com

     

     

    command list

    see a list of parma

    $ ros2 param list

     

    get value of a param

    $ ros2 param get <node_name> <parameter_name>

     

    set value

    $ ros2 param set <node_name> <parameter_name> <value>

     

     

    1. make a package

    $ ros2 pkg create python_parameters --build-type ament_python --dependencies rclpy

     

    2. write code

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    import rclpy
    from rclpy.node import Node
    from rclpy.exceptions import ParameterNotDeclaredException
     
    class MinimalParam(Node):
        def __init__(self):
            super().__init__('minimal_param_node')
            timer_period = 2 # every 2 sec
     
            # to call callback func at custum hertz
            self.timer = self.create_timer(timer_period, self.timer_callback)
     
            self.declare_parameter('my_parameter''world'# param name, param value
     
        def timer_callback(self):
            # first, get param from the node and assign value to my_param
            my_param = self.get_parameter('my_parameter').get_parameter_value().string_value
     
            self.get_logger().info('Hello %s!' % my_param)
     
    def main():
        rclpy.init()
        node = MinimalParam()
     
        try:
            rclpy.spin(node)
        except KeyboardInterrupt:
            node.get_logger().info('This node is finished by keboard interrupt')
        finally:
            node.destroy_node()
            rclpy.shutdown()
     
    if __name__ == '__main__':
        main()
    cs

     

     

    3. revise package.xml file

    4. revise the setup.py file

    ** entry_point**

     

    note that the node's executable name is 'param_talker'

     

    5. build and run

    6. check the created parameter

     

    see a list of parma

    $ ros2 param list

    get value of a param

    $ ros2 param get <node_name> <parameter_name>

    set value

    $ ros2 param set <node_name> <parameter_name> <value>

     

    7. Add a parameter

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    import rclpy
    from rclpy.node import Node
    from rclpy.exceptions import ParameterNotDeclaredException
     
    class MinimalParam(Node):
        def __init__(self):
            super().__init__('minimal_param_node')
            timer_period = 2
     
            # to call callback func at custum hertz
            self.timer = self.create_timer(timer_period, self.timer_callback)
     
            self.declare_parameter('my_parameter''world'# param name, param value
            self.declare_parameter('num_parameter'1# another param
     
        def timer_callback(self):
            # first, get param from the node and assign value to my_param
            my_param = self.get_parameter('my_parameter').get_parameter_value().string_value
            num_param = self.get_parameter('num_parameter').get_parameter_value().integer_value
     
            self.get_logger().info('Hello %s!, Num: %d,' % (my_param, num_param))
     
    def main():
        rclpy.init()
        node = MinimalParam()
     
        try:
            rclpy.spin(node)
        except KeyboardInterrupt:
            node.get_logger().info('This node is finished by keboard interrupt')
        finally:
            node.destroy_node()
            rclpy.shutdown()
     
    if __name__ == '__main__':
        main()
    cs

     

    add two lines

    self.declare_parameter('num_parameter'1

    self.get_logger().info('Hello %s!, Num: %d,' % (my_param, num_param))

     

    8. test

    9. check in rqt and revise the param value

    at rqt - Plugins-Configuration-Dynamic reconfigure

     

     

    728x90
    반응형

    댓글 0

Designed by Tistory.