系统是乌班图18的系统。
//安装C加加编译器
sudo apt-get install g++
//安装python解释器
sudo apt-get install python
//安装vim文本编译器
sudo apt install vim
代码运行实例(c++)
//终端输入,在主目录下创造一个test的文件夹。
mkdir test
//创建一个名为hello的点cpp文件。
touch hello.cpp
//在文件中写入内容
//写完后保存关闭
//打开终端输入,编译C加加文件
g++ hello.cpp -o hello
//执行可执行文件。
./hello
//同理。执行python文件
python hello.py
ros安装
//添加ros软件源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
//添加密匙
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
//安装ros
sudo apt update
sudo apt install ros-melodic-desktop-full
//初始化rosdep
sudo rosdep init
rosdep update
//设置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
//安装rosinstall
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
鱼香ros一键安装
wget http://fishros.com/install -O fishros && . fishros
小乌龟实例
//启动ros mastre
roscore
//启动小海龟仿真器
rosrun turtlesim turtlesim_node
//启动海龟控制节点
rosrun turtlesim turtle_teleop_key
创建工作空间
//创建工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
//编译工作空间
cd catkin_ws/
catkin_make
//设置环境变量
source devel/setup.bash
//检查环境变量
echo $ROS_PACKAGE_PATH
功能包创建与编译
//创建功能包
cd ~/catkin_ws/src
catkin_create_pkg my_package_name rospy roscpp std_msgs geometry_msgs turtlesim
//编译
cd catkin_ws/
catkin_make
//刷新环境变量
source ~/catkin_ws/devel/setup.bash
C++编译配置<cmakelists.txt>
add_executable(${PROJECT_NAME}_node src/my_package_name_node.cpp)
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES})
自定义消息
1.在功能包文件夹内创建msg文件夹,并新建Person.msg文件,在里面写入
string name
uint8 age
uint8 sex
uint8 unknown = 0
uint8 male = 1
uint8 female = 2
2.在package.xml
文件内添加依赖:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
3.在CMakeLists.txt
内加入:
add_message_files(
FILES
Person.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
并把
# CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs turtlesim
改为
CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs turtlesim message_runtime
-----------------------------------------------------------------------------------------------------
系统关机及重启
//关机
shutdown -h now
//重启
sudo reboot
Ctrl all +T 打开新的终端