ICube-Robotics / ethercat_driver_ros2_examples

Example repository for the EtherCAT Driver ROS2 stack
Apache License 2.0
19 stars 12 forks source link

how to make ethercat_motor_drive to run alone so that I can make it running on an isolated CPU? #21

Open 467480903 opened 4 months ago

467480903 commented 4 months ago

this is the .launch file:

from launch import LaunchDescription
from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration
from launch.actions import DeclareLaunchArgument

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare

def generate_launch_description():

    # Declare arguments
    declared_arguments = []
    declared_arguments.append(
        DeclareLaunchArgument(
            'description_file',
            default_value='motor_drive.config.xacro',
            description='URDF/XACRO description file with the axis.',
        )
    )

    description_file = LaunchConfiguration('description_file')

    # Get URDF via xacro
    robot_description_content = Command(
        [
            PathJoinSubstitution([FindExecutable(name="xacro")]),
            " ",
            PathJoinSubstitution(
                [
                    FindPackageShare("ethercat_motor_drive"),
                    "description/config",
                    description_file,
                ]
            ),
        ]
    )
    robot_description = {"robot_description": robot_description_content}

    robot_controllers = PathJoinSubstitution(
        [
            FindPackageShare("ethercat_motor_drive"),
            "config",
            # "controllers_12_jihua_t_6.yaml",
            # "controllers_12_jihua_t.yaml",
            "controllers.yaml",
        ]
    )

    control_node = Node(
        package="controller_manager",
        executable="ros2_control_node",
        parameters=[robot_description, robot_controllers],
        output="both",
    )
    robot_state_pub_node = Node(
        package="robot_state_publisher",
        executable="robot_state_publisher",
        output="both",
        parameters=[robot_description],
    )

    joint_state_broadcaster_spawner = Node(
        package="controller_manager",
        executable="spawner",
        arguments=["joint_state_broadcaster", "-c", "/controller_manager"],
    )

    trajectory_controller_spawner = Node(
        package="controller_manager",
        executable="spawner",
        arguments=["trajectory_controller", "-c", "/controller_manager"],
    )

    effort_controller_spawner = Node(
        package="controller_manager",
        executable="spawner",
        arguments=["effort_controller", "-c", "/controller_manager"],
    )

    nodes = [
        control_node,
        robot_state_pub_node,
        joint_state_broadcaster_spawner,
        trajectory_controller_spawner,
        # velocity_controller_spawner,
        # effort_controller_spawner,
    ]

    return LaunchDescription(
        declared_arguments +
        nodes)

if run this launch file together with CPU isolation in this way:

taskset -c 1 ros2 launch ethercat_motor_drive motor_drive.launch.py

I found there are more than 1 process running on cpu 1, which is not what I wanted, I want robot_state_publisher , joint_state_broadcaster_spawner, joint_state_broadcaster_spawner, trajectory_controller_spawner to running normally , leave control_node to run on CPU1 ,

how to do it?

thank you very much