Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What are the problem?
@hoshianaaa

ros c++ で hello world

ros c++ でhello worldをする手順です。

開発環境の設定

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
$ cd ~/catkin_ws
$ catkin_make

パッケージの作成

$ cd ~/catkin_ws/src
$ catkin_create_pkg my_hello std_msgs roscpp
$ cd my_hello

ビルド設定ファイルの修正

CMakeLists.txt
cmake_minimum_required(VERSION 3.0.2)
project(my_hello)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)
catkin_package(
  CATKIN_DEPENDS roscpp std_msgs
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(my_hello src/my_hello.cpp)
target_link_libraries(
  my_hello
  ${catkin_LIBRARIES}
)

ソースファイルの作成

src/my_hello.cpp
#include <ros/ros.h>

int main(int argc, char **argv) {
  ros::init(argc, argv, "my_hello");
  ros::NodeHandle n;
  ros::Rate r(10);
  while (ros::ok())
  {
    ROS_INFO("Hello world");
    r.sleep();
  }
  return 0;
}

パッケージのビルド

$ cd ~/catkin_ws
$ catkin_make

パッケージの実行

$ source ~/catkin_ws/devel/setup.bash
$ rosrun my_hello my_hello

[ INFO] [1627477251.605944564]: Hello world
[ INFO] [1627477251.706078609]: Hello world
...

参考

こちらを参考に作成しました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What are the problem?