Robot Code Snippets

Models

Convert xacro to urdf file
1
rosrun xacro xacro --inorder -o model.urdf model.urdf.xacro

launch file spawning a urdf model

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<launch>    
<!-- These are the arguments you can pass this launch file, for example paused:=true -->
<arg name="paused" default="true"/>
<arg name="use_sim_time" default="true"/>
<arg name="gui" default="true"/>
<arg name="headless" default="false"/>
<arg name="debug" default="false"/>

<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find wam_gazebo)/worlds/knife_grasping.world"/>
<arg name="debug" value="$(arg debug)" />
<arg name="gui" value="$(arg gui)" />
<arg name="paused" value="$(arg paused)"/>
<arg name="use_sim_time" value="$(arg use_sim_time)"/>
<arg name="headless" value="$(arg headless)"/>
</include>

<param name="robot_desc" command="cat $(find robot_description)/urdf/robot.urdf" />
<node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
args="-urdf -model robot_name_in_gazebo -param robot_desc"/>
</launch>
Convert mesh file type
1
2
3
for file in ./*.dae; do
ctmconv $file "${file%.*}.stl";
done

Matlab

Stop at the line where error occurs, no more break point needed.

1
dbstop if error

1
2
3
4
5
6
7
figure(1);                           % open a new figure
model = createpde(3); % create an empty model
model.importGeometry('model.stl'); % import geometry from stl file
pdegplot(model,'FaceLabels','on'); % plot model with facet label on
generateMesh(model); % generate mesh of the model
[p,e,t] = model.Mesh.meshToPet(); % representation of point, edge and mesh
A = e.getElementFaces(3); % triangles which lie on face 3
1
2
3
4
5
6
7
8
9
10
11
model = createpde(3);
model.importGeometry('model.stl');
mesh = generateMesh(model);
nodes = findNodes(mesh,'region','Face', 1);
figure
pdegplot(model,'FaceLabels','on');
hold on;
x = mesh.Nodes(1,nodes);
y = mesh.Nodes(2,nodes);
z = mesh.Nodes(3,nodes);
plot3(x, y, z, 'ok','MarkerFaceColor','g')

Nodes on facet

reference

ROS

Matlab Network