-
Notifications
You must be signed in to change notification settings - Fork 38
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
Refactored output parameter. #75
Closed
lewie-donckers
wants to merge
1
commit into
main
from
cleanup/refactored-output-parameter-to-return-value
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,9 +319,8 @@ void Controller::distToSegmentSquared( | |
} | ||
} | ||
|
||
tf2::Transform Controller::findPositionOnPlan( | ||
const geometry_msgs::Transform & current_tf, ControllerState * controller_state_ptr, | ||
size_t & path_pose_idx) | ||
Controller::FindPositionResult Controller::findPositionOnPlan( | ||
const geometry_msgs::Transform & current_tf, ControllerState * controller_state_ptr) | ||
{ | ||
tf2::Transform current_tf2; | ||
tf2::convert(current_tf, current_tf2); | ||
|
@@ -376,8 +375,8 @@ tf2::Transform Controller::findPositionOnPlan( | |
global_plan_tf_.size() - 1); | ||
// To finalize, compute the indexes of the start and end points of | ||
// the closest line segment to the current carrot | ||
tf2::Transform current_goal_local; | ||
current_goal_local = global_plan_tf_[controller_state_ptr->current_global_plan_index]; | ||
FindPositionResult result; | ||
result.position = global_plan_tf_[controller_state_ptr->current_global_plan_index]; | ||
|
||
tf2::Transform pose_projection_ahead; | ||
tf2::Transform pose_projection_behind; | ||
|
@@ -389,19 +388,19 @@ tf2::Transform Controller::findPositionOnPlan( | |
distToSegmentSquared( | ||
current_tf2, global_plan_tf_[0], global_plan_tf_[1], pose_projection_ahead, | ||
distance2_to_line_ahead, distance_to_end_line_ahead); | ||
current_goal_local = pose_projection_ahead; | ||
result.position = pose_projection_ahead; | ||
distance_to_goal_ = distance_to_goal_vector_[1] + distance_to_end_line_ahead; | ||
controller_state_ptr->last_visited_pose_index = 0; | ||
path_pose_idx = controller_state_ptr->current_global_plan_index; | ||
result.path_pose_index = controller_state_ptr->current_global_plan_index; | ||
} else if (controller_state_ptr->current_global_plan_index == global_plan_tf_.size() - 1) { | ||
distToSegmentSquared( | ||
current_tf2, global_plan_tf_[controller_state_ptr->current_global_plan_index - 1], | ||
global_plan_tf_[controller_state_ptr->current_global_plan_index], pose_projection_behind, | ||
distance2_to_line_behind, distance_to_end_line_behind); | ||
current_goal_local = pose_projection_behind; | ||
result.position = pose_projection_behind; | ||
distance_to_goal_ = distance_to_end_line_behind; | ||
controller_state_ptr->last_visited_pose_index = global_plan_tf_.size() - 2; | ||
path_pose_idx = controller_state_ptr->current_global_plan_index - 1; | ||
result.path_pose_index = controller_state_ptr->current_global_plan_index - 1; | ||
} else { | ||
distToSegmentSquared( | ||
current_tf2, global_plan_tf_[controller_state_ptr->current_global_plan_index], | ||
|
@@ -413,23 +412,23 @@ tf2::Transform Controller::findPositionOnPlan( | |
distance2_to_line_behind, distance_to_end_line_behind); | ||
|
||
if (distance2_to_line_ahead < distance2_to_line_behind) { | ||
current_goal_local = pose_projection_ahead; | ||
result.position = pose_projection_ahead; | ||
distance_to_goal_ = | ||
distance_to_goal_vector_[controller_state_ptr->current_global_plan_index + 1] + | ||
distance_to_end_line_ahead; | ||
controller_state_ptr->last_visited_pose_index = | ||
controller_state_ptr->current_global_plan_index; | ||
} else { | ||
current_goal_local = pose_projection_behind; | ||
result.position = pose_projection_behind; | ||
distance_to_goal_ = | ||
distance_to_goal_vector_[controller_state_ptr->current_global_plan_index] + | ||
distance_to_end_line_behind; | ||
controller_state_ptr->last_visited_pose_index = | ||
controller_state_ptr->current_global_plan_index - 1; | ||
} | ||
path_pose_idx = controller_state_ptr->current_global_plan_index; | ||
result.path_pose_index = controller_state_ptr->current_global_plan_index; | ||
} | ||
return current_goal_local; | ||
return result; | ||
} | ||
|
||
geometry_msgs::Twist Controller::update( | ||
|
@@ -452,24 +451,29 @@ geometry_msgs::Twist Controller::update( | |
current_tf.rotation.x, current_tf.rotation.y, current_tf.rotation.z, current_tf.rotation.w); | ||
current_with_carrot_.setRotation(cur_rot); | ||
|
||
size_t path_pose_idx; | ||
const auto current_tf_for_find_position = [¤t_tf, track_base_link = config_.track_base_link, | ||
current_with_carrot = current_with_carrot_]() { | ||
if (track_base_link) { | ||
return current_tf; | ||
} | ||
geometry_msgs::Transform current_with_carrot_g; | ||
tf2::convert(current_with_carrot, current_with_carrot_g); | ||
return current_with_carrot_g; | ||
}(); | ||
|
||
const auto find_position_result = | ||
findPositionOnPlan(current_tf_for_find_position, &controller_state_); | ||
const auto path_pose_idx = find_position_result.path_pose_index; | ||
current_pos_on_plan_ = current_goal_ = find_position_result.position; | ||
|
||
if (config_.track_base_link) { | ||
// Find closes robot position to path and then project carrot on goal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would preserve these kind of comments (after fixing the typo ;)), and move it to the new lambda function |
||
current_pos_on_plan_ = current_goal_ = | ||
findPositionOnPlan(current_tf, &controller_state_, path_pose_idx); | ||
// To track the base link the goal is then transform to the control point goal | ||
double theda_rp = tf2::getYaw(current_goal_.getRotation()); | ||
tf2::Vector3 newControlOrigin; | ||
newControlOrigin.setX(current_goal_.getOrigin().x() + config_.l * cos(theda_rp)); | ||
newControlOrigin.setY(current_goal_.getOrigin().y() + config_.l * sin(theda_rp)); | ||
newControlOrigin.setZ(0); | ||
current_goal_.setOrigin(newControlOrigin); | ||
} else { | ||
// find position of current position with projected carrot | ||
geometry_msgs::Transform current_with_carrot_g; | ||
tf2::convert(current_with_carrot_, current_with_carrot_g); | ||
current_pos_on_plan_ = current_goal_ = | ||
findPositionOnPlan(current_with_carrot_g, &controller_state_, path_pose_idx); | ||
} | ||
|
||
*progress = 1.0 - distance_to_goal_ / distance_to_goal_vector_[0]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These lambda functions don't really increase readability. But I get the point.
Although
current_tf_for_find_position
sounds like something that could be a simple request function on the class?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.
Actually, something is off here.
You're comment suggests a
current_tf
is requested. But there is also a variablecurrent_tf
. We should fix these names first.Probably one tf points to
base_link
and the other to the tf that tries to follow the carrot. Right @cesar-lopez-mar ?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, if I move the lambda to a member function we could add some documentation (that was present in the original implementation).
current_tf
is used ifconfig_.track_base_link
, else the following is used: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 agree that readability does not improve for all developers that might no be familiar with lambda functions (including myself). I would keep the comments of the original implementation in this function to help understanding the new code.
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.
Indeed current_tf points to base_link, and the other one to the carrot.
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.
Not the carrot. But the ControlPoint.
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 opened #87 for this. Referencing here to put it on the list ;)
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.
Okay, I'm confused as to what the conclusion of this discussion is/should be. I need some help.
Would replacing the lambda with a member function suffice? If so, I would like some help in naming and documenting that function.
Or, is there some underlying problem that needs to be fixed and which is preventing us from continuing with this PR?
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, there is an underlying problem that the variable names are off. I propose we fix that first.
I hope a more clear solution direction will follow from that.
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.
These variable names are really confusing indeed.
current_tf
also seems to imply that this is atf2::Transform
, but looking at this code, that cannot be the case (otherwise this wouldn't compile, ascurrent_with_carrot_g
is ageometry_msgs::Transform
).BTW, I like this refactor with the IILE