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

ros_control/Executor #151

Merged
merged 7 commits into from
Apr 6, 2017
Merged

ros_control/Executor #151

merged 7 commits into from
Apr 6, 2017

Conversation

gilwoolee
Copy link
Contributor

Needs documentation, review, and unit-tests.

@gilwoolee gilwoolee self-assigned this Apr 4, 2017
@gilwoolee gilwoolee requested review from jslee02 and aditya-vk April 4, 2017 00:13
@mkoval mkoval mentioned this pull request Apr 4, 2017
@gilwoolee gilwoolee assigned jslee02 and unassigned gilwoolee Apr 4, 2017
@gilwoolee gilwoolee removed the request for review from jslee02 April 4, 2017 00:19
@jslee02 jslee02 added this to the Aikido 0.1.0 milestone Apr 4, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.0%) to 84.425% when pulling b102958 on ros_Executor into 4cd2795 on master.

Copy link
Member

@mkoval mkoval left a comment

Choose a reason for hiding this comment

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

Like @gilwoolee said, this is missing documentation and unit tests. Otherwise, it generally looks reasonable.

catch (const std::exception& e)
{
std::cerr << "Exception thrown by callback: " << e.what() << std::endl;
mIsRunning.store(false);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: add a break here so we don't sleep_until after encountering an error.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have much experience in multithreaded programming so this might be a silly question: Shouldn't we throw e here instead so that the caller can handle the exception?

}
catch (const std::exception& e)
{
std::cerr << "Exception thrown by callback: " << e.what() << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We should find another way to handle this error, so we don't print directly to std::cerr. Unfortunately, I don't have an immediately better solution since Aikido doesn't use any particular logging framework.

Copy link
Contributor Author

@gilwoolee gilwoolee Apr 5, 2017

Choose a reason for hiding this comment

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

Yeah. I think we'll have to keep it as a TODO for now. #155

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 85.518% when pulling f722010 on ros_Executor into 4cd2795 on master.

@jslee02
Copy link
Member

jslee02 commented Apr 4, 2017

Added documentation and tests

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0ec48ea on ros_Executor into ** on master**.

Copy link
Contributor Author

@gilwoolee gilwoolee left a comment

Choose a reason for hiding this comment

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

LGTM!

}
catch (const std::exception& e)
{
std::cerr << "Exception thrown by callback: " << e.what() << std::endl;
Copy link
Contributor Author

@gilwoolee gilwoolee Apr 5, 2017

Choose a reason for hiding this comment

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

Yeah. I think we'll have to keep it as a TODO for now. #155

@gilwoolee
Copy link
Contributor Author

Looks good! Thanks @jslee02 @mkoval @ClintLiddick for all your previous and current work on this. I'll merge it once Travis passes. :D

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 85.208% when pulling 55000a4 on ros_Executor into 6779dd2 on master.

Copy link
Member

@mkoval mkoval left a comment

Choose a reason for hiding this comment

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

I left a few minor comments about docstrings. Once those are resolved, feel free to merge!

namespace aikido {
namespace util {

/// ExecutorMultiplexer stores callbacks and calls them in order of they added.
Copy link
Member

Choose a reason for hiding this comment

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

The fact that callbacks are called in the order they are added isn't important. My original intent for implementing this class was to allow one ExecutorThread to call multiple executors. The purpose of ExecutorThread is to periodically call "spin" functions, like those in RosJointStateClient and RosTrajectoryExecutor.

I'd like to capture this "big picture" idea here. Here's my attempt at a new docstring:

Combine multiple executors (i.e. no argument callbacks) into one executor.

This helper class allows one `ExecutorThread to call multiple executors by sequentially calling the callbacks added to this class.

It is not critical, but I would slightly prefer to remove all of the comments that specify the order the callbacks will be called in. The fact that they are called in order is an implementation detail that is subject to change - and may very well need to change if we add a removeCallback helper function to this class.

///
/// \code
/// ExecutorThread exec(
/// []() { std::cout << "running\n";}, std::chrono::nanoseconds(1));
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 a scary example because printing running will likely take longer than 1 ns. Can you change the example to something more realistic, e.g. 10 ms?

///
/// // thread is running
///
/// exec.stop();
Copy link
Member

Choose a reason for hiding this comment

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

I suggest removing stop() from this example code, since ExecutorThread is intended to be used primarily as an RAII class. In fact, I'd like to mention the fact that the destructor stops the thread in this comment.


std::this_thread::sleep_for(std::chrono::seconds(3));

EXPECT_TRUE(!exec.isRunning());
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 technically a race condition, but I don't see a better way of implementing it. I suppose the 3 second sleep is essentially a timeout for the test.

@jslee02
Copy link
Member

jslee02 commented Apr 6, 2017

Thanks for the comments @mkoval . Now I have a better understanding of the classes' purpose.

Let's merge this once Travis CI becomes happy.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 85.208% when pulling d6c937d on ros_Executor into 6779dd2 on master.

@jslee02 jslee02 merged commit ecca7f3 into master Apr 6, 2017
@jslee02 jslee02 deleted the ros_Executor branch April 6, 2017 03:10
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