设置环境变量
source /opt/ros/foxy/setup.bash
创建工作区间mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone ros_tutorials ,熟悉turtlesim git clone https://github.com/ros/ros_tutorials.git -b foxy-devel解决依赖cd ~/ros2_ws/
rosdep install -i —from-path src —rosdistro foxy -y 编译整个工作区间cd ~/ros2_ws/
colcon build 单独编译某个功能包cd ~/ros2_ws/
colcon build —packages-select ros_tutorials 在新的终端中,将你的主要 ROS 2 环境作为“底层”,这样你就可以在它的“之上”构建叠加层:source /opt/ros/foxy/setup.bash
cd ~/ros2_ws/
. install/local_setup.bash 打开小乌龟,这里是启动工作区间里的节点。ros2 run turtlesim turtlesim_node
创建功能包cd ~/ros2_ws/src
ros2 pkg create —build-type ament_cmake 创建功能包名:first_package, 节点名:first_noderos2 pkg create —build-type ament_cmake first_package —node-name fisrt_node
编译工作区间cd ~/ros2_ws
colcon build 或者单独编译first_package功能包cd ~/ros2_ws
colcon build —packages-select first_package 获取安装文件. install/local_setup.bash
启动first_node节点ros2 run first_package first_node
创建功能包名:cpp_package,并添加依赖:rclcpp std_msgs example_interfacesros2 pkg create —build-type ament_cmake cpp_package —dependencies rclcpp std_msgs example_interfaces
创建功能包名:py_package,并添加依赖:rclpy std_msgs example_interfacesros2 pkg create —build-type ament_python py_package —dependencies rclpy std_msgs example_interfaces
免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:ROS2–创建工作区间和功能包-ros怎么创建工作空间 https://www.yhzz.com.cn/a/8697.html