-
Notifications
You must be signed in to change notification settings - Fork 948
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
Assistant: load additional file with kinematics parameters #1997
Changes from all commits
6b784cb
734ff36
9af0426
4e9d8bb
31e5ba3
0bf0db2
a6b3eb4
cc53407
acaaf88
12aa7d7
e4fb611
2ce895c
9b9beb5
c8f39b6
40b9ecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1360,6 +1360,46 @@ bool MoveItConfigData::inputKinematicsYAML(const std::string& file_path) | |
return true; // file created successfully | ||
} | ||
|
||
// ****************************************************************************************** | ||
// Input planning_context.launch file | ||
// ****************************************************************************************** | ||
bool MoveItConfigData::inputPlanningContextLaunch(const std::string& file_path) | ||
{ | ||
TiXmlDocument launch_document(file_path); | ||
if (!launch_document.LoadFile()) | ||
{ | ||
ROS_ERROR_STREAM("Failed parsing " << file_path); | ||
return false; | ||
} | ||
|
||
// find the kinematics section | ||
TiXmlHandle doc(&launch_document); | ||
TiXmlElement* kinematics_group = doc.FirstChild("launch").FirstChild("group").ToElement(); | ||
while (kinematics_group && kinematics_group->Attribute("ns") != std::string("$(arg robot_description)_kinematics")) | ||
{ | ||
kinematics_group = kinematics_group->NextSiblingElement("group"); | ||
} | ||
if (!kinematics_group) | ||
{ | ||
ROS_ERROR("<group ns=\"$(arg robot_description)_kinematics\"> not found"); | ||
return false; | ||
} | ||
|
||
// iterate over all <rosparam namespace="group" file="..."/> elements | ||
// and if 'group' matches an existing group, copy the filename | ||
for (TiXmlElement* kinematics_parameter_file = kinematics_group->FirstChildElement("rosparam"); | ||
kinematics_parameter_file; kinematics_parameter_file = kinematics_parameter_file->NextSiblingElement("rosparam")) | ||
{ | ||
const char* ns = kinematics_parameter_file->Attribute("ns"); | ||
if (ns && (group_meta_data_.find(ns) != group_meta_data_.end())) | ||
{ | ||
group_meta_data_[ns].kinematics_parameters_file_ = kinematics_parameter_file->Attribute("file"); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// ****************************************************************************************** | ||
// Helper function for parsing an individual ROSController from ros_controllers yaml file | ||
// ****************************************************************************************** | ||
|
@@ -1550,6 +1590,46 @@ bool MoveItConfigData::setPackagePath(const std::string& pkg_path) | |
return true; | ||
} | ||
|
||
// ****************************************************************************************** | ||
// Extract the package/stack name from an absolute file path | ||
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. This whole function is rather complex. But I just have seen that you moved it from 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. Sure, I just didn't want to put too much into one PR |
||
// Input: path | ||
// Output: package name and relative path | ||
// ****************************************************************************************** | ||
bool MoveItConfigData::extractPackageNameFromPath(const std::string& path, std::string& package_name, | ||
std::string& relative_filepath) const | ||
{ | ||
fs::path sub_path = path; // holds the directory less one folder | ||
fs::path relative_path; // holds the path after the sub_path | ||
|
||
bool package_found = false; | ||
|
||
// truncate path step by step and check if it contains a package.xml | ||
while (!sub_path.empty()) | ||
{ | ||
ROS_DEBUG_STREAM("checking in " << sub_path.make_preferred().string()); | ||
if (fs::is_regular_file(sub_path / "package.xml")) | ||
{ | ||
ROS_DEBUG_STREAM("Found package.xml in " << sub_path.make_preferred().string()); | ||
package_found = true; | ||
relative_filepath = relative_path.string(); | ||
package_name = sub_path.leaf().string(); | ||
break; | ||
} | ||
relative_path = sub_path.leaf() / relative_path; | ||
sub_path.remove_leaf(); | ||
} | ||
|
||
// Assign data to moveit_config_data | ||
if (!package_found) | ||
{ | ||
// No package name found, we must be outside ROS | ||
return false; | ||
} | ||
|
||
ROS_DEBUG_STREAM("Package name for file \"" << path << "\" is \"" << package_name << "\""); | ||
return true; | ||
} | ||
|
||
// ****************************************************************************************** | ||
// Resolve path to .setup_assistant file | ||
// ****************************************************************************************** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -962,6 +962,9 @@ bool ConfigurationFilesWidget::generatePackage() | |
absolute_path = config_data_->appendPaths(new_package_path, file->rel_path_); | ||
ROS_DEBUG_STREAM("Creating file " << absolute_path); | ||
|
||
// Clear template strings in case export is run multiple times with changes in between | ||
template_strings_.clear(); | ||
|
||
// Run the generate function | ||
if (!file->gen_func_(absolute_path)) | ||
{ | ||
|
@@ -1118,6 +1121,24 @@ void ConfigurationFilesWidget::loadTemplateStrings() | |
addTemplateString("[ROS_CONTROLLERS]", controllers.str()); | ||
} | ||
|
||
// Pair 10 - Add parameter files for the kinematics solvers that should be loaded | ||
// in addition to kinematics.yaml by planning_context.launch | ||
std::string kinematics_parameters_files_block; | ||
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. Can you add a comment to this section as for the others? |
||
for (const auto& groups : config_data_->group_meta_data_) | ||
{ | ||
if (groups.second.kinematics_parameters_file_.empty()) | ||
continue; | ||
|
||
// add a linebreak if we have more than one entry | ||
if (!kinematics_parameters_files_block.empty()) | ||
kinematics_parameters_files_block += "\n"; | ||
|
||
std::string line = " <rosparam command=\"load\" ns=\"" + groups.first + "\" file=\"" + | ||
groups.second.kinematics_parameters_file_ + "\"/>"; | ||
kinematics_parameters_files_block += line; | ||
} | ||
addTemplateString("[KINEMATICS_PARAMETERS_FILE_NAMES_BLOCK]", kinematics_parameters_files_block); | ||
|
||
addTemplateString("[AUTHOR_NAME]", config_data_->author_name_); | ||
addTemplateString("[AUTHOR_EMAIL]", config_data_->author_email_); | ||
} | ||
|
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 don't get the role of the
ns
attribute here, which doesn't exist in the template file:https://github.com/ros-planning/moveit/blob/4d3062164bf03ebb74c57d5eba0e3e50438481ba/moveit_setup_assistant/templates/moveit_config_pkg_template/launch/planning_context.launch#L19-L22
Shouldn't you check for the existence of the
file
attribute instead?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.
the namespace is written in the block template "KINEMATICS_PARAMETERS_FILE_NAMES_BLOCK" (which is a bit ugly because there is no proper templating library with for loops like grantlee ...) and contains the name of the JointModelGroup