一文学会使用键盘控制moveit2机械臂模型

这篇具有很好参考价值的文章主要介绍了一文学会使用键盘控制moveit2机械臂模型。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


前言

在之前文章的基础上相信大家已经学会了如何搭建一个机械臂模型,那么我们如何对其进行控制呢,上网检索了一下没找到能清晰指导实现整套流程的文章,所以自己摸索着写了一篇希望能帮到大家

这篇文章会分享记录如何实现用键盘控制之前我们建立的gp110机械臂的全套流程,想要学习搭建机械臂模型可参考–
一文学会MoveIt Setup Assistant搭建moveit2机械臂模型

一文学会使用键盘控制moveit2机械臂模型


一、官方样例实现

软件版本

官方样例的版本如下,这部分通过键盘做机械臂控制教程为–Realtime Arm Servoing

repository: moveit2_tutorials
branch: humble
commit hash: 1855ba9513584ea6f5a764ae618971fb0039cb8f

repository: moveit2
branch: humble
commit hash: 8d7a2140eab5d7ab344ab82f232e1e842fe21432

bug修复

官方教程有如下bug,已提交issus–realtime_servo can not control by keyboard input. fixed in local test #709

修复方法如下:

  1. 注释servo_cpp_interface_demo中不停发送控制指令部分
# moveit2_tutorials/doc/examples/realtime_servo/src/servo_cpp_interface_demo.cpp
# Line  188
 //rclcpp::TimerBase::SharedPtr timer = node_->create_wall_timer(50ms, publishCommands);
  1. 修改servo_keyboard_input中publisher的定义
# moveit2_tutorials/doc/examples/realtime_servo/src/servo_keyboard_input.cpp
# Line 70 71
const std::string TWIST_TOPIC = "/servo_demo_node/delta_twist_cmds";
const std::string JOINT_TOPIC = "/servo_demo_node/delta_joint_cmds";

运行测试

窗口1运行:

$ ros2 launch moveit2_tutorials servo_cpp_interface_demo.launch.py

窗口2运行:

$ ros2 run moveit2_tutorials servo_keyboard_input 
Reading from keyboard
---------------------------
Use arrow keys and the '.' and ';' keys to Cartesian jog
Use 'W' to Cartesian jog in the world frame, and 'E' for the End-Effector frame
Use 1|2|3|4|5|6|7 keys to joint jog. 'R' to reverse the direction of jogging.
'Q' to quit.

一文学会使用键盘控制moveit2机械臂模型

二、gp110机械臂控制

文件添加

拷贝源代码文件到gp110_moveit_config/src,具体文件如下
moveit2_tutorials/doc/examples/realtime_servo/src/servo_cpp_interface_demo.cpp
moveit2_tutorials/doc/examples/realtime_servo/src/servo_keyboard_input.cpp

拷贝launch文件到gp110_moveit_config/launch,具体文件如下
moveit2_tutorials/doc/examples/realtime_servo/launch/servo_cpp_interface_demo.launch.py

拷贝rviz参数及servo参数文件到gp110_moveit_config/config,具体文件如下
moveit2_tutorials/doc/examples/realtime_servo/config/demo_rviz_config.rviz改名为moveit_empty.rviz
moveit2/moveit_ros/moveit_servo/config/panda_simulated_config.yaml改名为gp110_simulated_config.yaml

修改后文件如下所示:

gp110_moveit_config$ tree .
.
├── CMakeLists.txt
├── config
│   ├── common_colors.xacro
│   ├── common_materials.xacro
│   ├── gp110_macro.xacro
│   ├── gp110_simulated_config.yaml
│   ├── gp110.urdf.xacro
│   ├── initial_positions.yaml
│   ├── joint_limits.yaml
│   ├── kinematics.yaml
│   ├── moveit_controllers.yaml
│   ├── moveit_empty.rviz
│   ├── moveit.rviz
│   ├── pilz_cartesian_limits.yaml
│   ├── robot.ros2_control.xacro
│   ├── robot.srdf
│   ├── robot.urdf.xacro
│   └── ros2_controllers.yaml
├── launch
│   ├── demo.launch.py
│   ├── move_group.launch.py
│   ├── moveit_rviz.launch.py
│   ├── rsp.launch.py
│   ├── servo_cpp_interface_demo.launch.py
│   ├── setup_assistant.launch.py
│   ├── spawn_controllers.launch.py
│   ├── static_virtual_joint_tfs.launch.py
│   └── warehouse_db.launch.py
├── package.xml
└── src
    ├── servo_cpp_interface_demo.cpp
    └── servo_keyboard_input.cpp

