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

Added a PoseBundle to SimpleCarState_V system. #497

Merged
merged 3 commits into from
Jul 13, 2018

Conversation

apojomovsky
Copy link

Fixes #485

  • By following the second approach proposed in this comment, this PR implements a PoseBundleToSimpleCarState_V system that, as its name suggests, feeds from the PoseBundle message published by the PoseAggregator (which includes the poses of all the agents in the simulation) and generates an array of SimpleCarState.

Solved issues:

  • The Topic Viewer wasn't displaying the non-ignition messages' payload. Solved in delphyne-gui's #136

Current issues:

  • The Topic Viewer cannot display the content of repeated (vector) elements from an ignition message. This can be appreciated in the /visualizer/scene_update topic, as well as in the just added /agents/state topic, both shown in the figure below:

Open to discussion:

  • In case we decide to go ahead with this PR, we'd need to fix the issue with the Topic Viewer.
  • As an option, we could go with the first approach proposed here, although it have its own difficulties that might not worth it.
  • Otherwise, I'm completely open to new proposals/options.

@apojomovsky apojomovsky force-pushed the apojomovsky/pose_bundle_to_simple_car_state branch from afccc2e to 5bf6afe Compare July 5, 2018 17:39
@stonier
Copy link
Collaborator

stonier commented Jul 6, 2018

In case we decide to go ahead with this PR, we'd need to fix the issue with the Topic Viewer.

Whether we go ahead with this PR, we might want to fix that. Someone using a vector ... will be inevitable. I can imagine that there are some difficulties around time-varying lengths when it comes to displaying them though - let alone handling dragging the topics to a plotter. Ask in an issue to the appropriate ignition forum. A side question - do they handle this for plotting or viewing ROS topics?

@apojomovsky
Copy link
Author

apojomovsky commented Jul 6, 2018

Sure @stonier , I think this problem deserves its own issue, so I just created it here, and there I'll be answering the questions raised here as I get them.

Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

@apojomovsky First pass, I left a couple comments.

const delphyne::AgentBase<T>&
AutomotiveSimulator<T>::GetAgentById(int agent_id) const {
const delphyne::AgentBase<T>& AutomotiveSimulator<T>::GetAgentById(
int agent_id) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky why the change?

Copy link
Author

@apojomovsky apojomovsky Jul 12, 2018

Choose a reason for hiding this comment

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

Hmm, seems like clang-format has been doing his thing here, which is weird since this code should have been already compliant. Just returned to its original state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, seems like clang-format has been doing his thing here, which is weird since this code should have been already compliant. Just returned to its original state.

Yeah, it seems to keep changing its mind; very often when I run it, it comes up with new differences. Not quite sure what is going on with it.

const drake::Isometry3<double>& pose = pose_bundle.get_pose(i);
// Translates pose from quaternion to euler.
const Eigen::Vector3d& euler_rotation =
pose.rotation().eulerAngles(0, 1, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky Hmm, eulerAngles() seems to be returning by-value. I wouldn't tie that temporary to a reference. Consider removing that extra &.

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks!

const drake::multibody::SpatialVelocity<double>& spatial_velocity =
velocity.get_velocity();
const double& velocity_norm =
static_cast<double>(spatial_velocity.translational().norm());
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky Same as above for the last two statements.

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks!

static_cast<double>(spatial_velocity.translational().norm());

// Appends a new state to the vector.
auto* current_state = output->add_states();
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky Does auto* infer SimpleCarState*? If so, it'd be great if you could be explicit about the type.

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks!


/// @brief A system that takes a PoseBundle and generates an array of
/// SimpleCarStates (SimpleCarState_V).
class PoseBundleToSimpleCarState_V : public drake::systems::LeafSystem<double> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky meta: why can't PoseBundleToSimpleCarState_V be a DrakeToIgn subclass?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm you're right! Just did that. Thanks!

ign_monitor.get_last_message();
ign_monitor.get_last_message().states(0);

// A very minimal loss of accuracy is produced during the conversion from the
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky consider Computations of SimpleCarState from a PoseBundle incur minimal numerical precision loss. Hence....

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks for the suggestion! Sounds a lot better!


// Shortly after starting, we should have not have moved much.
const int kStateMessagesCount{1};
EXPECT_TRUE(ign_monitor.do_until(
kStateMessagesCount, kTimeoutMs,
[this, &simulator]() { simulator->StepBy(kSmallTimeStep); }));

ignition::msgs::SimpleCarState state_message = ign_monitor.get_last_message();
ignition::msgs::SimpleCarState state_message =
ign_monitor.get_last_message().states(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

@apojomovsky should we be checking that there's at least one state in the array?

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks!

@apojomovsky apojomovsky force-pushed the apojomovsky/pose_bundle_to_simple_car_state branch from 63a4029 to 1b4f971 Compare July 12, 2018 19:20
@apojomovsky
Copy link
Author

Thanks for the review @hidmic , I just finished addressing your first round of comments. PTAL.

@apojomovsky apojomovsky merged commit a296593 into master Jul 13, 2018
@apojomovsky apojomovsky deleted the apojomovsky/pose_bundle_to_simple_car_state branch July 13, 2018 16:59
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.

Add a SimpleCarStatePublisher system that feeds from the PoseAggregator
4 participants