21 #include <std_msgs/Float64.h> 22 #include <std_msgs/Float64MultiArray.h> 23 #include <controller_manager_msgs/LoadController.h> 24 #include <controller_manager_msgs/SwitchController.h> 25 #include <boost/thread/mutex.hpp> 57 ROS_ERROR(
"...Load service not available!");
69 ROS_ERROR(
"...Load service not available!");
73 std::string
param =
"max_command_silence";
80 ROS_ERROR(
"Parameter %s not set, using default 0.3s...", param.c_str());
85 param =
"joint_names";
88 ROS_ERROR(
"Parameter %s not set, shutting down node...", param.c_str());
92 std::string joint_trajectory_controller_name =
nh_.
param<std::string>(
"joint_trajectory_controller_name",
"joint_trajectory_controller");
101 std::string joint_group_position_controller_name =
nh_.
param<std::string>(
"joint_group_position_controller_name",
"joint_group_position_controller");
103 if (
nh_.
hasParam(joint_group_position_controller_name))
111 std::string joint_group_velocity_controller_name =
nh_.
param<std::string>(
"joint_group_velocity_controller_name",
"joint_group_velocity_controller");
113 if (
nh_.
hasParam(joint_group_velocity_controller_name))
160 controller_manager_msgs::LoadController load_srv;
161 load_srv.request.name = load_controller;
164 if (load_srv.response.ok)
166 ROS_INFO(
"%s loaded", load_controller.c_str());
176 ROS_ERROR(
"ServiceCall failed: load_controller");
183 bool switchController(std::vector< std::string > start_controllers, std::vector< std::string > stop_controllers)
185 controller_manager_msgs::SwitchController switch_srv;
186 switch_srv.request.start_controllers = start_controllers;
187 switch_srv.request.stop_controllers = stop_controllers;
188 switch_srv.request.strictness = 2;
192 if (switch_srv.response.ok)
194 std::string str_start;
195 std::string str_stop;
197 if (start_controllers.empty())
199 str_start =
"no_start_controller_defined";
203 str_start = start_controllers.back();
205 if (stop_controllers.empty())
207 str_stop =
"no_stop_controller_defined";
211 str_stop = stop_controllers.back();
214 ROS_INFO(
"Switched Controllers. From %s to %s", str_stop.c_str(), str_start.c_str());
221 ROS_ERROR(
"Could not switch controllers");
226 ROS_ERROR(
"ServiceCall failed: switch_controller");
232 void cmd_pos_cb(
const std_msgs::Float64MultiArray::ConstPtr& msg)
234 boost::mutex::scoped_lock lock(
mutex_);
238 void cmd_vel_cb(
const std_msgs::Float64MultiArray::ConstPtr& msg)
240 boost::mutex::scoped_lock lock(
mutex_);
246 if (!
nh_.
ok()) {
return;}
248 boost::mutex::scoped_lock lock(
mutex_);
262 ROS_ERROR(
"Unable to switch to velocity_controllers. Not executing command...");
266 ROS_INFO(
"Successfully switched to velocity_controllers");
278 ROS_ERROR(
"Unable to switch to position_controllers. Not executing command...");
282 ROS_INFO(
"Successfully switched to position_controllers");
293 ROS_INFO(
"Have not heard a pos command for %f seconds, switched back to trajectory_controller", period_pos.
toSec());
297 ROS_INFO(
"Have not heard a vel command for %f seconds, switched back to trajectory_controller", period_vel.
toSec());
307 ROS_ERROR(
"Unable to switch to trajectory_controller. Not executing command...");
352 int main(
int argc,
char** argv)
354 ros::init(argc, argv,
"cob_control_mode_adapter_node");
362 ROS_ERROR(
"Failed to initialize CobControlModeAdapter");
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
std::vector< std::string > joint_names_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
void update(const ros::TimerEvent &event)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::ServiceClient load_client_
std::vector< std::string > current_controller_names_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Subscriber cmd_vel_sub_
bool call(MReq &req, MRes &res)
bool has_traj_controller_
ros::Subscriber cmd_pos_sub_
void cmd_pos_cb(const std_msgs::Float64MultiArray::ConstPtr &msg)
std::vector< std::string > traj_controller_names_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool switchController(std::vector< std::string > start_controllers, std::vector< std::string > stop_controllers)
enum CobControlModeAdapter::@0 current_control_mode_
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
const std::string & getNamespace() const
double max_command_silence_
ros::ServiceClient switch_client_
#define ROS_DEBUG_STREAM(args)
int main(int argc, char **argv)
std::vector< std::string > vel_controller_names_
ros::Time last_vel_command_
void cmd_vel_cb(const std_msgs::Float64MultiArray::ConstPtr &msg)
bool getParam(const std::string &key, std::string &s) const
ros::Time last_pos_command_
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
bool loadController(std::string load_controller)
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)
std::vector< std::string > pos_controller_names_
ROSCPP_DECL void waitForShutdown()
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)