Ubuntu20.04 +ros1 noetic环境下编译
1.下载和编译
mkdirfetch_ws/srccdfetch_ws/srcgitclone https://github.com/fetchrobotics/fetch_gazebo.gitgitclone https://github.com/fetchrobotics/fetch_ros.gitgitclone https://github.com/fetchrobotics/fetch_msgs.git切换到gazebo11分支
cdfetch_gazebogitcheckout gazebo11 catkin_make出现
Could not find a package configuration file provided by “robot_controllers”
解决
sudoapt-getinstallros-noetic-robot-controllers其他编译依赖库报错
cd~/fetch_ws rosdepinstall--from-paths src --ignore-src-y2.运行fetch_gazebo
roslaunch fetch_gazebo playground.launch3.启动键盘控制机器人移动
rosrun teleop_twist_keyboard teleop_twist_keyboard.py发现底盘可以移动
4.控制机械臂移动
(1)启动 MoveIt!
# 启动 MoveIt! 核心节点(运动规划、碰撞检测等)roslaunch fetch_moveit_config move_group.launch(2)RViz 中的交互操作
# 终端2: 启动 RViz 可视化交互界面roslaunch fetch_moveit_config moveit_rviz.launch打开的 RViz 界面中:
a.添加 Display(若未自动加载):
点击左下角 Add → 添加 MotionPlanning。
确保 Global Options 中的 Fixed Frame 设置为 base_link。
b.控制机械臂:
交互式标记:拖动 RViz 中的黄色立方体(末端执行器)设定目标位姿。
c.规划与执行:
点击 Plan 按钮预览运动轨迹(灰色线)。
确认无误后点击 Execute 执行运动(机械臂将实际移动)。
拖动后如图
5.c++代码控制机械臂移动
(1)创建 C++ 包**
在 ROS 工作空间中创建一个新包:
cd~/fetch_ws/src catkin_create_pkg arm_control roscpp moveit_core moveit_ros_planning_interfacecd~/fetch_ws&&catkin_make(2)C++ 代码示例 :控制机械臂到目标位姿**
创建文件src/arm_control.cpp:
#include<ros/ros.h>#include<moveit/move_group_interface/move_group_interface.h>#include<moveit/planning_scene_interface/planning_scene_interface.h>intmain(intargc,char**argv){ros::init(argc,argv,"fetch_arm_control");ros::NodeHandle nh;ros::AsyncSpinnerspinner(1);spinner.start();// 初始化 MoveIt! 接口moveit::planning_interface::MoveGroupInterfacearm("arm");arm.setPlannerId("RRTConnectkConfigDefault");// 设置运动规划器// 设置目标位姿 (相对于 base_link)geometry_msgs::Pose target_pose;target_pose.position.x=0.5;target_pose.position.y=0.2;target_pose.position.z=0.8;target_pose.orientation.w=1.0;// 四元数 (w=1表示无旋转)arm.setPoseTarget(target_pose);// 运动规划moveit::planning_interface::MoveGroupInterface::Plan plan;if(arm.plan(plan)){ROS_INFO("Planning succeeded, executing...");arm.execute(plan);}else{ROS_ERROR("Planning failed!");}ros::shutdown();return0;}(3)编译配置
修改 CMakeLists.txt
在arm_control/CMakeLists.txt中添加:
find_package(catkin REQUIRED COMPONENTS roscpp moveit_core moveit_ros_planning_interface ) add_executable(arm_control src/arm_control.cpp) target_link_libraries(arm_control ${catkin_LIBRARIES} )编译运行
cd~/fetch_ws&&catkin_makesourcedevel/setup.bash rosrun arm_control arm_control发现机械臂可以运动
6.操作演示
底盘机械臂仿真fetch rviz
底盘机械臂仿真fetch
底盘机械臂仿真fetch gazebo
底盘机械臂仿真fetch