参考wiki.ros.org上的 Ubuntu install of ROS Kinetic 以及之前的博客:Docker尝试,在Docker中配置ROS
# 运行容器 GUI 且使用Nidia显卡
xhost+
sudo docker run --ipc=host --runtime=nvidia -e $DISPLAY:$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -it nvidia/cudagl:11.0-base-ubuntu16.04
## 容器内部
# 更新
apt-get update
# 安装 sudo lsb-release
apt-get install sudo
sudo apt-get install lsb-release
# 添加ros源和公钥
sudo 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
# 更新
sudo apt-get update
# 安装
sudo apt-get install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt-get install ros-kinetic-desktop-full
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo rosdep init
sudo rosdep update
# 测试 全屏快捷键 F11
gazebo
# 退出
终端Crtl+C
# 退出容器
exit 或者 crtl+D
# container-id or name 查看
sudo docker ps -a
# 将修改后的容器保存为镜像 ros:kinetic-desktop-full-ubuntu16.04
sudo docker commit <container-id or name> ros:kinetic-desktop-full-ubuntu16.04
docker的修改能自动保存吗? Docker,一台电脑>>>许多电脑 >o<
ROS 通讯模型,两种,One:Topic/Message模型,Publisher与Subscriber;Two:Client/Server,......?
ROS Turtle小乌龟
# Tips: Command尝试使用Tab键自动补全,终端某程序使用Ctrl+C退出
# docker打开容器新终端使用docker exec -it id_or_name bash
roscore
# new terminal
rosrun turtlesim turtlesim_node
# new terminal 查看节点/话题等信息,-h 查看命令帮助信息,
rosnode list
rostopic lsit
rosmsg list
rosservice list
rqt_graph
# new terminal,添加新的小乌龟
rosservice call /spawn "x: y: z: theta: name:''"
# Publisher -r 10次/秒,小乌龟turtle1转圈圈圈
rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 2.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 2.0"
# node:turtle_teleop_key,键盘控制,默认只能控制turtle1,还不知道如何修改?
rosrun turtlesim turtle_teleop_key
课程练习1
1. Setup the Husky simulation: http://wiki.ros.org/husky_gazebo/Tutorials/Simulating%20Husky
xhost+
sudo docker run --runtime=nvidia -e $DISPLAY:$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -it ros:kinetic-desktop-full-ubuntu16.04
sudo apt-get install ros-kinetic-husky-simulator
export HUSKY_GAZEBO_DESCRIPTION=$(rospack find husky_gazebo)/urdf/description.gazebo.xacro
roslaunch husky_gazebo husky_empty_world.launch
roslaunch husky_gazebo husky_playpen.launch
roslaunch husky_gazebo husky_empty_world.launch world_name:=worlds/willowgarage.world
2. Launch the simulation and inspect the created nodes and their topics using:
rosnode list
rostopic list
rostopic echo [TOPIC]
rostopic hz [TOPIC]
rqt_graph
For more information take a look at the slides or:
http://wiki.ros.org/rostopic
http://wiki.ros.org/rosnode
3. Command a desired velocity to the robot from the terminal
( rostopic pub [TOPIC] )
4. Use teleop_twist_keyboard to control your robot using the keyboard. Find it online and compile it from source! Use git clone to clone the repository to the folder ~/git.
For a short git overview see:
http://rogerdudler.github.io/git-guide/files/git_cheat_sheet.pdf
5. Write a launch file with the following content (Lecture 1 Slides 27-30):
- husky simulation with a different world:
Include husky_empty_world.launch file and change the world_name
Argument, e.g. worlds/robocup14_spl_field.world a world from the
directory /usr/share/gazebo-7/worlds.
Note: the world_name is with respect to /usr/share/gazebo-7/
- teleop_twist_keyboard node
Evaluation
❏ Check if teleop_twist_keyboard is compiled from source ( roscd
teleop_twist_keyboard should show the catkin_ws folder)
❏ Start the launch file. This should bring everything up that’s needed to drive Husky
with the keyboard as shown in the above image.
Hints
●
If the robot stops again after sending the velocity command, specify the rate of the
publisher. Check out rostopic pub --help.
编写成脚本,方便
ros.sh
#!/bin/bash ##################### Build in Things ###################### #. $Function_Top/Include/Enviroment_Config.inc Call_Path=$(pwd) #Where this call from? #Where is here? if [ -n "$Function_Path" ];then Here_Path=$Function_Path else Here_Path=$(dirname $(readlink -f $0)) fi echo "Here_Path: $Here_Path" #Who am I? if [ -n "$Function_Name" ];then File_Name=$Function_Name.func else # File_Name=${0##*/}; Function_Name=${File_Name%.*}; fi echo "File_Name: $File_Name" echo "File_Name: ${0##*/}" echo "Function_Name: $Function_Name" # echo $0 # echo ${0#*/} # echo ${0##*/} # pwd function build() { image_name="nvidia/cudagl:11.0-base-ubuntu16.04" if [ -n "$1" ];then image_name=$1 fi container_name="ros" if [ -n "$2" ];then container_name=$2 fi echo "Build docker image is $image_name, and the container name is $container_name." xhost + sudo docker run --ipc=host --runtime=nvidia --privileged -e DISPLAY=$DISPLAY -e GDK_SCALE -e GDK_DPI_SCAL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/bus/usb:/dev/bus/usb -v $Here_Path:$Here_Path -w $Here_Path --name=$container_name -it $image_name /bin/bash # docker run --ipc=host --runtime=nvidia --privileged -e DISPLAY=$DISPLAY -e GDK_SCALE -e GDK_DPI_SCAL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/bus/usb:/dev/bus/usb --name=ros -it ros:kinetic-desktop-full-ubuntu16.04 /bin/bash } function start() { image_name="ros:kinetic-desktop-full-ubuntu16.04" if [ -n "$1" ];then image_name=$1 fi container_name="ros" if [ -n "$2" ];then container_name=$2 fi echo "Start docker image is $image_name, and the container name is $container_name." xhost + sudo docker run --ipc=host --runtime=nvidia --privileged -e DISPLAY=$DISPLAY -e GDK_SCALE -e GDK_DPI_SCAL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/bus/usb:/dev/bus/usb -v $Here_Path:$Here_Path -w $Here_Path --name=$container_name -it $image_name /bin/bash # docker run --ipc=host --runtime=nvidia --privileged -e DISPLAY=$DISPLAY -e GDK_SCALE -e GDK_DPI_SCAL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/bus/usb:/dev/bus/usb --name=ros -it ros:kinetic-desktop-full-ubuntu16.04 /bin/bash } function detect_runing_environment() { str_device=$(cat /proc/1/cgroup | grep devices) # str_device=$(which docker) # echo $str_device str_docker=$(echo $str_device | grep docker) # echo $str_docker # str_device=$(which docker) # echo $str_device | grep docker # ${#str_device} if [ ${#str_docker} -ge "6" ];then echo "It's running in a docker container." else echo "It's not running in a docker container." fi # test_len="docker" # echo ${#test_len} } function help() { echo "This is help function!" } function test() { echo "This is a test function." } function introduction() { echo "This is introduction function!" } if [ -n "$1" ];then while [ -n "$1" ]; do case $1 in ##BEGIN_HELP## -h) shift 1;help;exit 1;; #Show usages -i) shift 1;introduction;exit 1;; #Show introduction -*) echo "Error: No such option $1. -h for help.";exit 1;; *) $*;exit 1;; #Call function here ##END_HELP## esac done else echo "continue" fi
ros_install.sh
#!/bin/bash apt-get update apt-get install sudo sudo apt-get install lsb-release -y 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 # UN apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116 sudo apt-get update sudo apt-get install ros-kinetic-desktop-full -y sudo apt-get install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential -y sudo rosdep init sudo rosdep update \ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc