Search code examples
pythonros

"process has died" error while launching the file in ros


I am going to implement the Monte_Carlo localization with ROS; however,when i launch my node in a Roslaunch file i receive the below error. the interesting thing is that, whenever i run the node using rosrun it works, but not working in roslaunch file.

the ROS node from which i want to create a launch file:

#!/usr/bin/env python 
from nav_msgs.msg import Odometry
from visualization_msgs.msg import Marker, MarkerArray

from geometry_msgs.msg import Point
import tf
from tf.transformations import euler_from_quaternion
import numpy as np
import rostopic
import rospy


global mu
mu=[-2,-0.5,0]


def callback(data):
    global mu

    #add_point = Point()
    vel=data.twist.twist.linear.x/odom_hz
    ang=data.twist.twist.angular.z/odom_hz
    x_p=mu[0]+vel*np.cos(mu[2])
    y_p=mu[1]+vel*np.sin(mu[2])
    theta_p=ang+mu[2]
    mu=[x_p,y_p,theta_p]
    #add_point.x = x_p those are for a seet of point 
    #add_point.y = y_p
    #add_point.z = 0
    number_of_particles=100
    marker_arr=MarkerArray()
    marker_arr.markers=[]
    for i in range(number_of_particles):
        marker = Marker()

        marker.header.frame_id = "odom"
        marker.type = marker.SPHERE
        marker.action = marker.ADD
        marker.ns="est_pose_"+str(i)
        marker.id=i

        # marker scale
        marker.scale.x = 0.01
        marker.scale.y = 0.01
        marker.scale.z = 0.01

        # marker color
        marker.color.a = 1.0
        marker.color.r = 1.0
        marker.color.g = 1.0
        marker.color.b = 0.0

        # marker orientaiton
        marker.pose.orientation.x = 0.0
        marker.pose.orientation.y = 0.0
        marker.pose.orientation.z = 0.0
        marker.pose.orientation.w = 1.0

        marker.pose.position.x=np.random.uniform(x_p-0.05,x_p+0.05)
        marker.pose.position.y=np.random.uniform(y_p-0.05,y_p+0.05)
        marker.pose.position.z=0
        marker_arr.markers.append(marker)
        #marker.points.append(add_point)
        # Publish the Marker
    pub_point.publish(marker_arr)





# marker line points
#marker.points = []

if __name__=="__main__":
    global odom_hz
    map_file = rospy.get_param("~map_file")
    odom_topic_name = "odom"
    rospy.init_node('position_tracker')
    time_stamp=rospy.Time.now()
    pub_point = rospy.Publisher('realpoints_marker', MarkerArray, queue_size=1)


    tf_sub=tf.TransformListener()
    r = rostopic.ROSTopicHz(-1)
    s=rospy.Subscriber('/' + odom_topic_name, Odometry, r.callback_hz, callback_args='/odom')
    rospy.sleep(1)
    odom_hz = int(r.get_hz('/' + odom_topic_name)[0])
    s.unregister()
    rospy.Subscriber("/odom",Odometry, callback)

    rospy.spin()

the launch file including the ros node;

<launch>

    <node pkg="just_for_learning"  type="pointstamp.py" name="position_tracker">
            <param name="map_file" value="$(find robot_laser_grid_mapping)/maps/map.yaml" />

    </node>
    <node pkg="teleoperat1" type="key_to_twist.py" name="keys_to_twist" ></node>
    <node pkg="teleoperat1" type="keyboard_drive.py" name="keyboard_driver" ></node>

    <include file="$(find turtlebot3_gazebo)/launch/turtlebot3_world.launch" ></include>

    <include file="$(find turtlebot3_bringup)/launch/turtlebot3_model.launch"></include>

</launch>

Solution

  • One of the only things that would cause this to crash with roslaunch only is your map file param. That map file either does not exist or the name spacing is wrong; since you’re pulling from the private namespace in your script.

    It should also be noted that you should not be trying to pull params before calling init_node(). The get_param call should be after init as that can also cause problems.