{#--------------------------------SDF generator for Spiri with Tether Gazebo model---------------------------#}
{#------------------------------Retrieved from:https://github.com/RigidWing/sitl_gazebo----------------------#}
{#---------------------------------Maintained by Kitepower BV: info@kitepower.nl-----------------------------#}
{#--------------------------------The parameters bellow are the ones to be tweaked---------------------------#}
{#--------------------------------------------:Tweakable parameters:-----------------------------------------#}
{%- set number_elements = 1 -%}
{%- set tl = 0.8 -%} {#- tl: length of the tether element (meters) -#}
{%- set cr = 0.005 -%} {#- cr: radius of the tether element (meters) -#}
{%- set cr_v = 0.005 -%} {#- cr_v: radius of the tether element visual (meters) -#}
{%- set sr = 0.01 -%} {#- sr: element joint radius (sphere) (meters) -#}
{%- set m = 0.005 * tl -%} {#- m: mass of the element (kg), given the length -#}
{%- set cda = 1.253582 -%} {#- cda: the ratio of the drag coefficient before stall. -#}
{%- set cda_stall = 1.4326647564469914 -%} {#- cda_stall: the ratio of the drag coefficient after stall. -#}
{%- set damping = 0.0001 -%} {#- Model damping -#}
{%- set friction = 0.0 -%} {#- Friction of the model relative to the world -#}
{%- set tether_stiffness = 0.0005 -%} {#- Tether stiffness -#}
{%- set joint_stiffness = 0.0005 -%} {#- Joint stiffness, i.e where tether attaches to drone -#}
{%- set spring_reference = 0.0 -%} {#- Reference where the spring forces are applied -#}
{%- set element_color = 'White' -%} {#- Color of the tether elements -#}
{%- set joint_color = 'Red' -%} {#- Color of the tether element joints -#}
{%- set vehicle_spawn_point_y = 0.0 -%} {#- Y coordinate of vehicle spawn point -#}
{%- set debug = 0 -%} {#- Used for debugging tether joints -#}
{#----------------------------------------------------------------------------------------------------------#}
{#---------------------------------------------:Payload parameters:-----------------------------------------#}
{#----------------------------------------------------------------------------------------------------------#}
{%- set payload_m = 0.25 -%} {#- Payload mass (kg). Used to be 0.5 -#}
{%- set pr = 0.025 -%} {#- Payload radius (meters). Has to be less than FULL tether length -#}
{%- set add_imu = 1 -%} {#- Add IMU to payload for localization-#}
{#-----------------------------------------------------------------------------------------------------------#}
{#----------------------------------------------:Spiri parameters:-------------------------------------------#}
{#-----------------------------------------------------------------------------------------------------------#}
{%- set spiri_collision_x = 0.21355 -%}
{%- set spiri_collision_y = 0.132 -%}
{%- set spiri_collision_z = 0.04206 -%}
{%- set theta = 1.5707 -%}
{%- set yaw = 0 -%} {#- Necessary to spawn magnometer and Spiri in correct orientation -#}
{#----------------------------------------------------------------------------------------------------------#}
{#---------------------------------------------:Computed parameters:----------------------------------------#}
{#----------------------------------------------------------------------------------------------------------#}
{%- set last_elem = number_elements |int - 1 -%}
{%- set full_tether_len = number_elements * tl -%}
{%- set vehicle_spawn_point_x = full_tether_len -%}
{#- Check if we are in debug mode -#}
{%- if debug == 1 -%}
{%- set vehicle_spawn_point_z = 4.0 -%} {#- Used to spawn in desired z location -#}
{%- set pload_spawn_x = 0 -%}
{%- set pload_spawn_y = 0 -%}
{%- set pload_spawn_z = vehicle_spawn_point_z - tl -%}
{%- set pload_joint_x = 0 -%}
{%- set pload_joint_y = 0 -%}
{%- set pload_joint_z = -tl/2 -%}
{%- else -%}
{%- set vehicle_spawn_point_z = 0.0 -%}
{%- set pload_spawn_x = full_tether_len -%}
{%- set pload_spawn_y = 0 -%}
{%- set pload_spawn_z = 0 -%}
{%- set pload_joint_x = 0 -%}
{%- set pload_joint_y = 0 -%}
{%- set pload_joint_z = tl/2 -%}
{%- endif -%}
{%- set tether_pos = vehicle_spawn_point_z - full_tether_len/2 -%} {#- Spawns tether vertically -#}
{#----------------------------------------------------------------------------------------------------------#}
{#-----------------------------------------------:MACROS:---------------------------------------------------#}
{#----------------------------------------------------------------------------------------------------------#}
{%- macro payload(payload_m, n, pr, x, y, z, j_x, j_y, j_z) -%}
{{ x }} {{ y }} {{ z }} 0 0 0
1
{{ payload_m }}
0 0 0 0 0 0
{{ pr }}
0 0 0 0 0 0
{{ sphere(pr) }}
{%- if number_elements == 1 %}
{%- else -%}
{%- set k = 'ball' -%}
{#- -#}
{% endif %}
payload
link_{{n}}
{#- joint_param(tl, damping, friction, joint_stiffness, spring_reference, k) #}
{{ j_x }} {{ j_y }} {{ j_z }} 0 0 0
true
{%- if n is number -%}
1.0
ft_sensor_topic/payload
tether_mass_connection
{%- endif %}
{%- endmacro -%}
{%- macro cylinder(tl, cr_v) -%}
{{tl}}
{{cr_v}}
{%- endmacro -%}
{%- macro imu_link(x, y, z) -%}
{{ x }} {{ y }} {{ z }} 0 0 0
0.015
1e-05
0
0
1e-05
0
1e-05
pload_imu
payload
1 0 0
0
0
0
0
0
0
0
true
pload_imu
/pload_imu
imu_service
0.0
20.0
{%- endmacro -%}
{%- macro sphere(sr) -%}
{{sr}}
{%- endmacro -%}
{%- macro inertial(m) -%}
{#- A note about the inertial tensor matrix - It should be as below -#}
{#- set izz = m/2*cr**2 -#}
{#- set ixx = m/12*tl**2 + m/4*cr**2 -#}
{#- set iyy = m/12*tl**2 + m/4*cr**2 -#}
{#- but seems to segfault Gazebo when changing the values of the element specs -#}
{%- set izz = 0.01 -%}
{%- set ixx = 0.01 -%}
{%- set iyy = 0.01 -%}
{{m}}
{{ixx}}
0
0
{{iyy}}
0
{{izz}}
{%- endmacro -%}
{%- macro collision(tl, cr) -%}
{{tl / 2 - tl / 2}} 0 0 0 0 0
{{ cylinder(tl, cr) }}
0.00005
1.0
1.0
{%- endmacro -%}
{%- macro element_material(element_color) -%}
{%- endmacro -%}
{%- macro joint_material(joint_color) -%}
{%- endmacro -%}
{%- macro element_visual(tl, cr_v, element_color) -%}
{%- set x = tl * 0.5 -%}
0 0 0 0 0 0
{{ cylinder(tl, cr_v) }}
{{ element_material(element_color) }}
{%- endmacro -%}
{%- macro sphere_visual(sr, joint_color) -%}
0 0 {{ tl / -2 }} 0 0 0
{{ sphere(sr) }}
{{ joint_material(joint_color) }}
{%- endmacro -%}
{%- macro link(n, x, y, z, theta, m, tl, cr, cr_v, sr, element_color, joint_color) -%}
{% if debug == 1 %}
{%- endif %}
true
{{x}} {{y}} {{z}} 0.0 {{theta}} 0.0
{{ inertial(m) }}
{%- if n != 0 and n != "spiri_attch_fixed" %}
{{ collision(tl, cr) }}
{{ element_visual(tl, cr_v, element_color) }}
{%- endif -%}
{%- if n != 0 -%}
{{ sphere_visual(sr, joint_color) }}
{%- endif %}
{%- endmacro %}
{%- macro joint(k, damping, friction, joint_stiffness, spring_reference, joint_type, number_elements) -%}
{%- if k is number -%}
{%- set link_n = k - 1 -%}
link_{{k}}
link_{{link_n}}
{{ joint_param(tl, damping, friction, tether_stiffness, spring_reference, k) }}
{%- elif number_elements == 1 -%}
{%- else -%}
{%- set link_n = 1 -%}
link_{{k}}
link_{{link_n}}
{{ joint_param(tl, damping, friction, tether_stiffness, spring_reference, k) }}
{%- endif %}
{%- endmacro -%}
{%- macro joint_param(tl, damping, friction, joint_stiffness, spring_reference, k) -%}
{%- if k is number -%}
0 0 -{{ tl/2 }} 0 0 0
{%- else -%}
0 0 {{ tl/2 }} 0 0 0
{%- endif %}
0 1 0
{{damping}}
{{friction}}
{{joint_stiffness}}
{{spring_reference}}
true
0 0 1
{{damping}}
{{friction}}
{{joint_stiffness}}
{{spring_reference}}
true
1
{%- if k is not number -%}
true
{%- endif -%}
{%- endmacro -%}
{%- macro lift_drag(n, tl, cr) -%}
{%- set area = 2 * cr * tl -%}
0
0
{{cda}}
0
{{cda_stall}}
true
{{tl/2}} {{cr}} {{cr}}
{{area}}
1.2041
0 1 0
0 0 1
link_{{n}}
{%- endmacro -%}
{#- -#}
{%- macro final_tether(tl) -%}
{%- if debug == 1 -%}
{{ link("spiri_attch", 0, 0, tether_pos, 0, m, tl, cr, cr_v, sr, element_color, joint_color) }}
{{ lift_drag("spiri_attch", tl, cr) }}
{{ joint("spiri_attch", damping, friction, joint_stiffness, spring_reference, "universal", number_elements) }}
{%- else -%}
{%- set lose_x = tl/2 -%}
{{ link("spiri_attch", tl/2, vehicle_spawn_point_y, 0, theta, m, tl, cr, cr_v, sr, element_color, joint_color) }}
{{ lift_drag("spiri_attch", tl, cr) }}
{{ joint("spiri_attch", damping, friction, joint_stiffness, spring_reference, "universal", number_elements) }}
{%- endif -%}
{%- if debug == 1 -%}
{%- endif -%}
{%- endmacro -%}
{#- -#}
{%- macro joint_type(j_type) -%}
{%- if j_type == 'ball' -%}
link_spiri_attch
spiri::base
{#- joint_param(tl, damping, friction, joint_stiffness, spring_reference, 1) -#}
{% if debug == 1 %}
0 0 {{ tl/2 }} 0 0 0
{%- else -%}
0 0 -{{ tl/2 }} 0 0 0
{% endif %}
true
{%- else -%}
link_spiri_attch
spiri::base
{{ joint_param(tl, damping, friction, joint_stiffness, spring_reference, 1) }}
{%- endif -%}
{%- endmacro -%}
{#----------------------------------------------------------------------------------------------------------#}
{#-----------------------------------------------:SDF GENERATION:-------------------------------------------#}
{#----------------------------------------------------------------------------------------------------------#}
0 0 0 0.0 0.0 0.0 {# only have to change this to change spawn location #}
model://spiri_mocap
0.0 0.0 {{ vehicle_spawn_point_z }} 0.0 0.0 {{ yaw }}
{{ debug }}
{{joint_type('ball')}}
1.0
ft_sensor_topic/spiri
tether_to_spiri_joint
{#- ---------- CREATE TETHER LINKS -------- -#}
{{ final_tether(tl) }}
{%- for n in range(1, number_elements) -%}
{%- set x = (tl / 2 + (n*tl)) -%}
{{ link(n, x, vehicle_spawn_point_y, 0.0, theta, m, tl, cr, cr_v, sr, element_color, joint_color) }}
{{ lift_drag(n, tl, cr) }}
{%- endfor -%}
{%- for k in range(2, number_elements) -%}
{{ joint(k, damping, friction, tether_stiffness, spring_reference, "universal", number_elements) }}
{% endfor %}
{#------------- PAYLOAD -----------#}
{%- if number_elements == 1 -%}
{%- set n = "spiri_attch" -%}
{%- else -%}
{%- set n = number_elements - 1 -%}
{% endif %} {{ payload(payload_m,n,pr,pload_spawn_x,pload_spawn_y,pload_spawn_z,pload_joint_x,pload_joint_y,pload_joint_z) }}
{#------------- ADD IMU -----------#}
{%- if add_imu == 1 -%}
{{ imu_link(pload_spawn_x,pload_spawn_y,pload_spawn_z) }}
{% endif %}