The NodeOptions in the constructor is needed only when you use the following lines:
The latter, as you noted:
Is actually sufficient as well, as mentioned in the rclcpp documentation. I have also tried this and it works for me too, so I can verify this. Yet, I still do not understand when exactly I would need the 4 additional lines in the create_client function. This is how it is mentioned in the official documentation also : Writing an action server and client (C++) — ROS 2 Documentation: Foxy documentation
I understand that the explicit keyword is necessary but the NodeOptions is not.
Although, as indicated in the documentation, you may construct the constructor as follows:
MyActionClient(const rclcpp::NodeOptions &node_options)
: Node("my_action_client", node_options)
{
bool goal_done_ = false; // you can add this line here to make the constructor line smaller
[...]
}
In my opinion, the concise version works the same way as the version with the four pointers to the node interfaces.
I would still like to know the reason as you do, from The Construct team.
I have not yet implemented actions (server or client) with node composition. That is probably the reason why I was unaware of this information and the use for NodeOptions.
Yes, I realized this soon after I posted my response. I forgot to edit/update it.
I realized that NodeOptions are required when I read through the unit on “Components” again.
I should have probably said that I have not implemented “Components” by myself. It was only during when I learned the unit on ROS2 Components. I have not tried to use Components in my programs yet (or in the course project).
Anyways, thanks for clarifying that point.
Regards,
Girish
EDIT: Perhaps this reason for using NodeOptions could be added in the course with succinct lines, if not present in the course already, by The Construct team.