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

Setup assistant automating generation of controllers configs #908

Closed

Conversation

mayman99
Copy link
Contributor

@mayman99 mayman99 commented May 21, 2018

Description

This PR automates the generation of the ros_controller config files through the Setup Assistant, this is a part of upgrading the setup assistant. Issue 894

This ros_controllers.yaml was produced using this PR foe the PR2 Robot.

I'll follow this PR with another one that exposes the options through a GUI, and add documentation for it.

Checklist

  • Required: Code is auto formatted using clang-format
  • Extended the tutorials / documentation, if necessary reference
  • Include a screenshot if changing a GUI
  • Optional: Created tests, which fail without this PR reference
  • Optional: Decide if this should be cherry-picked to other current ROS branches (Indigo, Jade, Kinetic)

@mayman99 mayman99 closed this May 21, 2018
@mayman99 mayman99 reopened this May 21, 2018
// fake_controllers.yaml --------------------------------------------------------------------------------------
file.file_name_ = "fake_controllers.yaml";
// controllers.yaml --------------------------------------------------------------------------------------
file.file_name_ = "controllers.yaml";
Copy link
Member

Choose a reason for hiding this comment

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

ros_controller.yaml

@@ -251,7 +251,7 @@ class MoveItConfigData
bool outputOMPLPlanningYAML(const std::string& file_path);
bool outputKinematicsYAML(const std::string& file_path);
bool outputJointLimitsYAML(const std::string& file_path);
bool outputFakeControllersYAML(const std::string& file_path);
Copy link
Member

Choose a reason for hiding this comment

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

lets keep the fake controllers also

@@ -0,0 +1,17 @@
<?xml version="1.0"?>
Copy link
Member

Choose a reason for hiding this comment

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

ros_controllers.launch

@mayman99 mayman99 mentioned this pull request May 22, 2018
6 tasks
Copy link
Member

@davetcoleman davetcoleman left a comment

Choose a reason for hiding this comment

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

Great work!

