Load parameter in launchfile
Hello, I want to load a randomized spawn location from the parameter server.
I created a python script, which stores the location of some predefined strings '-x1 -y1 -z1 -Y0'
.
A random function selects one of those strings:
rospy.set_param('/robot_spawn_location', randomString)
rospy.get_param("/robot_spawn_location")
This works fine, with "rosparam list"
and "rosparam get robot_spawn_location"
it is accessible.
But i am confused on how to load the parameter in my launch file.
In my node, i want to load the String-Parameter in the args="-p1 -p2 -pN -robot_spawn_location"
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model turtlebot3_waffle_pi -robot_spawn_location -param robot_description" />
I tried to load the parameter with the help of serveral tutorial, but none worked. From that source i got my Inspiration.
Anybody got a hint?
System:
- Ros Noetic
- Ubuntu LTS 20.04
Edit: Workflow: I created a bash-file to start all necessary launchfiles and starting a roscore (easier to work with). With my maze.launch i want to start in a gazebo map (it is a maze) the turtlebot at a random location. The location is currently only 1 Position (=string) (which when implemented in the launch works just fine). To spawn randomly I created a python file which chooses a string from a list and this random string is then set as a ros parameter. In the launchfile I wanted to load that parameter.
python code randomizer (short version):
startPosition = [
'-x 0.625 -y 0.625 -z 0 -Y 0',
'-x 0.625 -y 0.625 -z 0 -Y 0',
'-x 0.625 -y 0.625 -z 0 -Y 0',]
getRandomPosition = random.choice(startPosition)
rospy.set_param('/robot_spawn_location', getRandomPosition)
if rospy.has_param('/robot_spawn_location'):
rospy.get_param("/robot_spawn_location")
else:
print("No Spawn Location Set")
return -1
code launchfile:
<?xml version="1.0" ?>
<launch>
<include file="$(find gazebo_ros)launch/empty_world.launch" >
<arg name="world_name" value="$(find myPkg)/maps/Maze.world" />
<arg name="paused" value="false" />
<arg name="use_sim_time" value="true" />
<arg name="gui" value="false" />
</include>
<include file="$(find turtlebot3_bringup)launch/turtlebot3_remote.launch" />
<!-- Set Parameter -->
<param name="robot_spawn_location" command="python3 $(find myPkg)/launch/randomizer.py"/>
<param name="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_waffle_pi.urdf.xacro" />
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="
-urdf
-model turtlebot3_waffle_pi
-param robot_spawn_location
-param robot_description" />
<!--ORIGINAL: node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model turtlebot3_waffle_pi -x 0.625 -y 0.625 -z 0 -Y 0 -param robot_description" / -->
</launch>
With that it did not load the parameter (seen in Parameter List of roslaunch) and spawns therefore at its default (i guess) location in the map. The parameter is there, but empty. While testing the python file, i started a roscore and then run the script and verified if the parameter was set correctly, and it is. With that i don't get an error, but the handling doesn't work.
Your current workflow is not entirely clear to me. Can you post your code? What error(s) are you getting when you try the solution in the answer you linked?