3 directories, 29 files

文件修改

# gp110_simulated_config.yaml

...

## MoveIt properties
# move_group_name:  panda_arm  # Often 'manipulator' or 'arm'
# planning_frame: panda_link0  # The MoveIt planning frame. Often 'base_link' or 'world'
move_group_name:  gp110_arm  # Often 'manipulator' or 'arm'
planning_frame: base_link  # The MoveIt planning frame. Often 'base_link' or 'world'

## Other frames
# ee_frame_name: panda_link8  # The name of the end effector link, used to return the EE pose
# robot_link_command_frame:  panda_link0  # commands must be given in the frame of a robot link. Usually either the base or end effector
ee_frame_name: tool0  # The name of the end effector link, used to return the EE pose
robot_link_command_frame:  base_link  # commands must be given in the frame of a robot link. Usually either the base or end effector

...

# command_out_topic: /panda_arm_controller/joint_trajectory # Publish outgoing commands here
command_out_topic: /gp110_arm_controller/joint_trajectory # Publish outgoing commands here

# moveit_empty.rviz
Panels:
  - Class: rviz_common/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /Status1
      Splitter Ratio: 0.5
    Tree Height: 628
  - Class: rviz_common/Selection
    Name: Selection
  - Class: rviz_common/Tool Properties
    Expanded:
      - /2D Goal Pose1
      - /Publish Point1
    Name: Tool Properties
    Splitter Ratio: 0.5886790156364441
  - Class: rviz_common/Views
    Expanded:
      - /Current View1
    Name: Views
    Splitter Ratio: 0.5
Visualization Manager:
  Class: ""
  Displays:
    - Alpha: 0.5
      Cell Size: 1
      Class: rviz_default_plugins/Grid
      Color: 160; 160; 164
      Enabled: true
      Line Style:
        Line Width: 0.029999999329447746
        Value: Lines
      Name: Grid
      Normal Cell Count: 0
      Offset:
        X: 0
        Y: 0
        Z: 0
      Plane: XY
      Plane Cell Count: 10
      Reference Frame: <Fixed Frame>
      Value: true
    - Class: moveit_rviz_plugin/PlanningScene
      Enabled: true
      Move Group Namespace: ""
      Name: PlanningScene
      Planning Scene Topic: /moveit_servo/publish_planning_scene
      Robot Description: robot_description
      Scene Geometry:
        Scene Alpha: 0.8999999761581421
        Scene Color: 50; 230; 50
        Scene Display Time: 0.20000000298023224
        Show Scene Geometry: true
        Voxel Coloring: Z-Axis
        Voxel Rendering: Occupied Voxels
      Value: true
  Enabled: true
  Global Options:
    Background Color: 48; 48; 48
    Fixed Frame: base_link
    Frame Rate: 30
  Name: root
  Tools:
    - Class: rviz_default_plugins/Interact
      Hide Inactive Objects: true
    - Class: rviz_default_plugins/MoveCamera
    - Class: rviz_default_plugins/Select
    - Class: rviz_default_plugins/FocusCamera
    - Class: rviz_default_plugins/Measure
      Line color: 128; 128; 0
    - Class: rviz_default_plugins/SetInitialPose
      Topic:
        Depth: 5
        Durability Policy: Volatile
        History Policy: Keep Last
        Reliability Policy: Reliable
        Value: /initialpose
    - Class: rviz_default_plugins/SetGoal
      Topic:
        Depth: 5
        Durability Policy: Volatile
        History Policy: Keep Last
        Reliability Policy: Reliable
        Value: /goal_pose
    - Class: rviz_default_plugins/PublishPoint
      Single click: true
      Topic:
        Depth: 5
        Durability Policy: Volatile
        History Policy: Keep Last
        Reliability Policy: Reliable
        Value: /clicked_point
  Transformation:
    Current:
      Class: rviz_default_plugins/TF
  Value: true
  Views:
    Current:
      Class: rviz_default_plugins/Orbit
      Distance: 2.155569553375244
      Enable Stereo Rendering:
        Stereo Eye Separation: 0.05999999865889549
        Stereo Focal Distance: 1
        Swap Stereo Eyes: false
        Value: false
      Focal Point:
        X: -0.08608254045248032
        Y: -0.20677587389945984
        Z: 0.3424459993839264
      Focal Shape Fixed Size: true
      Focal Shape Size: 0.05000000074505806
      Invert Z Axis: false
      Name: Current View
      Near Clip Distance: 0.009999999776482582
      Pitch: 0.4603978991508484
      Target Frame: <Fixed Frame>
      Value: Orbit (rviz)
      Yaw: 0.8753982782363892
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 857
  Hide Left Dock: false
  Hide Right Dock: true
  Selection:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: true
  Width: 1586
  X: 1179
  Y: 393
