Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ Finally, to launch the robot in Gazebo you should create a launch file. A partia
2. **Write a control node**: Write a control node that makes the robot randomly traverse within a four-walled area without making any collisions.
3. **Create a launch file**: Create a launch file that launches the robot in Gazebo with the URDF file and the control node.
4. **Test the robot**: Test the robot in Gazebo and make sure it is working as expected.
5. **Document the process**: Document the process of creating the URDF file, control node, and launch file. Include any challenges faced and how they were overcome.

5. **Document the process**: Document the process of creating the URDF file, control node, and launch file. Include any challenges faced and how they were overcome.
4 changes: 4 additions & 0 deletions gazebo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/gazebo:
ros__parameters:
publish_rate: 10.0
use_sim_time: true
85 changes: 85 additions & 0 deletions joint_state_publisher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/joint_state_publisher:
ros__parameters:
delta: 0.0
publish_default_efforts: false
publish_default_positions: true
publish_default_velocities: false
rate: 10
robot_description: <?xml version="1.0" ?> <!-- ===================================================================================
--> <!-- | This document was autogenerated by xacro from /ros2_ws/install/urdf_ex/share/urdf_ex/urdf/robot.xacro
| --> <!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED |
--> <!-- ===================================================================================
--> <robot name="four_wheel_robot"> <!-- Material description --> <material
name="white"> <color rgba="1 1 1 1"/> </material> <material name="orange"> <color
rgba="1 0.3 0.1 1"/> </material> <material name="blue"> <color rgba="0.2 0.2
1 1"/> </material> <material name="black"> <color rgba="0 0 0 1"/> </material>
<material name="red"> <color rgba="1 0 0 1"/> </material> <!-- Comment out the
gazebo include for now --> <!-- <xacro:include filename="/ros2_ws/src/urdf_ex/urdf/robot.gazebo"/>
--> <!-- Dummy link --> <link name="base_link"/> <!-- Body link --> <link name="body_link">
<visual> <geometry> <box size="1 0.6 0.3"/> </geometry> <origin rpy="0 0 3.141592653589793"
xyz="0 0 0"/> </visual> <collision> <geometry> <box size="1 0.6 0.3"/> </geometry>
<origin rpy="0 0 3.141592653589793" xyz="0 0 0"/> </collision> <inertial> <origin
rpy="0 0 3.141592653589793" xyz="0 0 0"/> <mass value="487.79999999999995"/>
<inertia ixx="18.292499999999993" ixy="0" ixz="0" iyy="44.308499999999995" iyz="0"
izz="55.283999999999985"/> </inertial> </link> <!-- Fixed joint between dummy
and body --> <joint name="base_joint" type="fixed"> <parent link="base_link"/>
<child link="body_link"/> <origin xyz="0 0 0.25"/> </joint> <link name="rear_right_wheel">
<visual> <geometry> <cylinder length="0.1" radius="0.15"/> </geometry> <origin
rpy="0 0 0" xyz="0 0 0"/> <material name="blue"/> </visual> <collision> <geometry>
<cylinder length="0.1" radius="0.15"/> </geometry> <origin rpy="0 0 0" xyz="0
0 0"/> </collision> <inertial> <origin rpy="0 0 0" xyz="0 0 0"/> <mass value="19.155861183375002"/>
<inertia ixx="0.12371493680929685" ixy="0" ixz="0" iyy="0.12371493680929685"
iyz="0" izz="0.21550343831296875"/> </inertial> </link> <joint name="rear_right_wheel_joint"
type="continuous"> <parent link="body_link"/> <child link="rear_right_wheel"/>
<origin rpy="1.5707963267948966 0 0" xyz="-0.32 -0.36 -0.1"/> <axis xyz="0 0
-1"/> <limit effort="1000" velocity="1000"/> <dynamics damping="1.0" friction="1.0"/>
</joint> <link name="rear_left_wheel"> <visual> <geometry> <cylinder length="0.1"
radius="0.15"/> </geometry> <origin rpy="0 0 0" xyz="0 0 0"/> <material name="blue"/>
</visual> <collision> <geometry> <cylinder length="0.1" radius="0.15"/> </geometry>
<origin rpy="0 0 0" xyz="0 0 0"/> </collision> <inertial> <origin rpy="0 0 0"
xyz="0 0 0"/> <mass value="19.155861183375002"/> <inertia ixx="0.12371493680929685"
ixy="0" ixz="0" iyy="0.12371493680929685" iyz="0" izz="0.21550343831296875"/>
</inertial> </link> <joint name="rear_left_wheel_joint" type="continuous"> <parent
link="body_link"/> <child link="rear_left_wheel"/> <origin rpy="-1.5707963267948966
0 0" xyz="-0.32 0.36 -0.1"/> <axis xyz="0 0 1"/> <limit effort="1000" velocity="1000"/>
<dynamics damping="1.0" friction="1.0"/> </joint> <link name="front_right_wheel">
<visual> <geometry> <cylinder length="0.1" radius="0.15"/> </geometry> <origin
rpy="0 0 0" xyz="0 0 0"/> <material name="blue"/> </visual> <collision> <geometry>
<cylinder length="0.1" radius="0.15"/> </geometry> <origin rpy="0 0 0" xyz="0
0 0"/> </collision> <inertial> <origin rpy="0 0 0" xyz="0 0 0"/> <mass value="19.155861183375002"/>
<inertia ixx="0.12371493680929685" ixy="0" ixz="0" iyy="0.12371493680929685"
iyz="0" izz="0.21550343831296875"/> </inertial> </link> <joint name="front_right_wheel_joint"
type="continuous"> <parent link="body_link"/> <child link="front_right_wheel"/>
<origin rpy="1.5707963267948966 0 0" xyz="0.32 -0.36 -0.1"/> <axis xyz="0 0
-1"/> <limit effort="1000" velocity="1000"/> <dynamics damping="1.0" friction="1.0"/>
</joint> <link name="front_left_wheel"> <visual> <geometry> <cylinder length="0.1"
radius="0.15"/> </geometry> <origin rpy="0 0 0" xyz="0 0 0"/> <material name="blue"/>
</visual> <collision> <geometry> <cylinder length="0.1" radius="0.15"/> </geometry>
<origin rpy="0 0 0" xyz="0 0 0"/> </collision> <inertial> <origin rpy="0 0 0"
xyz="0 0 0"/> <mass value="19.155861183375002"/> <inertia ixx="0.12371493680929685"
ixy="0" ixz="0" iyy="0.12371493680929685" iyz="0" izz="0.21550343831296875"/>
</inertial> </link> <joint name="front_left_wheel_joint" type="continuous">
<parent link="body_link"/> <child link="front_left_wheel"/> <origin rpy="-1.5707963267948966
0 0" xyz="0.32 0.36 -0.1"/> <axis xyz="0 0 1"/> <limit effort="1000" velocity="1000"/>
<dynamics damping="1.0" friction="1.0"/> </joint> <!-- Camera --> <link name="camera_link">
<visual> <origin xyz="0 0 0"/> <geometry> <cylinder length="0.05" radius="0.0125"/>
</geometry> <material name="black"/> </visual> <visual> <geometry> <box size="0.05
0.05 0.05"/> </geometry> <origin rpy="0 0 0" xyz="0 0 0.05"/> </visual> <collision>
<geometry> <box size="0.05 0.05 0.05"/> </geometry> <origin rpy="0 0 0" xyz="0
0 0"/> </collision> <inertial> <origin rpy="0 0 0" xyz="0 0 0"/> <mass value="0.5"/>
<inertia ixx="1e-6" ixy="0.0" ixz="0.0" iyy="1e-6" iyz="0.0" izz="1e-6"/> </inertial>
</link> <joint name="camera_joint" type="fixed"> <parent link="body_link"/>
<child link="camera_link"/> <origin xyz="-0.25 0 0.175"/> <axis xyz="0 1 0"/>
</joint> <!-- Sonar --> <link name="sonar_link"> <visual> <geometry> <box size="0.05
0.1 0.05"/> </geometry> <origin rpy="0 0 0" xyz="0 0 0.025"/> <material name="black"/>
</visual> <visual> <geometry> <box size="0.025 0.025 0.05"/> </geometry> <origin
rpy="0 0 0" xyz="0 0 0"/> <material name="black"/> </visual> <collision> <geometry>
<box size="0.05 0.05 0.05"/> </geometry> <origin rpy="0 0 0" xyz="0 0 0"/> </collision>
<inertial> <origin rpy="0 0 0" xyz="0 0 0"/> <mass value="0.5"/> <inertia ixx="1e-6"
ixy="0.0" ixz="0.0" iyy="1e-6" iyz="0.0" izz="1e-6"/> </inertial> </link> <joint
name="sonar_joint" type="fixed"> <parent link="body_link"/> <child link="sonar_link"/>
<origin xyz="0.4875 0 0.175"/> <axis xyz="0 1 0"/> </joint> </robot>
source_list: []
use_mimic_tags: true
use_sim_time: false
use_smallest_joint_limits: true
75 changes: 51 additions & 24 deletions launch/simulation.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def generate_launch_description():
pkg_name = FindPackageShare("pkg_name")
pkg_name = FindPackageShare("robot_model_pkg") # Updated package name

# Xacro command to generate URDF
xacro_command = [
Expand All @@ -18,8 +18,16 @@ def generate_launch_description():

return LaunchDescription(
[
# TODO: Create the control node
# Node
# Robot Control Node
Node(
package='robot_model_pkg',
executable='robot_control_node.py',
name='robot_control_node',
output='screen',
parameters=[
{'use_sim_time': True}
]
),
# Load Gazebo world
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
Expand All @@ -33,34 +41,53 @@ def generate_launch_description():
)
]
),
# TODO: Provide the correct values for the argumentsarguments
# Launch arguments for Gazebo
launch_arguments={
"world": PathJoinSubstitution(
[pkg_name, "worlds", "four_walls.world"]
),
"paused": "TODO: Provide the correct value",
"use_sim_time": "TODO: Provide the correct value",
"gui": "TODO: Provide the correct value",
"headless": "TODO: Provide the correct value",
"debug": "TODO: Provide the correct value",
"paused": "false",
"use_sim_time": "true",
"gui": "true",
"headless": "false",
"debug": "false",
}.items(),
),
# Robot description parameter
ExecuteProcess(
cmd=[
"ros2",
"param",
"set",
"/robot_state_publisher",
"robot_description",
PathJoinSubstitution([FindExecutable(name="xacro")]),
PathJoinSubstitution([pkg_name, "urdf", "robot.xacro"]),
],
shell=True,
),
# TODO: Create the robot state publisher node
# Robot state publisher
# TODO: Spawn the robot in Gazebo
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[
{'use_sim_time': True},
{'robot_description': xacro_command}
]
),

