-
Notifications
You must be signed in to change notification settings - Fork 160
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
[ros2topic] pub: add --repeat #66
Conversation
Instead of adding |
thanks I'll do that. I guess I'll adapt
Do you have any feedback on this? |
In general: the function seems to be so trivial that I wouldn't bother to declare it as a public API (which needs to be documented and tested at some point). In this specific case it might be possible to simply use |
ros2service/ros2service/verb/call.py
Outdated
try: | ||
rate = float(rate) | ||
except ValueError: | ||
raise argparse.ArgumentTypeError('rate must be a number') |
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.
This is unnecessary. Since the argument is of type=float
the variable args.rate
is already of type float
(or None
).
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.
Will fix
ros2service/ros2service/verb/call.py
Outdated
def requester(service_type, service_name, values, rate, once): | ||
if rate is not None: | ||
if once: | ||
raise RuntimeError('You cannot select both -r and -1 (--once)') |
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.
This argument checking should happen within argparse. You can use a mutually exclusive group for this.
ros2service/ros2service/verb/call.py
Outdated
if rate is not None: | ||
period = 1. / rate | ||
else: | ||
period = 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.
I would suggest to use a default value for the argument instead. That way the code doesn't have to contain some not-documented constants.
That might affect the choice to group the arguments...
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.
Yeah I went back and forth on this.
I'm fine with adding the default vaIue for the rate and keeping the logic for the mutual exclusion. That logic can be in a main
fuction before calling the actual requester like it's done for ros2topic.
TBH I think that they dont have to be mutually exclusive. If you specify a rate you override a default of 1Hz, but if you specify --once
, the rate (user specified or not) will not matter as we exit after the first call. I'm not convinced the executable should raise, it could just honor once
ros2topic/ros2topic/verb/pub.py
Outdated
|
||
def main(self, *, args): | ||
return main(args) | ||
|
||
|
||
def main(args): | ||
return publisher(args.message_type, args.topic_name, args.values) | ||
if args.rate <= 0: | ||
raise ValueError('rate must be greater than zero') |
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.
I would suggest ti move this into PubVerb.main
. That way the entity defining the command line arguments is also responsible of checking the sanity of the values. (The same way as it is for the CallVerb
above.)
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.
Does the ValueError result in a stack trace for the user? If so I would recommend to either use argparse to signal the error or raise a RuntimeError (both with the goal to not show a stack trace to the user).
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.
Good point, I changed it to a RuntimeError
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.
I would suggest ti move this into PubVerb.main. That way the entity defining the command line arguments is also responsible of checking the sanity of the values. (The same way as it is for the CallVerb above.)
Good point, moved in 041b411
ros2service/ros2service/verb/call.py
Outdated
def requester(service_type, service_name, values, rate, once): | ||
if rate is not None: | ||
period = 1. / rate | ||
else: |
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.
This is now never the case.
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.
forgot to commit local changes :/
29015d6
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.
lgtm (I haven't tried it though).
Thanks for the various fixups. |
If we would check the argument directly within argparse that would also fail for invalid values even when they are later not used. So I am ok with it raising in that case. |
Fair point. Merging then. |
what's the motivation for having repeated service calls the default? just to match ros2 topic? Repeated service calls wasn't the case in ros1 and I don't think it's appropriate as the default for ros2 |
It was not the case for rostopic in ROS 1 either, we did it for consistency but I agree the default should likely be to send only once. I'm fine to change it if everybody agrees |
👍 to sending it only once. Sometimes services have nontrivial downstream effects, like starting a motion plan or something. Of course, that argument can also be said for (some) topics, but somehow it feels like this happens more often for services. |
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
I kept the default behavior (publishing every second) the same for now as we dont have latching.
Not sure what the right place is to put the
float_or_int
utility for reuse. I'm not convinced it belongs in the Base class but I can imagine it being reused in many places. Maybe a set of argparse utilities in ros2cli would make sense.@dirk-thomas thoughts?