【PX4二次开发】PX4添加无人机模型和一些问题的总结
从SolidWorks中导出STL模型文件
SolidWorks建模
在Solidworks中开展建模工作,搭建无人机的模型。模型主要由机体,电机,螺旋桨等零件组成。
SolidWorks零件添加质量属性
为了尽量与实物的质量分布相同,我在对每个零件建模的时候都提前对实物的质量和尺寸进行测量,最后自定义材料属性并赋值给零件。这样可以尽可能地保证模型和实物的相似度,最终装配体的质量属性如下:
新建参考坐标系并导出STL文件
此处,我选取了无人机模型的重心作为坐标系的原点,并将坐标轴的X轴对齐无人机的机头方向。
另存为STL,选项中选择输出坐标系为刚才新建的坐标系。
PX4固件中的设置
方便起见,本次直接在PX4的默认启动模型iris基础上进行更改如下(也可以参考PX4官方文档教程新定义机型,本次不涉及):
SDF文件修改
在PX4-Autopilot/Tools/sitl_gazebo/models/iris文件夹中,新建一个sdf文件。仿照iris.sdf文件修改添加无人机质量,惯性矩,电机位置,机体和螺旋桨可视化文件,电机插件(电机常数、扭力系数,最大转速等参数可以通过动力系统实验测得数据),示例如下:
microfly.sdf
<!-- DO NOT EDIT: Generated from iris.sdf.jinja -->
<sdf version='1.6'>
<model name='microfly'>
<link name='base_link'>
<pose>0 0 0 0 0 0</pose>
<inertial>
<pose>0 0 0 0 0 0</pose>
<mass>0.279</mass>
<inertia>
<ixx>0.000509927</ixx>
<ixy>-0.0000</ixy>
<ixz>-0.0000</ixz>
<iyy>0.000543117</iyy>
<izy>-0.0000</izy>
<izz>0.000833593</izz>
</inertia>
</inertial>
<collision name='base_link_inertia_collision'>
<pose>0 0 0 0 0 0</pose>
<geometry>
<box>
<size>0.136 0.096 0.069</size>
</box>
</geometry>
<surface>
<contact>
<ode>
<min_depth>0.001</min_depth>
<max_vel>0</max_vel>
</ode>
</contact>
<friction>
<ode/>
</friction>
</surface>
</collision>
<visual name='base_link_inertia_visual'>
<pose>0 0 0 0 0 0</pose>
<geometry>
<mesh>
<scale>0.001 0.001 0.001</scale>
<uri>model://iris/meshes/microfly.STL</uri>
</mesh>
</geometry>
<material>
<script>
<name>Gazebo/DarkGrey</name>
<uri>file://media/materials/scripts/gazebo.material</uri>
</script>
</material>
</visual>
<gravity>1</gravity>
<velocity_decay/>
</link>
<link name='/imu_link'>
<pose>0 0 0 0 0 0</pose>
<inertial>
<pose>0 0 0 0 0 0</pose>
<mass>0.001</mass>
<inertia>
<ixx>1e-06</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>1e-06</iyy>
<iyz>0</iyz>
<izz>1e-06</izz>
</inertia>
</inertial>
</link>
<joint name='/imu_joint' type='revolute'>
<child>/imu_link</child>
<parent>base_link</parent>
<axis>
<xyz>1 0 0</xyz>
<limit>
<lower>0</lower>
<upper>0</upper>
<effort>0</effort>
<velocity>0</velocity>
</limit>
<dynamics>
<spring_reference>0</spring_reference>
<spring_stiffness>0</spring_stiffness>
</dynamics>
<use_parent_model_frame>1</use_parent_model_frame>
</axis>
</joint>
<link name='rotor_0'>
<pose>0.0535 -0.0535 -0.0224 0 0 0</pose>
<inertial>
<pose>0 0 0 0 0 0</pose>
<mass>0.0037</mass>
<inertia>
<ixx>9.50e-07</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>9.50e-07</iyy>
<iyz>0</iyz>
<izz>1.816e-06</izz>
</inertia>
</inertial>
<collision name='rotor_0_collision'>
<pose>0 0 0 0 0 0</pose>
<geometry>
<cylinder>
<length>0.005</length>
<radius>0.045</radius>
</cylinder>
</geometry>
<surface>
<contact>
<ode/>
</contact>
<friction>
<ode/>
</friction>
</surface>
</collision>
<visual name='rotor_0_visual'>
<pose>0 0 0 0 0 0</pose>
<geometry>
<mesh>
<scale>0.001 0.001 0.001</scale>
<uri>model://iris/meshes/microfly_3.5_prpo_ccw.stl</uri>
</mesh>
</geometry>
<material>
<script>
<name>Gazebo/RedTransparent</name>
<uri>file://media/materials/scripts/gazebo.material</uri>
</script>
</material>
</visual>
<gravity>1</gravity>
<velocity_decay/>
</link>
<joint name='rotor_0_joint' type='revolute'>
<child>rotor_0</child>
<parent>base_link</parent>
<axis>
<xyz>0 0 1</xyz>
<limit>
<lower>-1e+16</lower>
<upper>1e+16</upper>
</limit>
<dynamics>
<spring_reference>0</spring_reference>
<spring_stiffness>0</spring_stiffness>
</dynamics>
<use_parent_model_frame>1</use_parent_model_frame>
</axis>
</joint>
<link name='rotor_1'>
<pose>-0.0535 0.0535 -0.0224 0 0 0</pose>
<inertial>
<pose>0 0 0 0 0 0</pose>
<mass>0.0037</mass>
<inertia>
<ixx>9.50e-07</ixx>
<ixy>0</ixy>
<ixz>0</ixz>
<iyy>9.50e-07</iyy>
<iyz>0</iyz>
<izz>1.816e-06</izz>
</inertia>
</inertial>
<collision name='rotor_1_collision'>
<pose>0 0 0 0 0 0</pose>
<geometry>
<cylinder>
<length>0.005</length>
<radius>0.045</radius>
</cylinder>
</geometry>
<surface>
<contact>
<ode/>
</contact>
<friction>
<ode/>
</friction>
</surface>
</collision>
<visual name='rotor_1_visual'>
<pose>0 0 0 0 0 0</pose>
<geometry>
<mesh>
<s