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

Control arm LBR only on RVIZ without gazebo #193

Closed
antonio1matos opened this issue Jun 26, 2024 · 8 comments
Closed

Control arm LBR only on RVIZ without gazebo #193

antonio1matos opened this issue Jun 26, 2024 · 8 comments

Comments

@antonio1matos
Copy link

antonio1matos commented Jun 26, 2024

Hello @mhubii .
I was using this code: ros2 launch lbr_bringup bringup.launch.py model:=iiwa14 moveit:=true to launch the robot iiwa14 in simulation (gazebo) and Rviz. However i wanted to launch this robot only in Rviz without using gazebo. I tried following this tutorials of moviet humble: https://moveit.picknik.ai/main/doc/how_to_guides/moveit_configuration/moveit_configuration_tutorial.html and also this one: https://moveit.picknik.ai/main/doc/how_to_guides/moveit_launch_files/moveit_launch_files_tutorial.html

I tried to follow the way presented in the tutorials and this is my code:

import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch.conditions import IfCondition, UnlessCondition
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from launch.actions import ExecuteProcess
from ament_index_python.packages import get_package_share_directory
from moveit_configs_utils import MoveItConfigsBuilder
from lbr_description import LBRDescriptionMixin, RVizMixin
from lbr_bringup import LBRMoveGroupMixin

def generate_launch_description():

declared_arguments = []
declared_arguments.append(
    DeclareLaunchArgument(
        "rviz_config",
        default_value="miariiwa1.rviz",
        description="RViz configuration file",
    )
)

return LaunchDescription(
    declared_arguments + [OpaqueFunction(function=launch_setup)]
)

def launch_setup(context, *args, **kwargs):

moveit_config = (
    MoveItConfigsBuilder("iiwa14")
    .robot_description(os.path.join(
            get_package_share_directory("lbr_description"),
            "urdf/iiwa14/iiwa14.urdf.xacro",
        )
    )
    .trajectory_execution(file_path="/home/antonio/lbr-stack/src/lbr_fri_ros2_stack/lbr_moveit_config/iiwa14_moveit_config/config/moveit_controllers.yaml")
    .planning_scene_monitor(
        publish_robot_description=True, publish_robot_description_semantic=True
    )
    .planning_pipelines(
        pipelines=["ompl"]
    )
    .robot_description_kinematics(file_path="/home/antonio/lbr-stack/src/lbr_fri_ros2_stack/lbr_moveit_config/iiwa14_moveit_config/config/kinematics.yaml")
    .to_moveit_configs()   
)

# Start the actual move_group node/action server
run_move_group_node = Node(
    package="moveit_ros_move_group",
    executable="move_group",
    output="screen",
    parameters=[moveit_config.to_dict()],
)

rviz_base = LaunchConfiguration("rviz_config")
rviz_config = PathJoinSubstitution(
    #[FindPackageShare("lbr_description"), "config", rviz_base]
    [FindPackageShare("miar_robot"), "launch", rviz_base]
    
)

# RViz
rviz_node = Node(
    package="rviz2",
    executable="rviz2",
    name="rviz2",
    output="log",
    arguments=["-d", rviz_config],
    parameters=[
        moveit_config.robot_description,
        moveit_config.robot_description_semantic,
        moveit_config.robot_description_kinematics,
        moveit_config.planning_pipelines,
        moveit_config.joint_limits,
    ],
)

# Static TF
static_tf = Node(
    package="tf2_ros",
    executable="static_transform_publisher",
    name="static_transform_publisher",
    output="log",
    arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "link_0"],
)

# Publish TF
robot_state_publisher = Node(
    package="robot_state_publisher",
    executable="robot_state_publisher",
    name="robot_state_publisher",
    output="both",
    parameters=[moveit_config.robot_description],
)

# ros2_control using FakeSystem as hardware
ros2_controllers_path = os.path.join(
    get_package_share_directory("lbr_ros2_control"),
    "config",
    "lbr_controllers.yaml",
)
ros2_control_node = Node(
    package="controller_manager",
    executable="ros2_control_node",
    parameters=[moveit_config.robot_description, ros2_controllers_path],
    output="both",
)

joint_state_broadcaster_spawner = Node(
    package="controller_manager",
    executable="spawner",
    arguments=[
        "joint_state_broadcaster",
        "--controller-manager-timeout",
        "300",
        "--controller-manager",
        "/controller_manager",
    ],
)

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

nodes_to_start = [
    rviz_node,
    static_tf,
    robot_state_publisher,
    run_move_group_node,
    ros2_control_node,
    joint_state_broadcaster_spawner,
    arm_controller_spawner,
]

return nodes_to_star

PS: I put this launch file in a package called miar_robot as you can check in the code. However when i run this code in rviz i can plan a trajectory but i can´t execute it as you can see in the picture below:
image

In the terminal appears the following error: [ERROR] [ros2_control_node-5]: process has died [pid 15443, exit code -6, cmd '/opt/ros/humble/lib/controller_manager/ros2_control_node --ros-args --params-file /tmp/launch_params_e0scg7kp --params-file /home/antonio/lbr-stack/install/lbr_ros2_control/share/lbr_ros2_control/config/lbr_controllers.yaml'].
[spawner-7] [INFO] [1719412041.691157785] [spawner_joint_trajectory_controller]: Waiting for '/controller_manager' node to exist
[spawner-6] [INFO] [1719412041.739105946] [spawner_joint_state_broadcaster]: Waiting for '/controller_manager' node to exist Anyone know any way to launch the robot lbr only rviz and also be able to plan and execute in the rviz without using any simulator as gazebo?