# servo_cpp_interface_demo.launch.py
import os
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
from launch.actions import ExecuteProcess
from moveit_configs_utils import MoveItConfigsBuilder
from launch_param_builder import ParameterBuilder


def generate_launch_description():
    moveit_config = (
        MoveItConfigsBuilder("moveit_resources_gp110")
        .robot_description(file_path="config/robot.urdf.xacro")
        .robot_description_semantic(file_path="config/robot.srdf")
        .trajectory_execution(file_path="config/moveit_controllers.yaml")
        .to_moveit_configs()
    )

    # Get parameters for the Servo node
    servo_params = (
        ParameterBuilder("moveit_resources_gp110_moveit_config")
        .yaml(
            parameter_namespace="moveit_servo",
            file_path="config/gp110_simulated_config.yaml",
        )
        .to_dict()
    )

    # A node to publish world -> base_link transform
    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", "base_link"],
    )

    # The servo cpp interface demo
    # Creates the Servo node and publishes commands to it
    servo_node = Node(
        package="moveit_resources_gp110_moveit_config",
        executable="gp110_servo_cpp_interface_demo",
        output="screen",
        parameters=[
            servo_params,
            moveit_config.robot_description,
            moveit_config.robot_description_semantic,
        ],
    )

    # Publishes tf's for the robot
    robot_state_publisher = Node(
        package="robot_state_publisher",
        executable="robot_state_publisher",
        output="screen",
        parameters=[moveit_config.robot_description],
    )

    # RViz
    rviz_base = os.path.join(
        get_package_share_directory("moveit_resources_gp110_moveit_config"), "config"
    )
    rviz_full_config = os.path.join(rviz_base, "moveit_empty.rviz")

    rviz_node = Node(
        package="rviz2",
        executable="rviz2",
        name="rviz2",
        output="log",
        arguments=["-d", rviz_full_config],
        parameters=[
            moveit_config.robot_description,
            moveit_config.robot_description_semantic,
        ],
    )

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

    # Load controllers
    load_controllers = []
    for controller in ["gp110_arm_controller", "joint_state_broadcaster"]:
        load_controllers += [
            ExecuteProcess(
                cmd=["ros2 run controller_manager spawner {}".format(controller)],
                shell=True,
                output="screen",
            )
        ]

    return LaunchDescription(
        [rviz_node, static_tf, servo_node, ros2_control_node, robot_state_publisher]
        + load_controllers
    )
// servo_cpp_interface_demo.cpp

...

  // Next we will create a collision object in the way of the arm. As the arm is servoed towards it, it will slow down
  // and stop before colliding
  moveit_msgs::msg::CollisionObject collision_object;
  collision_object.header.frame_id = "base_link";
  collision_object.id = "box";

...

  // 屏蔽下一行
  // rclcpp::TimerBase::SharedPtr timer = node_->create_wall_timer(50ms, publishCommands);
// servo_keyboard_input.cpp

...

// 修改如下
// Some constants used in the Servo Teleop demo
// const std::string TWIST_TOPIC = "/servo_node/delta_twist_cmds";
// const std::string JOINT_TOPIC = "/servo_node/delta_joint_cmds";
const std::string TWIST_TOPIC = "/servo_demo_node/delta_twist_cmds";
const std::string JOINT_TOPIC = "/servo_demo_node/delta_joint_cmds";
const size_t ROS_QUEUE_SIZE = 10;
const std::string EEF_FRAME_ID = "tool0";
const std::string BASE_FRAME_ID = "base_link";

