# Get variables in urdf.xacro from the launch file

The situation is as follows:

We, as a student project group, have a model of a car. This car has several sensors, including a gps sensor. The car has to be simulated in a real world location using gazebo and ros. Therefore the gps reference location has to be accurate compared to real life. So, looking at the spawning coordinates of the car should give the same location in f.i. google maps. We have achieved this in the urfd.xacro file of the car but the coordinates are hard coded. However, we would like to declare the coordinates in the launch files. The reason that we want to give the exact coordinated per different maps(worlds) that are launched from different launch file. Currently we have to change the coordinates in the urdf.xacro model every time we change the map.

So to conclude, we would like to set a variable in a launch file and use this value in the urdf.xacro file. Does somebody know how we can achieve this? Thank you very much in advance!

Kind regards,

Student project group from HAN Automotive

edit retag close merge delete

You can probably do what you describe using the support for passing args to xacro, as documented in the Rospack commands section on wiki/xacro.
As you probably have other settings that would need to be easily changed, I'd perhaps recommend to use a proper .yaml file and import that into your .xacro. May be a bit more scalable.