Skip to content

ROS Commands

Shunya Hara edited this page Jun 24, 2024 · 6 revisions

ssh key setup

ssh-keygen -t rsa && cat ~/.ssh/id_rsa.pub

パッケージの作成

catkin_create_pkg rospackage_test roscpp rospy std_msgs tf 

cmakelist.txtの設定

add_executable(sample_node src/sample_node.cpp)
target_link_libraries(sample_node ${catkin_LIBRARIES})

cmakelist.txtの関数化

function(create_node node_name)
  add_executable(${node_name} src/${node_name}.cpp)
  target_link_libraries(${node_name} ${catkin_LIBRARIES})
endfunction()

#使うとき
create_example_node(hogehoge)

rosdep

srcの部分はrosdepを実行したいディレクトリを指定

rosdep install -i -y --from-paths src

rosbag

全てのtopicを記録

rosbag record -a

指定したtopicを記録

rosbag record /topic1 /topic2

保存するファイル名指定

rosbag record -O file.bag

2倍速再生

rosbag play robot_bag.bag -r 2.0 --clock

ループ再生

rosbag play robot_bag.bag -l

rosbag play lego-loam

rosbag play *.bag --clock --topic /velodyne_points

ROSノードのテンプレート

/**
* @file sample.cpp
* @brief node
* @author Shunya Hara
* @date 2021.mm.dd
* @details 
*/

#include <ros/ros.h>

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

int main(int argc, char **argv){
    
    ros::init(argc, argv, "wp_loader_node");
    ros::NodeHandle n;
    //制御周期10Hz
    ros::Rate loop_rate(10);

    //param setting
    ros::NodeHandle pn("~");

    while (n.ok())  {
        
        ros::spinOnce();//subsucriberの割り込み関数はこの段階で実装される
        loop_rate.sleep();
        
    }
    
    return 0;
}

VSCodeでROSの入力補完を有効にする

Control + Shift + Pでコマンド画面を出してC/C++ Edit Configuratons (JSON)を開く

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/home/catkin_ws/devel/include/**",
                "/opt/ros/melodic/include/**",
                "/usr/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}