SMACC
Loading...
Searching...
No Matches
cp_ros_control_interface.cpp
Go to the documentation of this file.
2
3#include <controller_manager_msgs/ListControllerTypes.h>
4#include <controller_manager_msgs/ListControllers.h>
5#include <controller_manager_msgs/LoadController.h>
6#include <controller_manager_msgs/ReloadControllerLibraries.h>
7#include <controller_manager_msgs/SwitchController.h>
8#include <controller_manager_msgs/UnloadController.h>
9
10namespace smacc
11{
12namespace components
13{
14using namespace controller_manager_msgs;
15
17{
18}
19
21{
22}
23
25{
26 srvListControllers = nh_.serviceClient<ListControllers>(*serviceName_);
27 srvListControllersTypes = nh_.serviceClient<ListControllerTypes>(*serviceName_);
28
29 srvLoadController = nh_.serviceClient<LoadController>(*serviceName_);
30 srvUnloadController = nh_.serviceClient<UnloadController>(*serviceName_);
31 srvReloadControllerLibraries = nh_.serviceClient<ReloadControllerLibraries>(*serviceName_);
32 srvSwitchControllers = nh_.serviceClient<SwitchController>(*serviceName_);
33}
34
35std::vector<controller_manager_msgs::ControllerState> CpRosControlInterface::listControllers()
36{
37 ListControllers::Request req;
38 ListControllers::Response res;
39
40 srvListControllers.call(req, res);
41 return res.controller;
42}
43
44std::vector<ControllerTypeInfo> CpRosControlInterface::listControllerTypes()
45{
46 ListControllerTypes::Request req;
47 ListControllerTypes::Response res;
48 srvListControllersTypes.call(req, res);
49
50 std::vector<ControllerTypeInfo> ret;
51 for (int i = 0; i < res.types.size(); i++)
52 {
54 entry.type = res.types[i];
55 entry.baseClass = res.base_classes[i];
56
57 ret.push_back(entry);
58 }
59
60 return ret;
61}
62
64{
65 LoadController::Request req;
66 LoadController::Response res;
67 req.name = name;
68
69 srvLoadController.call(req, res);
70 return res.ok;
71}
72
74{
75 UnloadController::Request req;
76 UnloadController::Response res;
77
78 req.name = name;
79 srvUnloadController.call(req, res);
80 return res.ok;
81}
82
84{
85 ReloadControllerLibraries::Request req;
86 ReloadControllerLibraries::Response res;
87 req.force_kill = forceKill;
88
89 srvReloadControllerLibraries.call(req, res);
90
91 return res.ok;
92 //srvReloadControllerLibraries
93}
94
95bool CpRosControlInterface::switchControllers(std::vector<std::string> start_controllers,
96 std::vector<std::string> stop_controllers,
97 Strictness strictness)
98{
99 SwitchController::Request req;
100 SwitchController::Response res;
101
102 req.start_controllers = start_controllers;
103 req.stop_controllers = stop_controllers;
104 req.strictness = strictness;
105
106 srvSwitchControllers.call(req, res);
107
108 return res.ok;
109}
110}
111}
bool switchControllers(std::vector< std::string > start_controllers, std::vector< std::string > stop_controllers, Strictness strictness)
std::vector< controller_manager_msgs::ControllerState > listControllers()
std::vector< ControllerTypeInfo > listControllerTypes()