# Joint state publisher
Node(
package='joint_state_publisher',
executable='joint_state_publisher',
name='joint_state_publisher',
output='screen',
parameters=[{'use_sim_time': True}]
),

# Spawn robot in Gazebo
Node(
package='gazebo_ros',
executable='spawn_entity.py',
name='spawn_robot',
output='screen',
arguments=[
'-topic', 'robot_description',
'-entity', 'four_wheel_robot',
'-x', '0.0',
'-y', '0.0',
'-z', '0.5'
],
parameters=[{'use_sim_time': True}]
),
]
)
43 changes: 43 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>robot_model_pkg</name>
<version>0.0.0</version>
<description>Four-wheeled robot simulation package with sensors and control</description>
<maintainer email="ravindurimdalk@gmail.com">ubuntu</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<!-- ROS2 core dependencies -->
<depend>rclpy</depend>
<depend>geometry_msgs</depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>

<!-- URDF and visualization -->
<depend>urdf</depend>
<depend>robot_state_publisher</depend>
<depend>joint_state_publisher</depend>
<depend>rviz2</depend>

<!-- Gazebo simulation -->
<depend>gazebo_ros</depend>
<depend>gazebo_plugins</depend>
<depend>gazebo_ros_pkgs</depend>

<!-- Launch files -->
<depend>launch</depend>
<depend>launch_ros</depend>

<!-- Computer vision -->
<depend>cv_bridge</depend>
<depend>image_transport</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading