In this section we will just add a third link and have a joint between it and the second link. Below is the modified code:
<?xml version="1.0"?>
<robot name="my_robot">
<material name="blue">
<color rgba="0 0 0.5 1" />
</material>
<material name="grey">
<color rgba="0.5 0.5 0.5 1" />
</material>
<link name="base_link">
<visual>
<geometry>
<box size="0.6 0.4 0.2" />
</geometry>
<origin xyz="0 0 0.1" rpy="0 0 0" />
<material name="blue" />
</visual>
</link>
<link name="second_link">
<visual>
<geometry>
<cylinder radius="0.1" length="0.2" />
</geometry>
<origin xyz="0 0 0.1" rpy="0 0 0" />
<material name="grey" />
</visual>
</link>
<link name="third_link">
<visual>
<geometry>
<box size="0.1 0.1 0.1" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
<material name="blue" />
</visual>
</link>
<joint name="base_second_joint" type="fixed">
<parent link="base_link" />
<child link="second_link" />
<origin xyz="0 0 0.2" rpy="0 0 0" />
</joint>
<joint name="second_third_joint" type="fixed">
<parent link="second_link" />
<child link="third_link" />
<origin xyz="0 0 0" rpy="0 0 0" />
</joint>
</robot>
The Result in RViz is the following:

Note that, although the origin of the squared box is set to 0 across all axes, it is not centered around the axis of the rectangular box but rather around the cylinder. This is because the squared box is a child of the cylinder, and its origin is defined relative to the cylinder.
To have the TF of the squared box above the TF of the cylinder we have just to move the joint origin between the squared box and the cylinder along the Z axis by the height of the cylinder i.e. 0.2 meters. The modified code is below:
<?xml version="1.0"?>
<robot name="my_robot">
<material name="blue">
<color rgba="0 0 0.5 1" />
</material>
<material name="grey">
<color rgba="0.5 0.5 0.5 1" />
</material>
<link name="base_link">
<visual>
<geometry>
<box size="0.6 0.4 0.2" />
</geometry>
<origin xyz="0 0 0.1" rpy="0 0 0" />
<material name="blue" />
</visual>
</link>
<link name="second_link">
<visual>
<geometry>
<cylinder radius="0.1" length="0.2" />
</geometry>
<origin xyz="0 0 0.1" rpy="0 0 0" />
<material name="grey" />
</visual>
</link>
<link name="third_link">
<visual>
<geometry>
<box size="0.1 0.1 0.1" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
<material name="blue" />
</visual>
</link>
<joint name="base_second_joint" type="fixed">
<parent link="base_link" />
<child link="second_link" />
<origin xyz="0 0 0.2" rpy="0 0 0" />
</joint>
<joint name="second_third_joint" type="fixed">
<parent link="second_link" />
<child link="third_link" />
<origin xyz="0 0 0.2" rpy="0 0 0" />
</joint>
</robot>
The Result on RViz is the following:

Note that, although the TF between the squared box and the cylinder is correct, we still have to move the origin of the squared box along the Z axis by half it’s height. The modified code is the following:
<?xml version="1.0"?>
<robot name="my_robot">
<material name="blue">
<color rgba="0 0 0.5 1" />
</material>
<material name="grey">
<color rgba="0.5 0.5 0.5 1" />
</material>
<link name="base_link">
<visual>
<geometry>
<box size="0.6 0.4 0.2" />
</geometry>
<origin xyz="0 0 0.1" rpy="0 0 0" />
<material name="blue" />
</visual>
</link>
<link name="second_link">
<visual>
<geometry>
<cylinder radius="0.1" length="0.2" />
</geometry>
<origin xyz="0 0 0.1" rpy="0 0 0" />
<material name="grey" />
</visual>
</link>
<link name="third_link">
<visual>
<geometry>
<box size="0.1 0.1 0.1" />
</geometry>
<origin xyz="0 0 0.05" rpy="0 0 0" />
<material name="blue" />
</visual>
</link>
<joint name="base_second_joint" type="fixed">
<parent link="base_link" />
<child link="second_link" />
<origin xyz="0 0 0.2" rpy="0 0 0" />
</joint>
<joint name="second_third_joint" type="fixed">
<parent link="second_link" />
<child link="third_link" />
<origin xyz="0 0 0.2" rpy="0 0 0" />
</joint>
</robot>
The Result on RViz is the following:
