ROS 프로그래밍 2

Jaewon·2021년 6월 4일
0

ROS

목록 보기
8/9
post-custom-banner

param 이용

pub-sub-param.launch

<launch>
	<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node" /> 
	<node pkg="my_pkg1" type="pub-param.py" name="pub_node" > 
		<param name="circle_size" value="2" />
	</node>
	<node pkg="my_pkg1" type="sub.py" name="sub_node" output="screen" /> 
</launch>

==> circle_size = 2

pub-param.py

#!/usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

rospy.init_node('my_node', anonymous=True)
pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)

msg = Twist()
#msg.linear.x = 2.0
linear_X=rospy.get_param('~circle_size')
msg.linear.x = linear_X
msg.linear.y = 0.0
msg.linear.z = 0.0
msg.angular.x = 0.0
msg.angular.y = 0.0
msg.angular.z = 1.8

rate = rospy.Rate(1)

while not rospy.is_shutdown():
    pub.publish(msg)
    rate.sleep()

==> param 이용할 때는 '~'으로 사용하기

실행

roslaunch my_pkg1 pub-sub-param.launch

param 변경, pub-sub-param.launch

<launch>
	<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node" /> 
	<node pkg="my_pkg1" type="pub-param.py" name="pub_node" > 
		<param name="circle_size" value="4" />
	</node>
	<node pkg="my_pkg1" type="sub.py" name="sub_node" output="screen" /> 
</launch>

==> circle_size = 4

post-custom-banner

0개의 댓글