Aikido
RosRobot.hpp
Go to the documentation of this file.
1 #ifndef AIKIDO_ROBOT_ROS_ROSROBOT_HPP_
2 #define AIKIDO_ROBOT_ROS_ROSROBOT_HPP_
3 
4 #include <string>
5 
6 #include <controller_manager_msgs/ListControllers.h>
7 #include <controller_manager_msgs/LoadController.h>
8 #include <controller_manager_msgs/SwitchController.h>
9 #include <dart/utils/urdf/DartLoader.hpp>
10 
13 #include "aikido/robot/Robot.hpp"
14 
15 namespace aikido {
16 namespace robot {
17 namespace ros {
18 
20 
21 class RosRobot : public Robot
23 {
24 public:
31  RosRobot(
32  const dart::common::Uri& urdf,
33  const dart::common::Uri& srdf,
34  const std::string name,
35  const bool addDefaultExecutors,
36  const dart::common::ResourceRetrieverPtr& retriever
37  = std::make_shared<aikido::io::CatkinResourceRetriever>(),
38  const ::ros::NodeHandle& node = ::ros::NodeHandle(),
39  const std::string modeControllerName = "");
40 
44  RosRobot(
45  dart::dynamics::ReferentialSkeletonPtr refSkeleton,
46  Robot* rootRobot,
47  dart::collision::CollisionDetectorPtr collisionDetector,
48  std::shared_ptr<dart::collision::BodyNodeCollisionFilter> collisionFilter,
49  const std::string name,
50  const ::ros::NodeHandle& node = ::ros::NodeHandle(),
51  const std::string modeControllerName = "");
52 
54  virtual ~RosRobot() = default;
55 
61  void step(const std::chrono::system_clock::time_point& timepoint) override;
62 
71  dart::dynamics::ReferentialSkeletonPtr refSkeleton,
72  const std::string& name,
73  const std::string& modeControllerName = "");
74 
78  void deactivateExecutor() override;
79 
93  int registerExecutor(
95  std::string desiredName,
96  std::string controllerName,
97  hardware_interface::JointCommandModes controllerMode);
98 
110  int registerExecutor(
112  std::string desiredName,
113  std::string controllerName);
114 
123  bool activateExecutor(const int id) override;
124 
125  // This un-hides Robot::activateExecutor(const aikido::control::ExecutorType
126  // type) and Robot::activateExecutor(std::string id)
128 
134  void setRosControllerClients(const std::string modeControllerName);
135 
136 protected:
137  std::unordered_map<int, hardware_interface::JointCommandModes>
139  std::unordered_map<int, std::string> mRosControllerNames;
140 
141  // Ros node associated with this robot.
142  ::ros::NodeHandle mNode;
143 
144  // Ros list controller service client.
145  std::shared_ptr<::ros::ServiceClient> mRosListControllersServiceClient;
146 
147  // Ros load controller service client.
148  std::shared_ptr<::ros::ServiceClient> mRosLoadControllerServiceClient;
149 
150  // Ros switch controller service client.
151  std::shared_ptr<::ros::ServiceClient> mRosSwitchControllerServiceClient;
152 
153  // Ros joint mode command client.
154  // Default is nullptr so mode switching is impossible.
155  std::shared_ptr<aikido::control::ros::RosJointModeCommandClient>
157 
163  bool startController(const std::string startControllerName);
164 
170  bool stopController(const std::string stopControllerName);
171 
179  bool switchControllers(
180  const std::vector<std::string> startControllersNames,
181  const std::vector<std::string> stopControllersNames);
182 
188  bool loadController(const std::string loadControllerName);
189 
196  const hardware_interface::JointCommandModes jointMode);
197 
203  bool isControllerActive(const std::string controllerName);
204 };
205 
206 } // namespace ros
207 } // namespace robot
208 } // namespace aikido
209 
210 #endif // AIKIDO_ROBOT_ROS_ROSROBOT_HPP_
aikido::robot::ros::RosRobot::registerExecutor
int registerExecutor(aikido::control::ExecutorPtr executor, std::string desiredName, std::string controllerName, hardware_interface::JointCommandModes controllerMode)
Loads the controller.
aikido::robot::ros::RosRobot::mRosControllerModes
std::unordered_map< int, hardware_interface::JointCommandModes > mRosControllerModes
Definition: RosRobot.hpp:138
aikido::control::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.hpp:16
aikido::robot::Robot::activateExecutor
virtual bool activateExecutor(const int id)
Deactivates the current active executor.
aikido::robot::ros::RosRobot::mRosLoadControllerServiceClient
std::shared_ptr<::ros::ServiceClient > mRosLoadControllerServiceClient
Definition: RosRobot.hpp:148
aikido::robot::ros::RosRobot::registerSubRobot
RobotPtr registerSubRobot(dart::dynamics::ReferentialSkeletonPtr refSkeleton, const std::string &name, const std::string &modeControllerName="")
Registers a subset of the joints of the skeleton as a new RosRobot.
aikido
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
aikido::robot::ros::RosRobot
Robot interface augmented with ROS components.
Definition: RosRobot.hpp:22
RosJointModeCommandClient.hpp
aikido::robot::ros::RosRobot::activateExecutor
bool activateExecutor(const int id) override
Deactivates the current active executor.
aikido::robot::RobotPtr
std::shared_ptr< Robot > RobotPtr
Definition: Robot.hpp:35
aikido::robot::ros::RosRobot::startController
bool startController(const std::string startControllerName)
Starts the controller with name startControllerName.
aikido::robot::ros::RosRobot::mNode
::ros::NodeHandle mNode
Definition: RosRobot.hpp:142
aikido::robot::ros::RosRobot::mRosSwitchControllerServiceClient
std::shared_ptr<::ros::ServiceClient > mRosSwitchControllerServiceClient
Definition: RosRobot.hpp:151
aikido::robot::ros::RosRobot::switchControllerMode
bool switchControllerMode(const hardware_interface::JointCommandModes jointMode)
Switches the controller mode to jointMode.
aikido::robot::ros::RosRobot::~RosRobot
virtual ~RosRobot()=default
Destructor.
aikido::robot::ros::RosRobot::RosRobot
RosRobot(const dart::common::Uri &urdf, const dart::common::Uri &srdf, const std::string name, const bool addDefaultExecutors, const dart::common::ResourceRetrieverPtr &retriever=std::make_shared< aikido::io::CatkinResourceRetriever >(), const ::ros::NodeHandle &node=::ros::NodeHandle(), const std::string modeControllerName="")
Construct a new RosRobot object.
aikido::robot::ros::RosRobot::deactivateExecutor
void deactivateExecutor() override
Stops the controller corresponding to this executor and deactivates executor.
aikido::robot::ros::RosRobot::mRosListControllersServiceClient
std::shared_ptr<::ros::ServiceClient > mRosListControllersServiceClient
Definition: RosRobot.hpp:145
aikido::robot::ros::RosRobot::mRosJointModeCommandClient
std::shared_ptr< aikido::control::ros::RosJointModeCommandClient > mRosJointModeCommandClient
Definition: RosRobot.hpp:156
aikido::robot::ros::RosRobot::stopController
bool stopController(const std::string stopControllerName)
Stops the controller with name stopControllerName.
aikido::robot::ros::RosRobot::switchControllers
bool switchControllers(const std::vector< std::string > startControllersNames, const std::vector< std::string > stopControllersNames)
Stops the controller with name stopControllerName and starts the controller with name startController...
aikido::robot::ros::RosRobot::setRosControllerClients
void setRosControllerClients(const std::string modeControllerName)
Sets the ros controller clients which enable controller listing, loading, switching and mode switchin...
aikido::robot::ros::RosRobot::step
void step(const std::chrono::system_clock::time_point &timepoint) override
Steps the ros robot (and underlying executors and subrobots) through time.
aikido::robot::ros::RosRobot::mRosControllerNames
std::unordered_map< int, std::string > mRosControllerNames
Definition: RosRobot.hpp:139
aikido::robot::ros::RosRobot::isControllerActive
bool isControllerActive(const std::string controllerName)
Checks if the controller with name controllerName is active.
Robot.hpp
CatkinResourceRetriever.hpp
aikido::robot::ros::RosRobot::loadController
bool loadController(const std::string loadControllerName)
Loads the controller with name loadControllerName.
aikido::robot::Robot
Robot base class for defining basic behaviors common to most robots.
Definition: Robot.hpp:38
AIKIDO_DECLARE_POINTERS
#define AIKIDO_DECLARE_POINTERS(X)
Definition: pointers.hpp:21