1. ノードの初期化
ROSCPP_DECL void init(int &argc, char **argv, const std::string& name, uint32_t options = 0);
ROSCPP_DECL void init(const M_string& remappings, const std::string& name, uint32_t options = 0);
ROSCPP_DECL void init(const VP_string& remapping_args, const std::string& name, uint32_t options = 0);
パラメータ |
意味 |
argc |
main関数の最初のパラメータ |
引数 |
main関数の2番目のパラメータ |
名前 |
ノードの名前は一意である必要があります |
2. トピックコミュニケーション
2.1 パブリッシャーオブジェクトの作成
template <class M>
Publisher NodeHandle::advertise(const std::string& topic, uint32_t queue_size, bool latch = false);
template <class M>
Publisher NodeHandle::advertise(const std::string& topic, uint32_t queue_size,
const SubscriberStatusCallback& connect_cb,
const SubscriberStatusCallback& disconnect_cb = SubscriberStatusCallback(),
const VoidConstPtr& tracked_object = VoidConstPtr(),
bool latch = false);
パラメータ |
意味 |
トピック |
トピック名は一意である必要があります |
キューサイズ |
サブスクライバへの送信を待機しているメッセージの最大数 |
ラッチ |
true の場合、トピックによって公開された最後のメッセージが保存され、後でサブスクライバーが接続したときにメッセージがサブスクライバーに送信されます。 |
2.2 ニュースリリース
template <typename M>
void Publisher::publish(const M& message) const;
パラメータ |
意味 |
メッセージ |
整理されたメッセージ |
2.3 加入者オブジェクトの作成
template<class M>
Subscriber NodeHandle::subscribe(const std::string& topic, uint32_t queue_size, void(*fp)(const boost::shared_ptr<M const>&), const TransportHints& transport_hints = TransportHints());
template<class M>
Subscriber NodeHandle::subscribe(const std::string& topic, uint32_t queue_size, const boost::function<void (const boost::shared_ptr<M const>&)>& callback,
const VoidConstPtr& tracked_object = VoidConstPtr(), const TransportHints& transport_hints = TransportHints());
パラメータ |
意味 |
トピック |
トピック名は一意である必要があります |
キューサイズ |
main関数の2番目のパラメータ |
FP |
コールバック関数の関数ポインタ |
戻る |
呼び出しが成功すると加入者オブジェクトが返され、呼び出しが失敗すると空のオブジェクトが返されます。 |
3.サービスコミュニケーション
3.1 サービスオブジェクトの作成
template<class T, class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, bool(T::*srv_func)(MReq &, MRes &), T *obj);
template<class T, class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, bool(T::*srv_func)(ServiceEvent<MReq, MRes>&), T *obj);
template<class T, class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, bool(T::*srv_func)(MReq &, MRes &), const boost::shared_ptr<T>& obj);
template<class T, class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, bool(T::*srv_func)(ServiceEvent<MReq, MRes>&), const boost::shared_ptr<T>& obj);
template<class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, bool(*srv_func)(MReq&, MRes&));
template<class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, bool(*srv_func)(ServiceEvent<MReq, MRes>&));
template<class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string& service, const boost::function<bool(MReq&, MRes&)>& callback,
const VoidConstPtr& tracked_object = VoidConstPtr());
template<class S>
ServiceServer NodeHandle::advertiseService(const std::string& service, const boost::function<bool(S&)>& callback,
const VoidConstPtr& tracked_object = VoidConstPtr());
パラメータ |
意味 |
サービス |
サービス名は一意である必要があります |
srv_func |
リクエストを受信した場合、コールバック関数を使用してリクエストを処理する必要があります |
戻る |
リクエストが成功するとサービス オブジェクトが返され、それ以外の場合は空のオブジェクトが返されます。 |
3.2 顧客オブジェクトの作成
template<class MReq, class MRes>
ServiceClient NodeHandle::serviceClient(const std::string& service_name, bool persistent = false,
const M_string& header_values = M_string());
template<class Service>
ServiceClient NodeHandle::serviceClient(const std::string& service_name, bool persistent = false,
const M_string& header_values = M_string());
パラメータ |
意味 |
サービス名 |
サービス名は一意である必要があります |
3.3 クライアントがリクエストを送信する
template<class Service>
bool ServiceClient::call(Service& service);
パラメータ |
意味 |
サービス |
.srv ファイルで定義されたサービス タイプ |
3.4 サービスを待機しているクライアント オブジェクト
ROSCPP_DECL bool service::waitForService(const std::string& service_name, int32_t timeout);
ROSCPP_DECL bool service::waitForService(const std::string& service_name, ros::Duration timeout = ros::Duration(-1));
パラメータ |
意味 |
サービス名 |
待機中のサービスの名前は一意である必要があります |
タイムアウト |
最大待機時間。デフォルトは -1 です。ノードがシャットダウンされるまで永遠に待機できます。 |
戻る |
成功した場合は true を返し、それ以外の場合は false を返します |
4. ロータリー機能
- つまり、コールバック関数を使用する場合は、ラウンドアバウト関数を使用して処理する必要があります。
4.1スピン
ROSCPP_DECL void spin();
4.2 スピンワンス
ROSCPP_DECL void spinOnce();
5.時間
5.1 瞬間
5.1.1 現在の瞬間を取得する
ros::init(argc,argv,"hello_time");
ros::NodeHandle nh;
ros::Time right_now = ros::Time::now();
ROS_INFO("当前时刻:%.2f",right_now.toSec());
ROS_INFO("当前时刻:%d",right_now.sec);
5.1.2 時刻の設定
ros::init(argc,argv,"hello_time");
ros::NodeHandle nh;
ros::Time someTime(100,100000000);
ROS_INFO("时刻:%.2f",someTime.toSec());
ros::Time someTime2(100.3);
ROS_INFO("时刻:%.2f",someTime2.toSec());
5.2 時間間隔
5.2.1 時間間隔の設定
ros::init(argc,argv,"hello_time");
ros::NodeHandle nh;
ros::Duration du(10);
ROS_INFO("持续时间:%.2f",du.toSec());
5.2.2 休止状態
ros::init(argc,argv,"hello_time");
ros::NodeHandle nh;
ros::Duration du(10);
du.sleep();
5.3 運転周波数を設定する
Rate::Rate(double frequency);
6.パラメータ設定
6.1 パラメータの変更または追加
void NodeHandle::setParam(const std::string& key, const XmlRpc::XmlRpcValue& v) const;
void NodeHandle::setParam(const std::string& key, const std::string& s) const;
void NodeHandle::setParam(const std::string& key, const char* s) const;
void NodeHandle::setParam(const std::string& key, double d) const;
void NodeHandle::setParam(const std::string& key, int i) const;
void NodeHandle::setParam(const std::string& key, bool b) const;
void NodeHandle::setParam(const std::string& key, const std::vector<std::string>& vec) const;
void NodeHandle::setParam(const std::string& key, const std::vector<double>& vec) const;
void NodeHandle::setParam(const std::string& key, const std::vector<float>& vec) const;
void NodeHandle::setParam(const std::string& key, const std::vector<int>& vec) const;
void NodeHandle::setParam(const std::string& key, const std::vector<bool>& vec) const;
void NodeHandle::setParam(const std::string& key, const std::map<std::string, std::string>& map) const;
void NodeHandle::setParam(const std::string& key, const std::map<std::string, double>& map) const;
void NodeHandle::setParam(const std::string& key, const std::map<std::string, float>& map) const;
void NodeHandle::setParam(const std::string& key, const std::map<std::string, int>& map) const;
void NodeHandle::setParam(const std::string& key, const std::map<std::string, bool>& map) const;
- ROS には、上に示したように、設定できる 16 種類のパラメータが用意されています。
- を使用すると
ros::param::set
まったく同じ効果があります
6.2 パラメータの取得
6.3 パラメータの削除