Skip to content
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

Merged
merged 10 commits into from
Dec 4, 2017
Merged

[ros2topic] pub: add --repeat #66

merged 10 commits into from
Dec 4, 2017

Conversation

mikaelarguedas
Copy link
Member

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?

@mikaelarguedas mikaelarguedas added the in progress Actively being worked on (Kanban column) label Dec 3, 2017
@mikaelarguedas mikaelarguedas self-assigned this Dec 3, 2017
@dirk-thomas
Copy link
Member

Instead of adding --repeat I would suggest to add options similar to the ones available in ROS 1.

@mikaelarguedas
Copy link
Member Author

thanks I'll do that. I guess I'll adapt ros2 service call accordingly.

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.

Do you have any feedback on this?

@dirk-thomas
Copy link
Member

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.

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 type=float since that is what this custom function is doing anyway. I haven't tried that though...

try:
rate = float(rate)
except ValueError:
raise argparse.ArgumentTypeError('rate must be a number')
Copy link
Member

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

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)')
Copy link
Member

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.

if rate is not None:
period = 1. / rate
else:
period = 1
Copy link
Member

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...

Copy link
Member Author

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


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')
Copy link
Member

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.)

Copy link
Member

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).

Copy link
Member Author

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

Copy link
Member Author

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

def requester(service_type, service_name, values, rate, once):
if rate is not None:
period = 1. / rate
else:
Copy link
Member

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.

Copy link
Member Author

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

@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Dec 4, 2017
Copy link
Member

@dirk-thomas dirk-thomas left a 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).

@mikaelarguedas
Copy link
Member Author

Thanks for the various fixups.
I tried the various scenarios it seems to work fine.
One thing that's a bit weird is that if the use passes an invalid rate and also pass once it raises. I could make it perform the check on the rate being only if once is not passed if we wanted to be more correct.

@dirk-thomas
Copy link
Member

One thing that's a bit weird is that if the use passes an invalid rate and also pass once it raises. I could make it perform the check on the rate being only if once is not passed if we wanted to be more correct.

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.

@mikaelarguedas
Copy link
Member Author

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.

@mikaelarguedas mikaelarguedas merged commit 10f4147 into master Dec 4, 2017
@mikaelarguedas mikaelarguedas deleted the pub_add_repeat branch December 4, 2017 02:55
@mikaelarguedas mikaelarguedas removed the in review Waiting for review (Kanban column) label Dec 4, 2017
@dhood
Copy link
Member

dhood commented Dec 6, 2017

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

@mikaelarguedas
Copy link
Member Author

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

@codebot
Copy link
Member

codebot commented Dec 6, 2017

👍 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.

@mikaelarguedas
Copy link
Member Author

#67

esteve pushed a commit to esteve/ros2cli that referenced this pull request Dec 16, 2022
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants