Unable to read a file while using relative path
Hi, I want to read a file inside python script in ros indigo in the following way -
file_name = rospy.get_param("~file", None)
Below is the snippet of launch file -
<launch>
<arg name="file" default="$(find kinematics)/sample/joint_states.csv" />
<arg name="animation" default="true" /> <!-- run animation -->
<group if="$(arg animation)">
<node pkg="kinematics" type="trajectory.py" name="trajectory_animation" respawn="true">
<param name="file" value="$(arg file)" />
</node>
</group>
</launch>
While providing the file
parameter as a command line argument, it says No such file or directory
. Below is the output of terminal -
ravi@ravi-pc:~/ros_ws$ roslaunch kinematics baxter.launch file:=src/../../Desktop/joint_states.csv
File "/home/ravi/ros_ws/src/kinematics/src/trajectory.py", line 19, in __init__
with open(file_name, 'r') as f:
IOError: [Errno 2] No such file or directory: 'src/../../Desktop/joint_states.csv'
ravi@ravi-pc:~/ros_ws$ ll src/../../Desktop/joint_states.csv
-rw-rw-r-- 1 ravi ravi 179308 May 19 20:46 src/../../Desktop/joint_states.csv
ravi@ravi-pc:~/ros_ws$ roslaunch kinematics baxter.launch file:=src/kinematics/sample/joint_states.csv
File "/home/ravi/ros_ws/src/kinematics/src/trajectory.py", line 19, in __init__
with open(file_name, 'r') as f:
IOError: [Errno 2] No such file or directory: 'src/kinematics/sample/joint_states.csv'
ravi@ravi-pc:~/ros_ws$ ll src/kinematics/sample/joint_states.csv
-rw-rw-r-- 1 tom tom 179308 May 19 20:46 src/kinematics/sample/joint_states.csv