# Revision history [back]

So first of all, its not a good idea to create this in SDF due to its repeated structure. For this model you have to use XACROS. It will also help you in the control and ROS integration.

Here I leave a video tutorial explaining all you need to create it: VIDEO Tutorial

Here I've done an example code of a snake made up of eight main cylinders and seven joint cylinders. In your case it would be the same but replacing the cylinders by meshes. This snake is made so that it has 2 DOF in each "joint", having roll and pitch. It has also position control to move it around and of course the joint states are published, so that you will be able to see it in RVIZ TFs and the Robot Model.

Here I leave the code with the launches and also the control parameters. Hope it helps. Sorry for the false extensions, but here some file formats are not allowed. Launch the **init_snake.launch" in an empty world to spawn the robot with the controlers.

snake_controllers.urdf.xacro

snake_full_control.yaml

spawn_xacro.launch

spawn_full_snake.launch

snake_full_control.launch

init_snake.launch

So first of all, its not a good idea to create this in SDF due to its repeated structure. For this model you have to use XACROS. It will also help you in the control and ROS integration.

Here I leave a video tutorial explaining all you need to create it: VIDEO Tutorial

Here I've done an example code of a snake made up of eight main cylinders and seven joint cylinders. In your case it would be the same but replacing the cylinders by meshes. This snake is made so that it has 2 DOF in each "joint", having roll and pitch. It has also position control to move it around and of course the joint states are published, so that you will be able to see it in RVIZ TFs and the Robot Model.

Here I leave the code with the launches and also the control parameters. Hope it helps. Sorry for the false extensions, but here some file formats are not allowed. Launch the **init_snake.launch" in an empty world to spawn the robot with the controlers.

snake_controllers.urdf.xacro

snake_full_control.yaml

spawn_xacro.launch

spawn_full_snake.launch

snake_full_control.launch

init_snake.launch

So first of all, its not a good idea to create this in SDF due to its repeated structure. For this model you have to use XACROS. It will also help you in the control and ROS integration.

Here I leave a video tutorial explaining all you need to create it: VIDEO Tutorial

Here I've done an example code of a snake made up of eight main cylinders and seven joint cylinders. In your case it would be the same but replacing the cylinders by meshes. This snake is made so that it has 2 DOF in each "joint", having roll and pitch. It has also position control to move it around and of course the joint states are published, so that you will be able to see it in RVIZ TFs and the Robot Model.

Here I leave the code with the launches and also the control parameters. Hope it helps. Sorry for the false extensions, but here some file formats are not allowed. Launch the **init_snake.launch" in an empty world to spawn the robot with the controlers.

snake_controllers.urdf.xacro

snake_full_control.yaml

spawn_xacro.launch

spawn_full_snake.launch

snake_full_control.launch

init_snake.launch

Edit:

Based on what @chapulina said I created an example also with SDF macro-Ruby system and got nice results also. In this case I parametrised absolutly everything which allows you to generate massive length snakes, with diferent size and recalcalculation of the inertias ;). I didnt add controlers though.

Here I leave the video explaining in detail the code and how to use it: VIDEO SDF MACRO

Here you have the code for the SDF version. You will need to always convert the .erb format file into sdf with the command erb snake.erb > snake_macro.sdf. And then you can launch it through spawn of and SDF like always.

Here you have an example of a 100 element snake with self colissions ;).

Sorry for the fake file extensions, but erb for some reason are not allowed here.

snake.erb

spawn_sdf_macro.launch

commands_sdf.sh

Hope with this you have a better understanding on how to create this multiple element snake in SDF or URDF ;). Thanks @chapulina for the SDF Macro Idea ;). Chapulina give in the comments very usefull example code for those interested in learning more about SDF-Ruby macro ;).

Have fun Roboticists !

So first of all, its not a good idea to create this in SDF due to its repeated structure. For this model you have to use XACROS. It will also help you in the control and ROS integration.

Here I leave a video tutorial explaining all you need to create it: VIDEO Tutorial

Here I've done an example code of a snake made up of eight main cylinders and seven joint cylinders. In your case it would be the same but replacing the cylinders by meshes. This snake is made so that it has 2 DOF in each "joint", having roll and pitch. It has also position control to move it around and of course the joint states are published, so that you will be able to see it in RVIZ TFs and the Robot Model.

Here I leave the code with the launches and also the control parameters. Hope it helps. Sorry for the false extensions, but here some file formats are not allowed. Launch the **init_snake.launch" in an empty world to spawn the robot with the controlers.

snake_controllers.urdf.xacro

snake_full_control.yaml

spawn_xacro.launch

spawn_full_snake.launch

snake_full_control.launch

init_snake.launch

Edit:

Based on what @chapulina said I created an example also with SDF macro-Ruby system and got nice results also. In this case I parametrised absolutly everything which allows you to generate massive length snakes, with diferent size and recalcalculation of the inertias ;). I didnt add controlers though.