@mhubii
Copy link
Member

mhubii commented Jun 26, 2024

Hi @antonio1matos , looking good , happy to see the gripper is making good progress. Sorry, little busy until the weekend.

So the controller_manager is loaded as plugin into Gazebo. No Gazebo -> no controller_manager.

That said, there is a way to use fake hardware, no simulation. This feature is missing here right now. Thank you for opening the issue. Let's look into that

@mhubii
Copy link
Member

mhubii commented Jul 6, 2024

@antonio1matos
Copy link
Author

Ok. Thank you @mhubii.
I will follow that link. Then i will give you feedback.

@antonio1matos
Copy link
Author

antonio1matos commented Jul 23, 2024

Hi @mhubii. I eventually solved my problem. I'm able to launch the robot iiwa14 without the gazebo system. The robot works only in moveit(rviz) and works fine independently of planner that im using. I used the hardware plugin: mock components as you said. Since i wanted to use a gripper in the arm i executed the MoveIt Setup Assistant to overwrite the iiwa14_moveit_config with the robot with the arm+gripper controllers. I launched the robot+gripper using the format presented in the moveit humble tutorials: https://moveit.picknik.ai/main/doc/how_to_guides/moveit_launch_files/moveit_launch_files_tutorial.html Instead of using the lbr_system_interface.xacro i used the file iiwa14.ros2_control.xacro generated by the MoveIt setup Assistant. This file is composed by this:

<xacro:macro name="iiwa14_ros2_control" params="name initial_positions_file">
<xacro:property name="initial_positions" value="${load_yaml(initial_positions_file)['initial_positions']}"/>

    <ros2_control name="${name}" type="system">
        <hardware>
            <!-- By default, set up controllers for simulation. This won't work on real hardware -->
            <plugin>mock_components/GenericSystem</plugin>
        </hardware>
        <joint name="A1">
            <command_interface name="position"/>
            <state_interface name="position">
              <param name="initial_value">${initial_positions['A1']}</param>
            </state_interface>
            <state_interface name="velocity"/>
        </joint>
        <joint name="A2">
            <command_interface name="position"/>
            <state_interface name="position">
              <param name="initial_value">${initial_positions['A2']}</param>
            </state_interface>
            <state_interface name="velocity"/>
        </joint>
        <joint name="A3">
            <command_interface name="position"/>
            <state_interface name="position">
              <param name="initial_value">${initial_positions['A3']}</param>
            </state_interface>
            <state_interface name="velocity"/>
        </joint>
        <joint name="A4">
            <command_interface name="position"/>
            <state_interface name="position">
              <param name="initial_value">${initial_positions['A4']}</param>
            </state_interface>
            <state_interface name="velocity"/>
        </joint>                                                                                                                                                                                               
        .........       (continue)  

What i wanted to know is if there is any problem of using this file (iiwa14.ros2_control.xacro) instead of the lbr_system_interface.xacro? According from what i read: "While ros2_control allows you to connect to real robot hardware, or robots in a physics-based simulator like Gazebo or NVIDIA Isaac Sim, it also exposes a mock components capability for simple, idealized simulations. (https://moveit.picknik.ai/main/doc/how_to_guides/moveit_launch_files/moveit_launch_files_tutorial.html)". So from what i understood, when using fake_hardware, i.e. mock components, it will not affect the arm behavior when planning trajectories and executing them. In other words, the behavior of arm execution will be the same as if I used it instead of the gazebo hardware plugin: gazebo_ros2_control/GazeboSystem as you used in the file: lbr_system_interface.xacro . Am i right?

@antonio1matos
Copy link
Author

antonio1matos commented Jul 23, 2024

I know that in the launch file instead of using the iiwa14.ros2_control.xacro file (which was generated by the MoveIt setup assistant) I could have still used the lbr_system_interface.xacro file, since here:
image
As long as I created another <xacro:if value="${use_fake_system}"> ,for example, where I called the hardware plugin: mock_components/GenericSystem. And in this way, depending on the laucnh file you said you wanted: sim (if you wanted to plan with the gazebo), use_fake_system (if you wanted only with moveit), and if neither of the two (neither sim nor use_fake_system) used the hardware of the real robot that I suppose it's this: lbr_ros2_control::SystemInterface.

@antonio1matos
Copy link
Author

antonio1matos commented Jul 23, 2024

This was another question I wanted to confirm. You have the launch file named: sim.launch.py, where you are using the hardware: gazebo_ros2_control/GazeboSystem from the lbr_system_interface.xacro file, right? And if I didn't want to use a physical simulator like the gazebo, and wanted to test with a real robot, I would use the launch file: real.launch.py that would resort to the hardware plugin: lbr_ros2_control::SystemInterface, am i right?

These parts of code in the lbr_system_interface.xacro file present in the images below (sensors, torques..) are all related to the hardware to test on the real robot, right?
image
image
image
But if i wanted to only simulate in gazebo (for example using the launch file: sim.launch.py,), i only needed this parts of code, right? (see images below)
image
image

@antonio1matos
Copy link
Author

@mhubii If you could clarify these doubts for me I would be grateful. Thanks

@mhubii
Copy link
Member

mhubii commented Sep 10, 2024

Hi @antonio1matos,

closing this particular issue as now supported via:

ros2 launch lbr_bringup mock.launch.py

Make sure to run RViz in a second terminal (if desired)

ros2 launch lbr_bringup rviz.launch.py

Trying to fix the end-effector issue in another topic.

Introduced in #190

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

2 participants