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

private ControllerList in the controller manager #39

Open
swhart115 opened this issue Aug 7, 2018 · 5 comments
Open

private ControllerList in the controller manager #39

swhart115 opened this issue Aug 7, 2018 · 5 comments

Comments

@swhart115
Copy link

Hi I was wondering what the reason was to have the ControllerList private in the ControllerManager class. I'm trying to work with this class, but keep wanting more info about controllers. Since I can't access the list, and since i can only get the pointers to the handles for the controllers, it's proving difficult to get the info i need. I can get the joint handles by name, wondering why i cant actualyl get the controllers (as controller classes) by name. Thanks.

@swhart115
Copy link
Author

bump

@moriarty
Copy link
Contributor

Seems reasonable... Just to clarify, currently there is this:

HandlePtr ControllerManager::getHandle(const std::string& name)
{
  // Try joints first
  for (JointHandleList::iterator j = joints_.begin(); j != joints_.end(); j++)
  {
    if ((*j)->getName() == name)
      return *j;
  }

  // Then controllers
  for (ControllerList::iterator c = controllers_.begin(); c != controllers_.end(); c++)
  {
    if ((*c)->getController()->getName() == name)
      return (*c)->getController();
  }

  // Not found
  return HandlePtr();
}

JointHandlePtr ControllerManager::getJointHandle(const std::string& name)
{
  // Try joints first
  for (JointHandleList::iterator j = joints_.begin(); j != joints_.end(); j++)
  {
    if ((*j)->getName() == name)
      return *j;
  }

  // Not found
  return JointHandlePtr();
}

And I think you want:

ControllerPtr ControllerManager::getController(const std::string& name)
{
  for (ControllerList::iterator c = controllers_.begin(); c != controllers_.end(); c++)
  {
    if ((*c)->getController()->getName() == name)
      return (*c)->getController();
  }

  // Not found
  return ControllerPtr();
}

?

@swhart115
Copy link
Author

this is great, thank you for your response. Maybe while we are at it, we could also add a function that returns list of the controller names?

For example:

std::vector<std::string> ControllerManager::getControllerNames()
{
  std::vector<std::string> controller_names;
  for (ControllerList::iterator c = controllers_.begin(); c != controllers_.end(); c++)
  {
    controller_names.push_back((*c)->getController()->getName());
  }
  return controller_names;
}

or alternatively:

void ControllerManager::getControllerNames(std::vector<std::string> &controller_names)
{
  controller_names.clear();
  for (ControllerList::iterator c = controllers_.begin(); c != controllers_.end(); c++)
  {
    controller_names.push_back((*c)->getController()->getName());
  }
}

@moriarty
Copy link
Contributor

I think

std::vector<std::string> ControllerManager::getControllerNames()
{
  std::vector<std::string> controller_names;
  for (ControllerList::iterator c = controllers_.begin(); c != controllers_.end(); c++)
  {
    controller_names.push_back((*c)->getController()->getName());
  }
  return controller_names;
}

Fits better with the rest of the code.

@swhart115
Copy link
Author

looks good to me!

mikeferguson added a commit to mikeferguson/robot_controllers that referenced this issue Jun 17, 2020
mikeferguson added a commit that referenced this issue Jun 18, 2020
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

No branches or pull requests

2 participants