ROS命令管理器-利用模板创建脚本(命令行版)
ROS命令管理器-利用模板创建脚本(命令行版)
说明
- 通过模板来简化创建源码安装软件包的脚本
步骤
- 1.执行命令
cs -b
- 效果
#####################################################
########Build install script
#####################################################
#输入ROS版本信息,common为非ROS
Please input ROS Version , only input common, ros1 Or ros2 :ros2
You choose to build ros2 packages
#脚本名称
Please input file name like(install_xxx_xxx) :install_test1_shell
#脚本放置的目录
Please input folder name in ~/commands/ like (common) :ros2
#工作空间名称
Please input workspace name :ros2_test1_ws
#软件包名称
Please input soft name like :rmf_burger_maps
#软件包的gittee或github的地址
Please input soft url like(https://gitee.com/ncnynl/test.git) :http://gitee.com/ncnynl/rmf_burger_maps
#分支
Please input soft branch like (master) :humble
#如下是生成脚本的流程
Copy template to ~/tools/commands/commands_extra/ros2/shell/install_test1_shell.sh
Replace install_test1_shell to file
Replace 2023-03-10 to file
Replace ros2_test1_ws to file
Replace rmf_burger_maps to file
Replace http://gitee.com/ncnynl/rmf_burger_maps to file
Replace humble to file
Script is created , please use vscode to check and complete more
#新脚本的生成的路径
File path is: /home/ubuntu/tools/commands/commands_extra/ros2/shell/install_test1_shell.sh
2.编辑脚本
生成脚本之后,我们利用编辑器根据实际情况来编辑脚本内容
3.同步脚本
需要把脚本拷贝到~/commands目录下,才能通过
cs -s
来安装
cd ~/tools/commands/
./install_extra.sh
- 4.使用脚本
cs -s install_test1_shell.sh
- 完整脚本内容
#!/bin/bash
################################################
# Function : install_test1_shell
# Desc : <file_desc>
# Platform : ubuntu
# Version : 1.0
# Date : 2023-03-10
# Author : ncnynl
# Contact : 1043931@qq.com
# URL: https://ncnynl.com
# Licnese: MIT
# Company :Foshan AiZheTeng Information Technology Co.,Ltd.
# QQ Qun: 创客智造B群:926779095
# QQ Qun: 创客智造C群:937347681
# QQ Qun: 创客智造D群:562093920
################################################
# echo "Not Supported Yet!"
# exit 0
echo ""
echo "Set workspace"
workspace=ros2_test1_ws
echo ""
echo "Set soft name"
soft_name=rmf_burger_maps
echo ""
echo "Workspace if exits ?"
if [ ! -d ~/$workspace ];then
mkdir -p ~/$workspace/src
fi
echo ""
echo "Software if installed ?"
if [ -d ~/$workspace/src/$soft_name ];then
echo "$soft_name have installed" && exit 0
fi
echo ""
echo "Install system deps"
# 下载源码
echo ""
echo "Download source"
cd ~/$workspace/src
git clone -b humble http://gitee.com/ncnynl/rmf_burger_maps
echo ""
echo "Install rosdeps"
cd ~/$workspace/
rosdep install --from-paths src --ignore-src --rosdistro ${ROS_DISTRO} -y
# 编译代码
echo "Compile source"
cd ~/$workspace/
colcon build --symlink-install
echo "Add workspace to bashrc if not exits"
if ! grep -Fq "$workspace/install/local_setup.bash" ~/.bashrc
then
echo ". ~/$workspace/install/local_setup.bash" >> ~/.bashrc
echo " $workspace workspace have installed successfully! writed to ~/.bashrc"
else
echo "Has been inited before! Please check ~/.bashrc"
fi
#How to use
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号