ROS AGV 笔记

Ubuntu18.04 install of ROS Melodic
1 Installation
1.1 Configure your Ubuntu repositories
1.2 Setup your sources.list
$    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/   sources.list.d/ros-latest.list'
1.3 Set up your keys
$     sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
1.4 Installation
1.4.1 update   
$       sudo apt-get update
1.4.2 Desktop-Full Install: (Recommended) : ROS, rqt, rviz, robot-generic libraries, 2D/3D simulators and 2D/3D perception
      sudo apt-get install ros-melodic-desktop-full
1.5 Initialize rosdep
$     sudo rosdep init
$     rosdep update
1.6 Environment setup
$     echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
$     source ~/.bashrc
1.7 Dependencies for building packages
$   sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
1.8 Build farm status?
***********************
ROS Tutorials
1 Core ROS Tutorials
1.1 Beginner Level
1.1.1 Installing and Configuring Your ROS Environment
1.1.1.1 Install ROS
1.1.1.2 Managing Your Environment
        A good way to check environment variables like ROS_ROOT and ROS_PACKAGE_PATH are set:
$  printenv | grep ROS
//as below
ROS_ETC_DIR=/opt/ros/melodic/etc/ros
ROS_ROOT=/opt/ros/melodic/share/ros
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROS_PYTHON_VERSION=2
ROS_PACKAGE_PATH=/opt/ros/melodic/share:/opt/ros/melodic/stacks
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=melodic
//
rosbuild and catkin. These are the two available methods for organizing and building your ROS code. rosbuild is not recommended or maintained anymore but kept for legacy. catkin is the recommended way to organise your code, it uses more standard CMake conventions and provides more flexibility especially for people wanting to integrate external code bases or who want to release their software. For a full break down visit catkin or rosbuild.

************************************
ros 编写 helloworld 程序
(参考:https://blog.csdn.net/mxgsgtc/article/details/71450763)
************************************

1,先建立工作空间~/catkin_ws
(参考:https://www.douban.com/note/516838470/)
a,ros工作环境检查
$ export | grep ROS
b,将ros的配置文档加入到teminal启动脚本里
$ source /opt/ros/melodic/setup.bash
c,创建工程空间
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
d,将ros用户自己的工程目录配置到bash里
$ gedit ~/.bashrc
在其最后一行加入
export ROS_PACKAGE_PATH=~/catkin_ws:$ROS_PACKAGE_PATH
e,编译工程
$ cd ~/catkin_ws/
$ catkin_make
f,将catkin_make加入到shell里(重启电脑后需要重新source一次!)
//$ source devel/setup.bash
$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
$ source ~/.bashrc

$ echo $ROS_PACKAGE_PATH

2,在工作空间~/catkin_ws下创建包pkg目录beginner_tutorials
好处是通过创建包自动生成package.xml和CMakeLists.txt
(参考:www.douban.com/note/516843231/)
创建ros包
a,ros包必备的有两个文件:CMakeLists.txt和 package.xml
基于catkin工程来创建自己的ros包,需要在workspace的src下创建包目录
再在包目录里创建CMakeLists.txt和 package.xml文件。
建一个包就要在src下建一个包的目录,其下也得有这两个文件,有关如何先创建catkin的workspace上面1已经介绍,也可参阅http://www.douban.com/note/516838470/
b,切换到catkin工程目录的src
$ cd ~/catkin_ws/src
c,使用catkin_create_pkg创建包
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
安装tree命令,查看目录树
$ sudo apt  install tree
$ tree beginner_tutorials/
d,编译包
$ cd ~/catkin_ws/
$ catkin_make
e,把包加入当前的shell
$ . ~/catkin_ws/devel/setup.bash
f,检测,看ros文件系统下是否已经有了这个包
$ cd
$ roscd beginner_tutorials/
可以切换~/catkin_ws/src/beginner_tutorials$路径,建包完成
g,返回源码目录,查看下整体目录树,准备写hello world 代码
$ cd ~/catkin_ws/src
$ tree beginner_tutorials

3,在/beginner_tutorials/src目录下创建hello.cpp源代码文件
a,进入~/catkin_ws/src/beginner_tutorials/src源码目录
$ cd ~/catkin_ws/src/beginner_tutorials/src
b,安装vim,创建hello.cpp源代码
$ sudo apt install vim
$ vim hello.cpp
c,拷贝下面代码到vim编辑器,然后按ZZ,保存并退出

#include <ros/ros.h>
int main(int argc, char **argv) {
        ros::init(argc, argv, "helloros123");
        ros::NodeHandle n;
        ROS_INFO("Hello, ROS!");
        ros::spinOnce();
}

d,修改编译makefile文件 CMakeLists.txt
$ cd ~/catkin_ws/src/beginner_tutorials
$ gedit CMakeLists.txt
检查下面内容
cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs)
include_directories(${catkin_INCLUDE_DIRS})
add_executable(hello ./src/hello.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})

对比发现缺少最后两行,所以末尾加入下面代码,然后保存并退出
##Add hello.cpp by uunubt ##
add_executable(hello ./src/hello.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})
##
e,回到~/catkin_ws编译程序
$ cd ~/catkin_ws
$ catkin_make
f,测试hello world c++程序
打开一个终端里运行
$ roscore
另外一个终端里运行 rosrun beginner_tutorials hello
$ rosrun beginner_tutorials hello
终端有Hello, ROS!消息,完成Hello例程。
************************************


roscanopen
1, git 下载roscanopen源码到~/catkin_ws/src/
2,$ sudo apt-get install libmuparser-dev
3,   $ cd ~/catkin_ws
      $ catkin_make

猜你喜欢

转载自blog.csdn.net/uunubt/article/details/81304007