ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

param error (KeyError)

asked 2022-05-24 06:49:56 -0500

qwertyup667 gravatar image

Hi everyone! I started learn ROS. I try to read data from launch file with param. bu I give an error and I did not understand why? Please help me constructor:

def__init__(self,nodeName,goalx,goaly):
   rospy.init_node("node", anonymous="True")
   self.goalX = rospy.get_param("x1")
   self.goalY = rospy.get_param("y1")
   self.pub = rospy.Publisher(nodeName + '/cmd_vel',Twist,queue_size=10)
   self.sub = rospy.Subscriber(nodeName+"/odom",Odometry,callback=self.update_pose)
   self.odometry = Odometry()
   self.rate = rospy.Rate(10)
if __name__ == "__main__":
 nodeId = sys.argv[1]
try:
     nodeName = "robot_"+nodeId
     x = Turtlebot(nodeName,0,0)
     x.move2goal()
     rospy.spin()

Launch File:

    <param name="x1" type="int" value="4" />
<param name="y1" type="int" value="0" />
<param name="x2" type="int" value="5" />
<param name="y2" type="int" value="0" />


<node pkg="stage_ros" name="stageros" type="stageros" args="$(find beginner_tutorials)/world/worldfile.world" output="screen"/>



<!-- <node pkg="beginner_tutorials" name="rotate1" args="0"  type="projecttask2.py"/> -->
 <node pkg="beginner_tutorials" name="rotate2"  args="1" type="projecttask2.py">



</node>

Error: KeyError('x1')

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-05-24 10:13:03 -0500

Ranjit Kathiriya gravatar image

hello,

try to put / just before your variable name x1, It will work.

rospy.get_param('/x1')
edit flag offensive delete link more

Comments

Thank you!

qwertyup667 gravatar image qwertyup667  ( 2022-05-24 10:37:48 -0500 )edit

Tick the answer, if it is working It can help others,

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2022-05-24 10:38:59 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-05-24 06:48:57 -0500

Seen: 128 times

Last updated: May 24 '22