-
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
Add SimpleCarState Splitter #511
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.
@apojomovsky Left some comments!
src/backend/automotive_simulator.cc
Outdated
|
||
for (int i = 0; i < num_agents; ++i) { | ||
// Appends an ignition publisher to the vector for each agent. | ||
agent_state_vector.push_back( |
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.
@apojomovsky why keeping a vector of pointers, as opposed to just using the returned reference on each loop iteration and then dropping it?
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.
true that! done, thanks!
namespace delphyne { | ||
|
||
using std::placeholders::_1; | ||
using std::placeholders::_2; |
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.
@apojomovsky consider placing these using ...
statements closer to where they're being used (i.e. outside the loop but within the constructor).
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.
done, thanks!
using std::placeholders::_2; | ||
|
||
SimpleCarState_v_Splitter::SimpleCarState_v_Splitter(int agents_number) { | ||
DeclareAbstractInputPort(); |
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.
@apojomovsky should we validate agents_number > 0
?
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.
sounds good. done, thanks!
|
||
for (int i = 0; i < agents_number; ++i) { | ||
auto f = std::bind(&SimpleCarState_v_Splitter::DoSplit, this, _1, _2, i); | ||
auto d = std::bind(&SimpleCarState_v_Splitter::DoAlloc, this); |
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.
@apojomovsky consider taking d
outside the loop, we can reuse it for every output port.
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.
@apojomovsky also, consider giving both functors a more descriptive name.
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.
done, thanks!
|
||
std::unique_ptr<drake::systems::AbstractValue> | ||
SimpleCarState_v_Splitter::DoAlloc() { | ||
return drake::systems::AbstractValue::Make(ignition::msgs::SimpleCarState{}); |
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.
@apojomovsky consider having an ignition::msgs::SimpleCarState model_;
instead of instantiating a temporary one each time.
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.
done, thanks!
|
||
// Assigns the state returned by the agent_index to the output. | ||
auto& valor = output->GetMutableValue<ignition::msgs::SimpleCarState>(); | ||
if (simple_car_state_v.states_size() >= agent_index) { |
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.
@apojomovsky I wonder if we should let this pass by silently, as opposed to blowing up if it doesn't hold. Are we expecting transient variations here?
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.
just added a validation that throws an exception if the condition is not met
drake::systems::AbstractValue* output, int agent_index) const; | ||
|
||
/// @brief Allocates an abstract value object. | ||
std::unique_ptr<drake::systems::AbstractValue> DoAlloc(); |
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.
@apojomovsky can be const
?
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.
done, thanks!
/// @brief Sets the output value with the SimpleCarState message that's at the | ||
/// given index of the SimpleCarState_v. | ||
/// @param[in] context The simulation context. | ||
/// @param[in] output A pointer to an abstracted SimpleCarState message. |
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.
@apojomovsky missing agent_index
argument in documentation. Also, a bit of an explanation as to why its signature is different from that of all other output ports' Calc
functions is in order.
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.
done, thanks!
@@ -19,7 +19,6 @@ awscli | |||
curl | |||
git | |||
libignition-cmake-dev | |||
libsqlite3-dev |
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.
@apojomovsky what happened here?
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.
Hm, a commit from another PR. Just rebased my branch with master so that this doesn't appear anymore here.
|
||
/// @brief A system that takes a SimpleCarState_V and splits it into separate | ||
/// SimpleCarState messages. | ||
class SimpleCarState_v_Splitter : public drake::systems::LeafSystem<double> { |
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.
@apojomovsky consider making this a template: double
-> T
.
It's funny though, we need the scalar for this system to operate on a simulation but it doesn't use it. I wonder if there're examples of this already in Drake.
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.
done, thanks!
0ec6745
to
8fc2127
Compare
Thanks for the review @hidmic , I just finished addressing your comments. PTAL. |
8fc2127
to
3d58710
Compare
3d58710
to
04eaf31
Compare
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.
A few mostly minor things here.
src/backend/automotive_simulator.cc
Outdated
@@ -1,5 +1,7 @@ | |||
// Copyright 2017 Toyota Research Institute | |||
|
|||
#include "backend/automotive_simulator.h" | |||
|
|||
#include <algorithm> | |||
#include <functional> | |||
#include <utility> |
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.
Nit: #include <string>
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.
done, thanks!
src/backend/automotive_simulator.cc
Outdated
builder_ | ||
->template AddSystem<AgentsStatePublisherSystem>( | ||
std::make_unique<AgentsStatePublisherSystem>( | ||
"agent/" + std::to_string(i + 1) + "/state")) |
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.
Hm, kind of gross. Internally the agents are 0-based; are we sure we want them 1-based to the external observer?
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.
You're right. This change came from the index number that the PoseBundle to SimpleCarState_V was taking, that was 1-based (my mistake at that point), now changed it there and here to be 0-based again.
src/translations/CMakeLists.txt
Outdated
@@ -26,6 +27,7 @@ target_link_libraries(translations | |||
protobuf_messages | |||
${drake_LIBRARIES} | |||
${IGNITION-COMMON_LIBRARIES} | |||
ignition-msgs2::ignition-msgs2 |
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.
Minor, but we mostly are using ${IGNITION-MSGS_LIBRARIES}
in the code (the one exception is https://github.com/ToyotaResearchInstitute/delphyne/blob/master/test/regression/cpp/CMakeLists.txt#L24, which we should probably change to be consistent).
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.
Restored it for now, although we'll be changing to the library::library
format after #507
namespace delphyne { | ||
|
||
template <typename T> | ||
SimpleCarState_v_Splitter<T>::SimpleCarState_v_Splitter(int agents_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.
Personally I think num_agents
describes the situation better (agents_number
could possibly be confused for the number of an agent, which this is not).
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.
Totally agree, just did that. thanks!
src/backend/automotive_simulator.cc
Outdated
splitter->get_input_port(0)); | ||
|
||
for (int i = 0; i < num_agents; ++i) { | ||
// Appends an ignition publisher to the vector for each agent. |
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 this really do an append? It kind of just looks like it Connects the SimpleCarState_v
to the Splitter
, but I'm not sure. Could you clarify this comment a bit?
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.
Yes, it adds a new system to the builder on each iteration and connects it to the splitter.
That being said, I just replaced the previous comment block with a more cleared explanation.
Thanks for the review @clalancette . Just finished addressing your comments. PTAL |
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.
Couple comments @apojomovsky, but it looks great for the most part! 👍
// Assigns the state returned by the agent_index to the output. | ||
auto& mutable_state = | ||
output->GetMutableValue<ignition::msgs::SimpleCarState>(); | ||
if (simple_car_state_v.states_size() >= agent_index) { |
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.
@apojomovsky shouldn't be >
instead of >=
?
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.
You're right, thanks! Done.
/// | ||
/// In contrast to typical system's `Calc` methods, the presence of an extra | ||
/// argument in this function's signature comes from the need to specify which | ||
/// of the vector element must be used to generate the output. |
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.
@apojomovsky consider ...of the vector element...
-> ...of the vector elements...
.
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.
Done, thanks!
/// @brief Allocates an abstract value object. | ||
std::unique_ptr<drake::systems::AbstractValue> DoAlloc() const; | ||
|
||
ignition::msgs::SimpleCarState state_; |
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.
@apojomovsky missing documentation.
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.
Oops, just added it. thanks!
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 looks good to me, except for the one point about >
vs >=
that @hidmic brought up. Once that is fixed/clarified, I'm happy to approve.
Should we leave the publish rate in default or maybe reduce it to 10Hz or so? @clalancette @hidmic |
My opinion is that we should merge this as-is, and then open a separate issue/PR to address the publishing rate (as it may have knock-on effects, I'm not sure). But I could be convinced otherwise. |
Agree with @clalancette. This one is ready to go. |
Thanks guys! Merging... |
Fixes #504
caching
feature found in this experimental branch in drake helps us to reduce the impact to a minimum, which is expected since the successive calls to theEvalInputPort
method by each of the different state outputs would not require a whole recalculation of the vector.delphyne-mobil-perf
demo with 20MOBIL
cars, although the attention should focus in the relative times: