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

Load a urdf/xml file as rosparm from a c++ ros node

asked 2018-02-01 10:12:44 -0500

vacky11 gravatar image

updated 2018-02-01 12:47:07 -0500

I have followed the rosparam tutorial. But it dosent show how to load a xml/urdf file as a rosparam. Specifically, I want to set "robot_description" parameter from a c++ ros node not from a launch file.

edit retag flag offensive close merge delete

Comments

How about using a launch file?

jayess gravatar image jayess  ( 2018-02-01 13:08:03 -0500 )edit
1

I have mentioned it clearly in the question that I am not looking to set the parameter from a launch file. It is not suitable for my purpose.

vacky11 gravatar image vacky11  ( 2018-02-01 13:11:16 -0500 )edit

Yeah, guess I missed that. Why not?

jayess gravatar image jayess  ( 2018-02-01 13:18:04 -0500 )edit

The reason is that I get the 'robot_name' from a rostopic inside the ros node and then I need to load the appropriate urdf file as parameter:"robot_description", depending on the robot_name

vacky11 gravatar image vacky11  ( 2018-02-01 13:30:05 -0500 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2018-02-01 14:11:32 -0500

vacky11 gravatar image

updated 2018-06-04 12:52:13 -0500

Update:

Finally, this is how im doing it. You just need to read urdf file as a text file and store its content in a string and then set the string as a parameter

// Parse the urdf/xml file
std::string urdf_file_name = "/home/.../urdf_file_name.urdf"
std::ifstream f(urdf_file_name); 
std::stringstream ss;
ss << f.rdbuf();

// Set param
nh.setParam("robot_description", ss.str());
edit flag offensive delete link more

Comments

If you're not actually using the parsed urdf, why use tinyxml? A urdf is just a text file.

gvdhoorn gravatar image gvdhoorn  ( 2018-02-02 04:28:54 -0500 )edit

@gvdhoorn I didnt realize this. I'll try to read urdf file as a simple text file and will update my answer if that works

vacky11 gravatar image vacky11  ( 2018-02-05 10:53:32 -0500 )edit

@gvdhoorn you were absolutely correct. Thanks for your input.

vacky11 gravatar image vacky11  ( 2018-02-12 10:17:55 -0500 )edit

@vacky11 Could you please mention what is asset_urdf? Thanks.

NiranjanDeshpande gravatar image NiranjanDeshpande  ( 2018-04-01 10:12:53 -0500 )edit
1

@NiranjanDeshpande it is the urdf file name that needs to be set as a ros parameter. I will update my answer so that its intuitive

vacky11 gravatar image vacky11  ( 2018-05-22 14:07:02 -0500 )edit

Can you please update your full code. I code it like you, but there comes an error that 'youbot_arm' was not declared in this scope. youbot_arm is the name of my urdf file.

JonasG gravatar image JonasG  ( 2018-06-04 10:43:28 -0500 )edit

If I code it this way:

std::ifstream u ("/home/.../youbot_arm.urdf");

It cannot open the file.

JonasG gravatar image JonasG  ( 2018-06-04 11:16:04 -0500 )edit

@JonasG I have updated my answer. Hope that helps!

vacky11 gravatar image vacky11  ( 2018-06-04 12:52:50 -0500 )edit
1

answered 2018-02-01 12:43:16 -0500

updated 2018-02-01 13:25:41 -0500

rospy parameter API:
http://wiki.ros.org/rospy/Overview/Pa...

roscpp parameter API:
http://wiki.ros.org/roscpp/Overview/P...


rospy example (note, I have not tried running this code):

import rospy


rospy.init_node('my_node_name')

# Open .urdf and save contents as str
urdf_filename = "robot.urdf"
urdf_string = None
with open(urdf_filename) as urdf_file:  
    urdf_string = urdf_file.read()  

# Load urdf_string onto parameter server
if urdf_string is not None:
    rospy.set_param('robot_description', urdf_filename)

# Check
if not rospy.has_param('robot_description'):
    rospy.login("Cannot find 'robot_description' on parameter server")
else:
    urdf_string_param = rospy.get_param('robot_description')
    rospy.login(urdf_string_param )
edit flag offensive delete link more

Comments

@josephcoombe Thanks for your answer but Im looking for c++ implementation. Can you please give me a example for the same in c++?

vacky11 gravatar image vacky11  ( 2018-02-01 12:49:09 -0500 )edit

@vacky11 I've updated my answer with a link to the roscpp equivalent.

josephcoombe gravatar image josephcoombe  ( 2018-02-01 13:26:27 -0500 )edit

Hey. I am looking for that c++ implementation too. I don't know how to make a string out of my urdf.file. Can you please help me out? The rest of the code is clear.

Thanks

JonasG gravatar image JonasG  ( 2018-05-22 13:05:05 -0500 )edit
josephcoombe gravatar image josephcoombe  ( 2018-05-22 13:33:16 -0500 )edit

But I don't know what is meant with asset_urdf. I tried this but it doesn't work.

JonasG gravatar image JonasG  ( 2018-05-22 13:52:40 -0500 )edit
1

@JonasG it is urdf file name.

vacky11 gravatar image vacky11  ( 2018-05-22 14:09:10 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-01 10:12:44 -0500

Seen: 2,062 times

Last updated: Jun 04 '18