{
// Cache the joints' names.
std::vector<std::vector<std::string>> groups;
std::vector<std::string> groupJoints;
Copy link
Member

Choose a reason for hiding this comment

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

please use underscore for var names per ros style guidelines

bool MoveItConfigData::outputControllersYAML(const std::string& file_path)
{
// Cache the joints' names.
std::vector<std::vector<std::string>> groups;
Copy link
Member

Choose a reason for hiding this comment

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

use more specific name than just groups

std::vector<std::vector<std::string>> groups;
std::vector<std::string> groupJoints;

// Loop through groups
Copy link
Member

Choose a reason for hiding this comment

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

expand comment: why loop through?

if (joint->isPassive() || joint->getMimic() != NULL || joint->getType() == robot_model::JointModel::FIXED)
continue;
else
{
Copy link
Member

Choose a reason for hiding this comment

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

don't mix using brackets without using brackets... all or none

// Get list of associated joints
const robot_model::JointModelGroup* joint_model_group = getRobotModel()->getJointModelGroup(group_it->name_);
const std::vector<const robot_model::JointModel*>& joint_models = joint_model_group->getActiveJointModels();
// Iterate through the joints
Copy link
Member

Choose a reason for hiding this comment

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

explain why you are iterating through the joints

emitter << YAML::Value << YAML::BeginSeq;

// Iterate through the joints
for (int j = 0; j < groups[i].size(); j++)
Copy link
Member

Choose a reason for hiding this comment

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

std::size_t

emitter << YAML::Newline << YAML::Comment("Creates the /joint_states topic necessary in ROS");
emitter << YAML::EndMap;

emitter << YAML::BeginMap;
Copy link
Member

Choose a reason for hiding this comment

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

what if in order to track the begin and end of maps, brackets were used to indent these sections? e.g.

emitter << YAML::BeginMap;
{
    emitter << YAML::Key << "joint_state_controller";
    emitter << YAML::Value << YAML::BeginMap;
    ...
}
emitter << YAML::EndMap;

output_stream << emitter.c_str();
output_stream.close();

return true; // file created successfully
Copy link
Member

Choose a reason for hiding this comment

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

this function is very long and readability is low. can it be separated out into a few smaller functions for each section of the yaml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I can split it, but I think later we will have to change this function when we expose some of the options to be configured by the GUI, would it be okay to leave it as a one piece until then?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, no problem.

std::ofstream output_stream(file_path.c_str(), std::ios_base::trunc);
if (!output_stream.good())
{
ROS_ERROR_STREAM("Unable to open file for writing " << file_path);
Copy link
Member

Choose a reason for hiding this comment

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

use ROS_ERROR_STREAM_NAMED

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do you recommend using the Named version here?
All the functions here that cant output a file uses this
ROS_ERROR_STREAM("Unable to open file for writing " << file_path);

Copy link
Member

Choose a reason for hiding this comment

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

See the style guidelines under "ROS":
http://moveit.ros.org/documentation/contributing/code/

It makes filtering all the command line output much easier and cleaner. All of the MSA should be updated to use NAMED, but that belongs in a separate simple PR that doesn't clutter this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I understand, Thanks.

<!-- Load joint controller configurations from YAML file to parameter server -->
<rosparam file="$(find [GENERATED_PACKAGE_NAME])/config/controllers.yaml" command="load"/>

<!-- load the controllers -->
Copy link
Member

Choose a reason for hiding this comment

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

be consistent with capitalization in comments. i personally prefer capitalizing

@davetcoleman
Copy link
Member

@mcevoyandy please review

@mayman99
Copy link
Contributor Author

Sorry didn't see the comments till now, I'll have a look at them later today.
For now I got the output configuration to work with 'moveit_sim_controller'.

@mayman99
Copy link
Contributor Author

mayman99 commented May 25, 2018

Thanks for the review!
Addressed the comments, please have a look.
this is a ros_conttollers.yaml produced for the ur5 and tested with moveit_sim_controller
@davetcoleman @mcevoyandy

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Generally approve. Some minor comments remain.


<!-- Load the controllers -->
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
output="screen" ns="/[GENERATED_PACKAGE_NAME]" args="spawn joint_state_controller position_trajectory_controller"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

@willcbaker Is using absolute namespaces compatible to 4598f66?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe so, I would advise against absolute namespacing.
Unable to test or review until next week, seems changing this way with generated package name will require pushing down into package name namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you recommend to remove the ns argument from here and from the robot_state_publisher node? right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ros_controllers.launch is intended to be used with gazebo, and according to ros_control tutorials, this is how gazebo_ros_control plugin is defined in the urdf

<gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
    <robotNamespace>/MYROBOT</robotNamespace>
  </plugin>
</gazebo>

So if we were to launch the controllers with not the robot_name as a namespace , and leave the plugin element <robotNamespace> blank, how would we be able to use simulate multiple robot for example?
Is there a solution for a situation like that?

<!-- Convert joint states to TF transforms for rviz, etc -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
respawn="false" output="screen">
<remap from="/joint_states" to="/[GENERATED_PACKAGE_NAME]/joint_states" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@@ -254,6 +254,7 @@ class MoveItConfigData
bool outputKinematicsYAML(const std::string& file_path);
bool outputJointLimitsYAML(const std::string& file_path);
bool outputFakeControllersYAML(const std::string& file_path);
bool outputControllersYAML(const std::string& file_path);
Copy link
Contributor

Choose a reason for hiding this comment

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

outputROSControllersYAML?

@@ -732,7 +732,7 @@ bool MoveItConfigData::outputControllersYAML(const std::string& file_path)
std::ofstream output_stream(file_path.c_str(), std::ios_base::trunc);
if (!output_stream.good())
{
ROS_ERROR_STREAM("Unable to open file for writing " << file_path);
ROS_ERROR_STREAM_NAMED("ros_controllers_config", "Unable to open file for writing " << file_path);
Copy link
Member

Choose a reason for hiding this comment

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

how about namespace = "setup_assistant"

Copy link
Contributor

Choose a reason for hiding this comment

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

-1 The package name (which is moveit_setup_assistant) is already part of the logger name. No need for an additional name at all!

Copy link
Member

Choose a reason for hiding this comment

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

Good point about the duplicate namespace, I should have recommended the file name "moveit_config_data" as that's the standard we usually follow. I really do like using _NAMED though. I've just attempted to document this standard better:
moveit/moveit.ros.org#166

Copy link
Contributor Author

@mayman99 mayman99 May 30, 2018

Choose a reason for hiding this comment

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

So do we go back to ROS_ERROR_STREAM?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's my suggestion. @davetcoleman?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer the consistency of always using NAMED as I've just attempted to document in moveit/moveit.ros.org#166. Perhaps a Github issue should be opened to specifically debate this. Either way, having the namespace certainly does not hurt anything so I would like to just merge this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@davetcoleman I don't agree. If you just have a redundant logger name like xxx.xxx, there is no reason to insist in NAMED. When we recently reworked the logging in some other MoveIt packages, we also dropped the extra NAME in such cases.

@@ -6,12 +6,12 @@

<!-- Load the controllers -->
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
output="screen" ns="/[GENERATED_PACKAGE_NAME]" args="spawn joint_state_controller position_trajectory_controller"/>
output="screen" ns="[ROBOT_NAME]" args="spawn joint_state_controller position_trajectory_controller"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the ns prefix is very specific to your application. Why do you prefer ROBOT_NAME over GENERATED_PACKAGE_NAME now?

Copy link
Contributor Author

@mayman99 mayman99 May 29, 2018

Choose a reason for hiding this comment

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

After looking at gazebo_ros_demos/rrbot_control.launch , I've found we use the robot name not the package name for the namespace.
Which is also done in the ros_control tutorial here.

rhaschke pushed a commit that referenced this pull request May 30, 2018
- ros_controllers.launch
- ros_controllers.yaml
@rhaschke
Copy link
Contributor

@MohmadAyman Please do not merge the devel branch into pull-request branches - never ever.
Instead you should rebase your PR to the latest devel branch.
Otherwise the commit history is screwed up and we have a really hard time to follow in the git tree what happened. Also, we cannot easily squash-merge the PR.

I manually merged this now in 89f55aa.

@rhaschke rhaschke closed this May 30, 2018
rhaschke pushed a commit to ubi-agni/moveit that referenced this pull request May 30, 2018
- ros_controllers.launch
- ros_controllers.yaml
dg-shadow pushed a commit to shadow-robot/moveit that referenced this pull request Jul 30, 2018
- ros_controllers.launch
- ros_controllers.yaml
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.

None yet

4 participants