-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make pacledt-compose'Node' #9
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
とりあえずこれだけ
あと今入ってる日本語のコメント全部消してください
packet/packet_composed/include/packet_composed/sensorspacket.hpp
Outdated
Show resolved
Hide resolved
packet/packet_composed/include/packet_composed/sensorspacket.hpp
Outdated
Show resolved
Hide resolved
packet/packet_composed/include/packet_composed/sensorspacket.hpp
Outdated
Show resolved
Hide resolved
…とをしている気がします。ご指摘いただきたいです。よろしくお願いいたします。
slackでお騒がせしてすみません。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
作成するnodeは一つだけでいいです
欲しいのは"複数のtopicをsubscribeして一つのtopicにまとめるnode"なので, 以下のようなクラス定義が与えられます
class Composed : public rclcpp::Node {
private:
rclcpp::Publisher<packet_interfaces::msg::Composed>::SharedPtr composed_publisher;
rclcpp::Subscription<packet_interfaces::msg::Depth>::SharedPtr depth_subscription;
rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr imu_subscription;
rclcpp::Subscription<packet_interfaces::msg::Flex>::SharedPtr flex1_subscription;
rclcpp::Subscription<packet_interfaces::msg::Flex>::SharedPtr flex2_subscription;
// current, voltageのsubscriptionは略
void depth_topic_callback(const packet_interfaces::msg::Depth& msg);
void imu_topic_callback(const sensor_msgs::msg::Imu& msg);
void flex1_topic_callback(const packet_interfaces::msg::Flex& msg);
void flex2_topic_callback(const packet_interfaces::msg::Flex& msg);
// current, voltageのcallbackは略
// さらにいくつかのメソッド, プロパティが必要になる
public:
Composed();
};
より具体的には, "subscribeしたtopicの内容を記憶し, それらを組み合わせたtopicを定期的にpublishする"といったnodeになると思います.
今、コメントを読んでコードを変更しているところです。 私がやる方向性として このことを理解してpacket_composed/src内にあるcompsed.cppとcomposed_main.cpp、CMakeLists.txt、package.xmlt, ということは、この前私がPRを出したときにdepthなどの複数のノードを作成したパッケージは削除して、一番最初に作成したcomposedのファイルだけ残せばよいのでしょうか? ちなみにまだ、ファイルを一切消していません。。 よろしくお願いいたします。 |
あってる!Flexは2つあるので注意してください。
あってる!!他のやつはバッサリ捨てちゃってください 🔥 |
ありがとうございます!!! |
#3 色々と調べて、Composedクラスがセンサーデータ(Depth、IMU、Flexなど)を受信し、それらを1つのComposedメッセージとしてまとめてパブリッシュする。 [自分がした大まかな手順] このノードでやりたいことはわかるのですが、、 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
やりたいのは「複数topicを受信して、 一つの topicにまとめて 同時に publishする」ということです。今のコードだと「一つのtopicにまとめる」ところはできてますが、「同時にpublishする」というのができていません。これを実現するためには、以下のようにする必要があります。
- subscriptionで受信したtopicを一度保存する
- タイマー機能で、保存されているtopicを一つにまとめてpublishする
この「一度保存する」というのをどう実現するかが少し難しいところですが、考えて見てください。(しばらく考えてわかんなかったら教えてください)
packet/packet_composed/include/packet_composed/sensorspacket.hpp
Outdated
Show resolved
Hide resolved
packet/packet_composed/include/packet_composed/sensorspacket.hpp
Outdated
Show resolved
Hide resolved
_publisher = this->create_publisher<std_msgs::msg::String>("/sensors_composed", 10); | ||
composed_publisher = this->create_publisher<packet_interfaces::msg::Composed>("composed_topic", 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stringのpublishはしません & topic名はFigmaのやつ(から/packet/
のプレフィックスを取り除いたもの)と合わせるようにお願いします
_publisher = this->create_publisher<std_msgs::msg::String>("/sensors_composed", 10); | |
composed_publisher = this->create_publisher<packet_interfaces::msg::Composed>("composed_topic", 10); | |
composed_publisher = this->create_publisher<packet_interfaces::msg::Composed>("sensors_composed", 10); |
depth_subscription = this->create_subscription<packet_interfaces::msg::Depth>( | ||
"depth_topic", 10, std::bind(&Composed::depth_topic_callback, this, std::placeholders::_1)); | ||
|
||
imu_subscription = this->create_subscription<sensor_msgs::msg::Imu>( | ||
"imu_topic", 10, std::bind(&Composed::imu_topic_callback, this, std::placeholders::_1)); | ||
|
||
flex1_subscription = this->create_subscription<packet_interfaces::msg::Flex>( | ||
"flex1_topic", 10, std::bind(&Composed::flex1_topic_callback, this, std::placeholders::_1)); | ||
|
||
flex2_subscription = this->create_subscription<packet_interfaces::msg::Flex>( | ||
"flex2_topic", 10, std::bind(&Composed::flex2_topic_callback, this, std::placeholders::_1)); | ||
|
||
current_subscription = this->create_subscription<packet_interfaces::msg::Current>( | ||
"current_topic", 10, std::bind(&Composed::current_topic_callback, this, std::placeholders::_1)); | ||
|
||
voltage_subscription = this->create_subscription<packet_interfaces::msg::Voltage>( | ||
"voltage_topic", 10, std::bind(&Composed::voltage_topic_callback, this, std::placeholders::_1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここのtopic名も書き換えてください
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一旦、上記のコメント読んで直したファイルをcommit→PR出しました。 「同時にpublishする」という部分については考え中です。 個人的に浮かんだ考え方はcomposed.cppのcomposedのループを利用すればいいと思っています。
この部分にif文を追加して、同時に受け取ったときpublishするというif文を作る。 |
あってる。
subscriptionのcallbackとtimerのcallbackは非同期に呼ばれるので、「同時に受け取った時」を判定するのはとても難しそうです。
良さそうだけど、関数ではなく状態、ないしメンバ変数かな |
#3