Here I leave the video explaining in detail the code and how to use it: VIDEO SDF MACRO

Here you have the code for the SDF version. You will need to always convert the .erb format file into sdf with the command erb snake.erb > snake_macro.sdf. And then you can launch it through spawn of and SDF like always.

Here you have an example of a 100 element snake with self colissions ;).

And here 1000 elements ;). Just for fun:

Sorry for the fake file extensions, but erb for some reason are not allowed here.

snake.erb

spawn_sdf_macro.launch

commands_sdf.sh

Hope with this you have a better understanding on how to create this multiple element snake in SDF or URDF ;). Thanks @chapulina for the SDF Macro Idea ;). Chapulina give in the comments very usefull example code for those interested in learning more about SDF-Ruby macro ;).

Have fun Roboticists !

So first of all, its not a good idea to create this in SDF due to its repeated structure. For this model you have to use XACROS. It will also help you in the control and ROS integration.

Here I leave a video tutorial explaining all you need to create it: VIDEO Tutorial

Here I've done an example code of a snake made up of eight main cylinders and seven joint cylinders. In your case it would be the same but replacing the cylinders by meshes. This snake is made so that it has 2 DOF in each "joint", having roll and pitch. It has also position control to move it around and of course the joint states are published, so that you will be able to see it in RVIZ TFs and the Robot Model.

Here I leave the code with the launches and also the control parameters. Hope it helps. Sorry for the false extensions, but here some file formats are not allowed. Launch the **init_snake.launch" in an empty world to spawn the robot with the controlers.

snake_controllers.urdf.xacro

snake_full_control.yaml

spawn_xacro.launch

spawn_full_snake.launch

snake_full_control.launch

init_snake.launch

Edit:

Based on what @chapulina said I created an example also with SDF macro-Ruby system and got nice results also. In this case I parametrised absolutly everything which allows you to generate massive length snakes, with diferent size and recalcalculation of the inertias ;). I didnt add controlers though.

Here I leave the video explaining in detail the code and how to use it: VIDEO SDF MACRO

Here you have the code for the SDF version. You will need to always convert the .erb format file into sdf with the command erb snake.erb > snake_macro.sdf. And then you can launch it through spawn of and SDF like always.

Here you have an example of a 100 element snake with self colissions ;).

And here 1000 elements ;). Just for fun:

Sorry for the fake file extensions, but erb for some reason are not allowed here.

snake.erb

spawn_sdf_macro.launch

commands_sdf.sh

Hope with this you have a better understanding on how to create this multiple element snake in SDF or URDF ;). Thanks @chapulina for the SDF Macro Idea ;). Chapulina give in the comments very usefull example code for those interested in learning more about SDF-Ruby macro ;).

REEdit: Part 3: Automated Xacro by one script

This is the third edit where I give also a method on how to totaly automatise the spawning of the Snake in Xacros with the Controllers needed to make it work:

Here is the video with all the process detailed VIDEO Part3

Because when you generate a variable element robot, you need to have also a variable controler.yaml file, and also pass the number of elements to the XAcro through the launch file and the list of all the controllers used, a method to generate all that is needed.

So I divided it in these steps: 1) Pass the number of elements to be created in the snake to the xacro. That is done through the launch :

<param name="robot_description" command="$(find xacro)/xacro '$(arg xacro_robot_file)' prefix:=$(arg number_of_elements)" /> This passes the number of element to the xacro which reads it like this: <xacro:property name="NumberOfElements" value="$(arg prefix)" />

2) The second step is to pass the controller names list to the controller manager. That is accomplished through the controller_args arg:

<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" output="screen" ns="/snake" args="$(arg controller_args)"/> 3) These args controller_args and number_of_elements are passed to the launch file through the command line in a shell script reading from two different files, in the script start_snake.sh: number_of_elements=$(cat numelements_temp.yaml)
echo $number_of_elements controllerargs=$(cat controllerargs_temp.yaml)
echo $controllerargs roslaunch snake_description init_snake_n.launch number_of_elements:="$number_of_elements"
controller_args:="$controllerargs"  As you can see we launch the main init_snake_n.launch launch with those to arguments as input. 4) The final step is create a python script that generates those two files (numelements_temp.yaml and controllerargs_temp.yaml) and also the most important control file which is the snake_full_control_temp.yaml where all the PID values and controllers to joints relations are stated, among other things in the snake_full_control_n.launch: <rosparam file="$(find snake_description)/scripts/snake_full_control_temp.yaml" command="load"/>

The python script generates all this based only on the number of elements and it is launched before launching the init_snake_n.launch. This script is called config_files_yaml_generator.py.

Here I leave all the files used. I hope it was usefull.

snake_controllers_n.urdf.xacro

config_files_yaml_generator.py

start_snake.sh

spawn_xacro.launch

snake_full_control_n.launch

spawn_full_snake_n.launch

init_snake_n.launch

Have fun Roboticists !