Reputation: 1
<?xml version="1.0"?>
<robot name="my_robot">
<material name="green">
<color rgba="0.0 0.6 0.0 1"/>
</material>
<material name="blue">
<color rgba="0.0 0.0 1.0 1"/>
</material>
<material name="white">
<color rgba="1 1 1 1"/>
</material>
<!-- Base Footprint -->
<link name="base_footprint"/>
<!-- link name="base_footprint"/ -->
<!-- Base Link -->
<link name="base_link">
<inertial>
<mass value="1.0"/>
<origin xyz="0.0 0.0 0.1" rpy="0 0 0"/>
<inertia ixx="0.02" ixy="0.0" ixz="0.0" iyy="0.02" iyz="0.0" izz="0.02"/>
</inertial>
<visual>
<geometry>
<box size="0.6 0.4 0.2"/>
</geometry>
<origin xyz="0.0 0.0 0.1" rpy="0 0 0"/>
<material name="blue"/>
</visual>
<collision>
<geometry>
<box size="0.6 0.4 0.2"/>
</geometry>
<origin xyz="0.0 0.0 0.1" rpy="0 0 0"/>
</collision>
</link>
<gazebo reference="base_link">
<material>Gazebo/Blue</material>
</gazebo>
<!-- Lidar -->
<link name="lidar">
<inertial>
<mass value="0.1"/>
<origin xyz="0.0 0.0 0.05" rpy="0 0 0"/>
<inertia ixx="0.001" ixy="0.0" ixz="0.0" iyy="0.001" iyz="0.0" izz="0.001"/>
</inertial>
<visual>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="0 0 0"/>
<material name="white"/>
</visual>
<collision>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0"/>
</collision>
</link>
<!-- Caster Wheel -->
<link name="caster_wheel">
<inertial>
<mass value="0.1"/>
<origin xyz="0.0 0.0 0" rpy="0 0 0"/>
<inertia ixx="0.001" ixy="0.0" ixz="0.0" iyy="0.001" iyz="0.0" izz="0.001"/>
</inertial>
<visual>
<geometry>
<sphere radius="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="0 0 0"/>
<material name="white"/>
</visual>
<collision>
<geometry>
<sphere radius="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="0 0 0"/>
</collision>
</link>
<gazebo reference="caster_wheel">
<mu1 value="0.001"/>
<mu2 value="0.001"/>
</gazebo>
<!-- Left Wheel -->
<link name="left_wheel">
<inertial>
<mass value="0.2"/>
<origin xyz="0.0 0.0 0" rpy="0 0 0"/>
<inertia ixx="0.002" ixy="0.0" ixz="0.0" iyy="0.002" iyz="0.0" izz="0.002"/>
</inertial>
<visual>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="1.57 0 0"/>
<material name="white"/>
</visual>
<collision>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="1.57 0 0"/>
</collision>
</link>
<!-- Right Wheel -->
<link name="right_wheel">
<inertial>
<mass value="0.2"/>
<origin xyz="0.0 0.0 0" rpy="0 0 0"/>
<inertia ixx="0.002" ixy="0.0" ixz="0.0" iyy="0.002" iyz="0.0" izz="0.002"/>
</inertial>
<visual>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="1.57 0 0"/>
<material name="white"/>
</visual>
<collision>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
<origin xyz="0.0 0.0 0" rpy="1.57 0 0"/>
</collision>
</link>
<!-- Joints -->
<joint name="base_joint" type="fixed">
<parent link="base_link"/>
<child link="base_footprint"/>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0"/>
</joint>
<joint name="base_lidar_joint" type="fixed">
<parent link="base_link"/>
<child link="lidar"/>
<origin xyz="0.2 0.0 0.225" rpy="0 0 0"/>
</joint>
<joint name="left_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="left_wheel"/>
<origin xyz="-0.15 -0.225 0.04" rpy="0 0 0"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<joint name="right_wheel_joint" type="continuous">
<parent link="base_link"/>
<child link="right_wheel"/>
<origin xyz="-0.15 0.225 0.04" rpy="0 0 0"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<joint name="caster_wheel_joint" type="fixed">
<parent link="base_link"/>
<child link="caster_wheel"/>
<origin xyz="0.2 0 -0.01" rpy="0 0 0"/>
</joint>
<!-- Gazebo Plugins -->
<!-- Gazebo plugin for Lidar Sensor -->
<gazebo reference="lidar">
<sensor name="laser" type="ray">
<pose> 0 0 0 0 0 0 </pose>
<visualize>true</visualize>
<update_rate>30</update_rate>
<ray>
<scan>
<horizontal>
<samples>360</samples>
<min_angle>-3.14</min_angle>
<max_angle>3.14</max_angle>
</horizontal>
</scan>
<range>
<min>0.3</min>
<max>12</max>
</range>
</ray>
<plugin name="laser_controller" filename="libgazebo_ros_ray_sensor.so">
<ros>
<remapping>out:=/scan</remapping>
<!-- <namespace>/bot</namespace> -->
</ros>
<output_type>sensor_msgs/LaserScan</output_type>
<frame_name>lidar</frame_name>
</plugin>
</sensor>
</gazebo>
<gazebo>
<plugin name="bot_joint_state" filename="libgazebo_ros_joint_state_publisher.so">
<ros>
<remapping>~/out:=joint_states</remapping>
</ros>
<update_rate>30</update_rate>
<joint_name>right_wheel_joint</joint_name>
<joint_name>left_wheel_joint</joint_name>
<joint_name>caster_wheel_joint</joint_name>
<joint_name>base_lidar_joint</joint_name>
</plugin>
</gazebo>
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<!-- Wheel Information -->
<update_rate>30</update_rate>
<left_joint>left_wheel_joint</left_joint>
<right_joint>right_wheel_joint</right_joint>
<wheel_separation>0.45</wheel_separation>
<wheel_diameter>0.18</wheel_diameter>
<!-- Limits -->
<max_wheel_torque>10.0</max_wheel_torque>
<max_wheel_acceleration>1.0</max_wheel_acceleration>
<!-- Output -->
<command_topic>cmd_vel</command_topic>
<publish_odom>true</publish_odom>
<publish_odom_tf>true</publish_odom_tf>
<odometry_frame>odom</odometry_frame>
<robot_base_frame>base_link</robot_base_frame>
<publish_wheel_tf>true</publish_wheel_tf>
</plugin>
</gazebo>
</robot>
this is my urdf While running this in gazebo laser of the lidar is visible but in rviz not visible like it is sensing but while checking the topic using
ros2 topic echo /laser_controller/out
its publishing correcting but not visible in rviz I also tried by increasing the laser visible size in rviz no use.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable, IncludeLaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
from launch.launch_description_sources import PythonLaunchDescriptionSource
def generate_launch_description():
# Paths
pkg_bot = get_package_share_directory('bot')
pkg_gazebo_ros = get_package_share_directory('gazebo_ros')
world_path = os.path.join(pkg_bot, 'world', 'no_roof_small_warehouse.world')
urdf_file = os.path.join(pkg_bot, 'urdf', 'trial.urdf')
# Ensure files exist
if not os.path.exists(world_path):
raise FileNotFoundError(f"World file not found: {world_path}")
if not os.path.exists(urdf_file):
raise FileNotFoundError(f"URDF file not found: {urdf_file}")
# Read the URDF file to pass to robot_description
with open(urdf_file, 'r') as urdf_f:
robot_description = urdf_f.read()
return LaunchDescription([
# Set environment variables for Gazebo
SetEnvironmentVariable('GAZEBO_MODEL_PATH', os.path.join(pkg_bot, 'models')),
SetEnvironmentVariable('GAZEBO_PLUGIN_PATH', os.path.join(pkg_gazebo_ros, 'lib')),
# Launch Gazebo with the specified world
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_gazebo_ros, 'launch', 'gazebo.launch.py')
),
launch_arguments={'world': world_path}.items()
),
# Provide the robot_description to the robot_state_publisher
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
parameters=[{'robot_description': robot_description}],
output='screen'
),
# Spawn the robot in Gazebo
Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=['-file', urdf_file, '-entity', 'your_robot_name'],
output='screen'
),
# Static transform publisher for laser_frame relative to base_link
Node(
package='tf2_ros',
executable='static_transform_publisher',
arguments=[
'0.2', '0.0', '0.1', # Translation (x, y, z)
'0', '0', '0', # Rotation (roll, pitch, yaw in radians)
'base_link', # Parent frame
'laser_frame' # Child frame
],
output='screen'
)
])
so I have added a new node for static transform as temporary solution but while running slam toolbox the map is not forming.
Is there any solution for this?
ros2 run tf2_tools view_frames
using this I saw that there is no transform between lidar and base_link but in gazebo its clearly visile , the lidar topic also correctly publishing
Upvotes: 0
Views: 56