How to assign random values to robot's initial position args in launch file

asked 2018-11-24 17:40:50 -0500

sarmad.mehrdad.001@gmail.com gravatar image

updated 2018-11-26 10:54:50 -0500

Hi Everyone,

I want to try giving my robot random positions and orientations every time it spawns in the Gazebo model but I have no idea how to randomize the value of the args. I've already seen one other question with a similar problem and the solution didn't help me since it was regarding setting the value of "param"s with a python code which didn't work for me, at least with my knowledge of ROS. I'm trying my luck with a husky robot simulation so that, if successful, it can be tested on another robot. I'm using UBUNTU 16.04 and ROS Kinetic. My launch is as follows :

<launch>
  <arg name="laser_enabled" default="true"/>
  <arg name="ur5_enabled" default="false"/>
  <arg name="kinect_enabled" default="false"/>

  <param name="robot_description" command="$(find xacro)/xacro --inorder $(find husky_gazebo)/urdf/description.gazebo.xacro
    laser_enabled:=$(arg laser_enabled)
    ur5_enabled:=$(arg ur5_enabled)
    kinect_enabled:=$(arg kinect_enabled)
    " />

  <arg name="x" default="-0.25"/>
  <arg name="y" default="-1.25"/>
  <arg name="z" default="0"/>
  <node name="spawn_husky_model" pkg="gazebo_ros" type="spawn_model" args=" -unpause -urdf -param robot_description -model mobile_base -x $(arg x) -y $(arg y) -z $(arg z)"/>

</launch>

I will appreciate any help. If I should use a python file as a random number generator please explain to me how. Thank you

edit retag flag offensive close merge delete

Comments

1

I've already seen one other question with a similar problem and the solution didn't help me since it was regarding setting the value of "param"s with a python code which didn't work for me [..]

Without knowing what "didn't work" for you we can't help, but it seems like solving those issues ..

gvdhoorn gravatar imagegvdhoorn ( 2018-11-25 03:33:34 -0500 )edit

.. would be the thing to do here because there is no built-in way to "assign random values" in roslaunch.

So please describe what didn't work for you with the approaches that you already found and perhaps forum members can help you then.

gvdhoorn gravatar imagegvdhoorn ( 2018-11-25 03:34:29 -0500 )edit

Similar to #q216303 but new launch features may provide for a better answer.

lucasw gravatar imagelucasw ( 2018-11-25 08:23:18 -0500 )edit

#q216303 didn't work for me because it was referring to how use "param"s in a launch file and not "arg"s. I tried implementing the same approach with a python file as a random number generator for the args that I'm using but I got errors for using methods that were meant for "param"s for "arg"s ...

sarmad.mehrdad.001@gmail.com gravatar imagesarmad.mehrdad.001@gmail.com ( 2018-11-25 13:16:41 -0500 )edit

I have no problem of using a python script as a random number generator and based on #q216303 I believe this approach is the best way of doing it but I just need more elaboration on the subject of how to use the python script for "arg"s in this context and how to address it properly in the launch.

sarmad.mehrdad.001@gmail.com gravatar imagesarmad.mehrdad.001@gmail.com ( 2018-11-25 13:29:57 -0500 )edit