Why am I getting an rospy error in __getitem__ raise KeyError(key) ?
I am trying to launch a python script and hand over a parameter from the launchfile: script:
#!/usr/bin/env python
import roslib
roslib.load_manifest( 'package_name' )
import rospy
import datetime, sys, yaml
from gazebo_msgs.msg import ModelStates
# some functions
if __name__ == '__main__':
sim = rospy.get_param( '~sim' ) # <- edit
rospy.init_node('package_name', anonymous=True)
#something else ...
and I am trying to start it like that:
<?xml version="1.0"?>
<launch>
<arg name="sim" default="true"/>
<node name="node_name" pkg="package_name" type="script.py" output="screen">
<param name="sim" value="$( arg sim )" />
</node>
</launch>
import roslib and roslib.load_manifest should not be used if you're using ROS Groovy or later and catkin. Not sure if the inclusion of those lines may be causing your issue.
I ran into this and had simply forgotten that usually I provide a default parameter: