Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple robots with different namespaces isn't working #368

Closed
AshBastian opened this issue Aug 22, 2024 · 1 comment
Closed

Using multiple robots with different namespaces isn't working #368

AshBastian opened this issue Aug 22, 2024 · 1 comment

Comments

@AshBastian
Copy link

This is the next problem after solving the update_rate problem #366
Now that I can load my robot into the namespace, I tried to load a second one in the the same simulation (therefore the namespace for the robot). While the robot spawns into the simulation without a problem, the plugins take the namespace of the first robot, regardless of what you define in the xacro.urdf.
I hope I get help as fast as last time.
Here the code with the problem:

  1. The launch file:
import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription, RegisterEventHandler
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
from launch.event_handlers import OnProcessExit

import xacro
import rclpy

def generate_launch_description():
    # Create the launch description and populate
    ld = LaunchDescription()

    bringup_dir = get_package_share_directory('gazebo_simulation')
    pkg_gazebo_ros = get_package_share_directory('gazebo_ros')

    urdf1 = os.path.join(bringup_dir, 'urdf', 'test_cart_position_omni1.xacro.urdf')
    urdf2 = os.path.join(bringup_dir, 'urdf', 'test_cart_position_omni2.xacro.urdf')

    gazebo = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    pkg_gazebo_ros, 'launch'), '/gazebo.launch.py']),
             )
    
    doc1 = xacro.parse(open(urdf1))
    xacro.process_doc(doc1)
    params1 = {'robot_description': doc1.toxml()}

    doc2 = xacro.parse(open(urdf2))
    xacro.process_doc(doc2)
    params2 = {'robot_description': doc2.toxml()}

    remappings = [('/tf', 'tf'),
                  ('/tf_static', 'tf_static')]

    omni1_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        namespace='omni1',
        output='screen',
        parameters=[params1],
        remappings=remappings
        )
    
    omni2_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        namespace='omni2',
        output='screen',
        parameters=[params2],
        remappings=remappings
        )
    
    spawn_omni1 = Node(
            package='gazebo_ros',
            executable='spawn_entity.py',
            namespace='omni1',
            arguments=[
                '-topic', 'robot_description',
                '-entity', 'omni1_robot',
                '-x', '0.0', '-y', '0.0',
                '-z', '1.01', '-Y', '0.0',
                '-unpause',
            ],
            output='screen',
        )
    
    spawn_omni2 = Node(
            package='gazebo_ros',
            executable='spawn_entity.py',
            namespace='omni2',
            arguments=[
                '-topic', 'robot_description',
                '-entity', 'omni2_robot',
                '-x', '1.5', '-y', '10.5',
                '-z', '1.01', '-Y', '0.0',
                '-unpause',
            ],
            output='screen',
        )
    
    # ld.add_action(start_gazebo_server_cmd)
    # ld.add_action(start_gazebo_client_cmd)

    ld.add_action(gazebo)
    
    ld.add_action(omni1_state_publisher)
    ld.add_action(spawn_omni1)

    spawn_omni_event = RegisterEventHandler(
                event_handler=OnProcessExit(
                    target_action=spawn_omni1,
                    on_exit=[omni2_state_publisher,
                             spawn_omni2],
                )
            )

    ld.add_action(spawn_omni_event)
    # ld.add_action(omni2_state_publisher)
    # ld.add_action(spawn_omni2)
    
    
    return ld
  1. The urdf: (the namespace in changed according to the name in the launch, because there are 2 nearly identical file for the different namespaces)
<?xml version="1.0" ?>
<robot name="cart">
  <link name="world"/>
  <link name="slideBar">
    <visual>
      <geometry>
        <box size="30 0.05 0.05"/>
      </geometry>
      <origin xyz="0 0 0"/>
      <material name="green">
        <color rgba="0 0.8 .8 1"/>
      </material>
    </visual>
    <inertial>
      <mass value="100"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <link name="cart">
    <visual>
      <geometry>
        <box size="0.5 0.5 0.2"/>
      </geometry>
      <origin xyz="0 0 0"/>
      <material name="blue">
        <color rgba="0 0 .8 1"/>
      </material>
    </visual>
    <inertial>
      <mass value="1"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <joint name="world_to_base" type="fixed">
    <origin rpy="0 0 0" xyz="0 0 1"/>
    <parent link="world"/>
    <child link="slideBar"/>
  </joint>
  <joint name="slider_to_cart" type="prismatic">
    <axis xyz="1 0 0"/>
    <origin xyz="0.0 0.0 0.0"/>
    <parent link="slideBar"/>
    <child link="cart"/>
    <limit effort="1000.0" lower="-15" upper="15" velocity="30"/>
    <dynamics damping="0.0" friction="0.0"/>
  </joint>
  <ros2_control name="GazeboSystem" type="system">
    <hardware>
      <plugin>gazebo_ros2_control/GazeboSystem</plugin>
    </hardware>
    <joint name="slider_to_cart">
      <command_interface name="position">
        <param name="min">-15</param>
        <param name="max">15</param>
      </command_interface>
      <state_interface name="position">
        <param name="initial_value">1.0</param>
      </state_interface>
      <state_interface name="velocity"/>
      <state_interface name="effort"/>
    </joint>
  </ros2_control>

  <gazebo>
    <plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
      <ros>
        <namespace>omni1</namespace>
      </ros>
      <parameters>$(find gazebo_simulation)/models/rs_robot/config/controllers_omni1.yaml</parameters>
    </plugin>
  </gazebo>
</robot>
  1. The controllers_omni1.yaml: (Again namespace is change depending on the used namespace)
/omni1/controller_manager:
  ros__parameters:
    update_rate: 1000  # Hz

    joint_state_broadcaster:
      type: joint_state_broadcaster/JointStateBroadcaster

    forward_velocity_controller:
      type: forward_command_controller/ForwardCommandController

/omni1/forward_velocity_controller:
  ros__parameters:
    joints:
      - first_wheel_joint
      - second_wheel_joint
      - third_wheel_joint
      - fourth_wheel_joint
    interface_name: velocity
    command_interfaces:
      - velocity
    state_interfaces:
      - velocity

Screenshot from 2024-08-22 13-10-01
Screenshot from 2024-08-22 13-10-11

@AshBastian
Copy link
Author

#127 is still the problem here, so you need to comment out the namespace extra part in the gazebo_ros2_control_plugin.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant