Open rainit2006 opened 5 years ago
通过Docker安装ros 1,先安装docker 2,执行pull命令: docker pull ros,则会默认安装最新的ros 3, 通过ls查到ros安装路径: /opt/ros/melodic 4, 执行source /opt/ros/melodic/setup.bash 5, 则可以执行ros的roscd等命令了
问题:
方法二:手动添加: export ROS_PACKAGE_PATH=~/catkin_ws/src: ,实测有效,但问题同一.
方法三 (一劳永逸): locate .bashrc(首先查找.bashrc文件) vim /home/用户名/.bashrc 在最后一行加入 :source ~/catkin_ws/devel/setup.bash 也就是方法一用到的口令
■roslaunch roslaunch is a tool for easily launching multiple ROS nodes locally and remotely via SSH, as well as setting parameters on the Parameter Server.
Many ROS packages come with "launch files", which you can run with:
$ roslaunch package_name file.launch
$(env ENVIRONMENT_VARIABLE)
Substitute(代わりに用いる) the value of a variable from the current environment. The launch will fail if environment variable is not set. This value cannot be overridden by
$(optenv ENVIRONMENT_VARIABLE) $(optenv ENVIRONMENT_VARIABLE default_value)
Substitute the value of an environment variable if it is set. If default_value is provided, it will be used if the environment variable is not set. If default_value is not provided, an empty string will be used. default_value can be multiple words separated by spaces.
roslaunch命令常用参数: --screen Force all node output to screen. Useful for node debugging. --wait Delay the launch until a roscore is detected.
■ROSのLaunchファイル ROSのlaunchファイルの特徴:
サンプル:
<launch>
<arg name = "参数1" default="$(optenv XXXXX defaultValue)" />
<group ns="image_tutorial1">
<node pkg="image_tutorial" name="input_node" type="subscriber"/>
<node pkg="image_tutorial" name="output_node" type="publisher"/>
</group>
<group ns="image_tutorial2">
<node pkg="image_tutorial" name="input_node" type="subscriber"/>
<node pkg="image_tutorial" name="output_node" type="publisher"/>
</group>
<node pkg="image_tutorial" name="output_node" type="subscriber">
<remap from="image_data" to="data_stack"/>
</node>
<node pkg="image_tutorial" name="input_node" type="publisher">
<remap from="image_data" to="data_stack"/>
</node>
</launch>
構成説明: ◎launchタグ
ROS Package ROSの機能はPackage単位で構成されている。 http://wiki.ros.org/ROS/Tutorials/CreatingPackage
前処理:ワークスペース作成と設定
1, srcディレクトリ作成
mkdir -p ~/<catkin_ws>/src
2, ワークスペース初期化
cd ~/<catkin_ws>/src
catkin_init_workspace
この段階でワークスペースは空ですが、 3, ビルド
cd ~/<catkin_ws>
catkin_make
4,
source ~/<catkin_ws>/devel/setup.bash
もっと便利な方法: echo "~/<catkin_ws>/devel/setup.bash" >> ~/.bashrc
パッケージ操作するときには、主に以下のコマンドを利用。 catkin_create_pkg: catkin_make rosdep
パッケージ作成:
cd ~/<catkin_ws>/src
catkin_create_pkg test_pkg roscpp rospy
このコマンドで、新たなパッケージ「test_pkg」を作成した。このパッケージはroscpp, rospyというパッケージに依存する。 このコマンド実行すると、「test_pkg」ディレクトリが作成され、その下には次のファイルとディレクトリが作成される。 CMakeLists.txt : CMakeのビルドファイル package.xml : パッケージのマニフェストファイル include : ヘッダファイルを置くディレクトリ src :ソースファイルを置く 他にも、以下のディレクトリを必要に応じて作成する。 msg : メッセージ型の定義ファイルを置く srv : サービス型の定義ファイルを置く
プログラムのソースコードを書いた後は、ビルド
cd ~/<catkin_ws>
catkin_make
ビルドには必要な依存関係をインストールする必要があるかもしれません。 rosdep install package_name で必要なライブラリをインストールする。 また、以下のコマンドでrosdepのキャッシュ情報をアップデートします。 rosdep update
创建ROS的message和srv http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv
Publish to topic
pub = rospy.Publisher('topic_name', std_msgs.msg.String, queue_size=10)
pub.publish(std_msgs.msg.String("foo"))
https://www.slideshare.net/yyamauchi/rosrobot-operating-system