...

      case KEYCODE_1:
        RCLCPP_DEBUG(nh_->get_logger(), "1");
        // joint_msg->joint_names.push_back("panda_joint1");
        joint_msg->joint_names.push_back("joint_1_s");
        joint_msg->velocities.push_back(joint_vel_cmd_);
        publish_joint = true;
        break;
      case KEYCODE_2:
        RCLCPP_DEBUG(nh_->get_logger(), "2");
        // joint_msg->joint_names.push_back("panda_joint2");
        joint_msg->joint_names.push_back("joint_2_l");
        joint_msg->velocities.push_back(joint_vel_cmd_);
        publish_joint = true;
        break;
      case KEYCODE_3:
        RCLCPP_DEBUG(nh_->get_logger(), "3");
        // joint_msg->joint_names.push_back("panda_joint3");
        joint_msg->joint_names.push_back("joint_3_u");
        joint_msg->velocities.push_back(joint_vel_cmd_);
        publish_joint = true;
        break;
      case KEYCODE_4:
        RCLCPP_DEBUG(nh_->get_logger(), "4");
        // joint_msg->joint_names.push_back("panda_joint4");
        joint_msg->joint_names.push_back("joint_4_r");
        joint_msg->velocities.push_back(joint_vel_cmd_);
        publish_joint = true;
        break;
      case KEYCODE_5:
        RCLCPP_DEBUG(nh_->get_logger(), "5");
        // joint_msg->joint_names.push_back("panda_joint5");
        joint_msg->joint_names.push_back("joint_5_b");
        joint_msg->velocities.push_back(joint_vel_cmd_);
        publish_joint = true;
        break;
      case KEYCODE_6:
        RCLCPP_DEBUG(nh_->get_logger(), "6");
        // joint_msg->joint_names.push_back("panda_joint6");
        joint_msg->joint_names.push_back("joint_6_t");
        joint_msg->velocities.push_back(joint_vel_cmd_);
        publish_joint = true;
        break;
      // case KEYCODE_7:
      //   RCLCPP_DEBUG(nh_->get_logger(), "7");
      //   joint_msg->joint_names.push_back("panda_joint7");
      //   joint_msg->velocities.push_back(joint_vel_cmd_);
      //   publish_joint = true;
      //   break;
# CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(moveit_resources_gp110_moveit_config)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(control_msgs REQUIRED)
find_package(moveit_msgs REQUIRED)
find_package(moveit_servo REQUIRED)

add_executable(gp110_servo_keyboard_input src/servo_keyboard_input.cpp)
target_include_directories(gp110_servo_keyboard_input PUBLIC include)
ament_target_dependencies(gp110_servo_keyboard_input std_msgs control_msgs rclcpp)

add_executable(gp110_servo_cpp_interface_demo src/servo_cpp_interface_demo.cpp)
target_include_directories(gp110_servo_cpp_interface_demo PUBLIC include)
ament_target_dependencies(gp110_servo_cpp_interface_demo moveit_servo rclcpp)

install(
  TARGETS
    gp110_servo_keyboard_input
    gp110_servo_cpp_interface_demo
  DESTINATION
    lib/${PROJECT_NAME}
)

install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}
  PATTERN "setup_assistant.launch" EXCLUDE)
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})
install(FILES .setup_assistant DESTINATION share/${PROJECT_NAME})

ament_package()
<!-- package.xml 增加如下--> 

  <exec_depend>rclcpp</exec_depend>
  <exec_depend>control_msgs</exec_depend>
  <exec_depend>moveit_msgs</exec_depend>
  <exec_depend>moveit_servo</exec_depend>

编译工程

$ colcon build --packages-up-to --cmake-args -DCMAKE_BUILD_TYPE=Release
$ . install/setup.bash

运行测试

窗口1运行:

$ ros2 launch moveit_resources_gp110_moveit_config servo_cpp_interface_demo.launch.py

窗口2运行:

$ ros2 run moveit_resources_gp110_moveit_config gp110_servo_keyboard_input 
Reading from keyboard
---------------------------
Use arrow keys and the '.' and ';' keys to Cartesian jog
Use 'W' to Cartesian jog in the world frame, and 'E' for the End-Effector frame
Use 1|2|3|4|5|6|7 keys to joint jog. 'R' to reverse the direction of jogging.
'Q' to quit.

一文学会使用键盘控制moveit2机械臂模型


总结

以上就是今天要讲的内容,本文从头配置和修改实现了键盘控制机械臂,如果是joycon或其他输入控制与本文所分享思想相同,控制响应和publisher即可。文章来源地址https://www.toymoban.com/news/detail-514190.html

到了这里,关于一文学会使用键盘控制moveit2机械臂模型的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Moveit +Gazebo:搭建单臂机械臂仿真平台

    环境:Ubuntu20.04 ros-noetic 先放上效果展示:    首先要先安装ROS 和 Moveit,ROS的安装就不说了,Moeit的安装参看官网教程 Getting Started — moveit_tutorials Noetic documentation 安装过程中,用到了命令: rosdep update 最好在安装的时候能够科学上网 搭建单臂仿真平台主要分为4大步     

    2024年02月11日
    浏览(36)
  • keychron机械键盘使用感受

    最近入手了一个Keychron无线机械键盘,跟mac本搭配起来使用,体验非常好。记录下使用的感受。 包装 包装很结实,拆开快递盒后,快递盒里有充气袋包裹着键盘盒,键盘盒塑料薄膜封装,没有一点的磕碰。 拆封 不仅外包装结实,内包装也很用心,泡沫垫、塑料外套等防磕碰

    2024年02月09日
    浏览(43)
  • RK-H87无线机械键盘使用手册

    旋钮顺时针功能:音量+ 旋钮逆时针功能:音量- 旋钮按压时功能:静音(长按5s转换旋钮功能:灯效模式) 旋钮顺时针功能:亮度+ 旋钮逆时针功能:亮度- 旋钮按压时功能:切换背光灯灯效模式(长按5s转换旋钮功能:音量调节) 按FN+ENTER查看电池电量情况 键盘一共分为三种链

    2024年02月11日
    浏览(101)
  • 【硬件记录】烽影青轴机械键盘的灯光控制键 如何设置?如何设置键盘 跑马灯特效?附:烽影RGB三代快捷键 | 【SCI】计算机/期刊 论文中的 Preliminaries作为目录,一般表示什么意思?

      李白:任世人厌我、妒我、恨我、爱我、笑我、哭我,我只当风曾来过。   🎯作者主页: 追光者♂🔥          🌸个人简介:   💖[1] 计算机专业硕士研究生💖   🌟[2] 2022年度博客之星人工智能领域TOP4🌟   🏅[3] 阿里云社区特邀专家博主🏅   🏆[4] CSDN-人工智能领

    2024年02月02日
    浏览(46)
  • 「2023最新」「阿米洛 VARMILO」双模机械键盘使用指南(快捷键组合)

    在说明书找不到的时候却需要使用键盘的某些特性时查一下 以阿米洛 minilo 尤加利为例 开机 2 秒内连续敲击空格键三下,数字 1 或 2 或 3 键灯闪烁,键盘开机 重新配对 长按 5 秒 Fn + Q / W / E 键 (分别对应数字 1 / 2 / 3 频道),断开当前蓝牙设备连接,相应键位灯闪烁,重新进

    2024年02月09日
    浏览(147)
  • 一文学会git常用命令和使用指南

    背景:最近有刚入职公司的小伙伴们总是在git使用过程中一系列问题,而且问题很多都是低级问题。所以我觉得有必要分享一个帖子,和大家学习一下。找了一下公司git管理规范文档,发现文档的描述不是很好理解,而且已经和现在的管理方式有一定的出入。所以我自行总结

    2024年02月14日
    浏览(47)
  • 【Git】速食Git,一文学会Git使用

    版本控制是一种在开发的过程中用于管理我们对文件、目录或工程等内容的修改历史,方便查看更改历史记录,备份以便恢复以前的版本的软件工程技术。【通俗来说就跟我们所玩的游戏一样,不断地更新迭代游戏内容,比如赛季更新呀,新出皮肤呀等】 ①实现跨区域多人协

    2024年02月01日
    浏览(46)
  • 一文学会使用Git将本地代码上传GitHub仓库

    要上传本地代码到GitHub仓库,那必然要先在GitHub上建立一个存储代码的仓库,这里我在仓库新建了一个名为 5blog 的仓库。 备注:本文章将以默认分支 main 为例来讲解上传步骤 接着我们打开所要上传文件的所在目录,右键打开 Git Bash 进入Bash面板,依次执行以下步骤。 git in

    2024年02月04日
    浏览(75)
  • 【factoryio】使用SCL编写 <机械手控制> 程序

    使用虚拟工厂软件和博图联合仿真来编写【scl】机械手控制程序 文章目录 目录 文章目录  前言 二、程序编写 1.机械手运行部分 2.启动停止部分 3.急停复位部分  三、完整代码 总结 在前面我们一起写过了许多案例控制的编写,在这一章我们一起来编写一下一个仿真机械手程

    2024年02月03日
    浏览(44)
  • beef-xss详细教程(一文带你学会beef) | Kali下安装beef | beef-xss反射型,储存型利用 | beef实现Cookie会话劫持 | 键盘监听 | 浏览器弹窗,重定向等

    ✅作者简介:CSDN内容合伙人、信息安全专业在校大学生🏆 🔥系列专栏 :XSS漏洞应用-Beef 📃新人博主 :欢迎点赞收藏关注,会回访! 💬舞台再大,你不上台,永远是个观众。平台再好,你不参与,永远是局外人。能力再大,你不行动,只能看别人成功!没有人会关心你付

    2024年02月02日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包