20 #include <cob_light/LightModes.h> 21 #include <cob_light/SetLightModeAction.h> 22 #include <cob_script_server/ScriptAction.h> 23 #include <cob_sound/SayAction.h> 24 #include <cob_actions/SetStringAction.h> 25 #include <cob_actions/SetStringGoal.h> 26 #include <geometry_msgs/Twist.h> 27 #include <sensor_msgs/JointState.h> 28 #include <sensor_msgs/Joy.h> 29 #include <sensor_msgs/JoyFeedbackArray.h> 30 #include <std_msgs/Float64MultiArray.h> 31 #include <std_msgs/ColorRGBA.h> 32 #include <std_srvs/Trigger.h> 124 void say(std::string text,
bool blocking);
126 void joy_cb(
const sensor_msgs::Joy::ConstPtr &joy_msg);
141 std::string comp_name = p->first;
142 ROS_DEBUG(
"component name: %s",comp_name.c_str());
146 ROS_WARN(
"invalid component, name: %s",comp_name.c_str());
149 for(std::map<std::string,XmlRpc::XmlRpcValue>::iterator ps=comp_struc.begin();ps!=comp_struc.end();++ps)
151 std::string par_name = ps->first;
152 ROS_DEBUG(
"par name: %s",par_name.c_str());
153 if(par_name.compare(
"twist_topic_name")==0)
158 std::string
s((std::string)twist_topic_name);
159 ROS_DEBUG(
"twist_topic_name found = %s",s.c_str());
160 tempComponent.twist_topic_name = s;
161 tempComponent.twist_controller_publisher_ =
n_.
advertise<geometry_msgs::Twist>((s),1);
163 if(par_name.compare(
"twist_safety_topic_name")==0)
165 ROS_DEBUG(
"twist saftey topic name found");
168 std::string
s((std::string)twist_safety_topic_name);
169 ROS_DEBUG(
"twist_safety_topic_name found = %s",s.c_str());
170 tempComponent.twist_safety_topic_name = s;
171 tempComponent.twist_safety_controller_publisher_ =
n_.
advertise<geometry_msgs::Twist>((s),1);
173 else if(par_name.compare(
"velocity_topic_name")==0)
178 std::string
s((std::string)vel_group_topic_name);
179 ROS_DEBUG(
"topic_name found = %s",s.c_str());
180 tempComponent.vel_group_topic_name = s;
181 tempComponent.vel_group_controller_publisher_ =
n_.
advertise<std_msgs::Float64MultiArray>((s),1);
183 else if(par_name.compare(
"sss_default_target")==0)
185 ROS_DEBUG(
"default target position found");
188 std::string
s((std::string)sss_default_target);
189 ROS_DEBUG(
"sss_default_target found = %s",s.c_str());
190 tempComponent.sss_default_target = s;
192 else if(par_name.compare(
"joint_velocity")==0)
197 ROS_DEBUG(
"joint_velocity.size: %d \n", joint_velocity.
size());
198 for(
int i=0;i<joint_velocity.
size();i++)
201 double vel((
double)joint_velocity[i]);
202 ROS_DEBUG(
"joint_velocity found = %f",vel);
203 tempComponent.joint_velocity.push_back(vel);
206 else if(par_name.compare(
"twist_max_velocity")==0)
211 ROS_DEBUG(
"twist_max_velocity.size: %d \n", twist_max_velocity.
size());
212 for(
int i=0;i<twist_max_velocity.
size();i++)
215 double vel((
double)twist_max_velocity[i]);
216 ROS_DEBUG(
"twist_max_velocity found = %f",vel);
217 tempComponent.twist_max_vel.push_back(vel);
220 else if(par_name.compare(
"twist_max_acc")==0)
225 ROS_DEBUG(
"twist_max_acc.size: %d \n", twist_max_acc.
size());
226 for(
int i=0;i<twist_max_acc.
size();i++)
229 double vel((
double)twist_max_acc[i]);
230 ROS_DEBUG(
"twist_max_acc found = %f",vel);
231 tempComponent.twist_max_acc.push_back(vel);
235 ROS_DEBUG(
"%s module stored",comp_name.c_str());
236 component_config_.insert(std::pair<std::string,component_config>(comp_name,tempComponent));
278 ROS_INFO(
"Switched to mode 1: move the base using twist controller");
279 saytext =
"Base mode";
283 ROS_INFO(
"Switched to mode 2: move the actuators to a default position (Trajectory controller)");
284 saytext =
"Default position mode";
288 ROS_INFO(
"Switched to mode 3: move the actuators using joint group velocity controller");
289 saytext =
"Velocity mode";
293 ROS_INFO(
"Switched to mode 4: move the actuators in cartesian mode using twist controller");
294 saytext =
"Cartesian mode";
302 sensor_msgs::JoyFeedbackArray joy_fb;
303 joy_fb.array.resize(4);
304 for (
unsigned int i=0; i<4; i++)
306 joy_fb.array[i].type=0;
307 joy_fb.array[i].id=i;
308 joy_fb.array[i].intensity=
static_cast<int>(
LEDS_[i]);
320 geometry_msgs::Twist base_cmd;
323 for(
unsigned int i=0; i<3; i++)
332 for(
int i =0; i<3; i++)
375 cob_sound::SayGoal say_goal;
376 say_goal.text = text;
389 cob_light::LightMode light;
390 light.mode = cob_light::LightModes::FLASH;
393 std_msgs::ColorRGBA
color;
399 light.colors.push_back(color);
400 cob_light::SetLightModeGoal light_goal;
401 light_goal.mode = light;
426 ROS_INFO(
"Switch mode button pressed");
449 ROS_INFO(
"Waiting for script server");
456 say(
"init and recover",
true);
460 std::string comp_name = p->first;
462 ROS_INFO(
"Init %s",comp_name.c_str());
463 std::string saytext = comp_name;
464 std::replace(saytext.begin(), saytext.end(),
'_',
' ');
472 std::string saytext =
"Init " + comp_name +
" failed";
473 std::replace(saytext.begin(), saytext.end(),
'_',
' ');
477 ROS_INFO(
"Recover %s",comp_name.c_str());
483 std::string saytext =
"Recover " + comp_name +
" failed";
484 std::replace(saytext.begin(), saytext.end(),
'_',
' ');
496 ROS_DEBUG(
"Mode 1: Move the base using twist controller");
557 ROS_DEBUG(
"Mode 2: Move the actuators to a default position (Trajectory controller)");
561 int component_sss_default_target_button_temp = -1;
562 std::string comp_name = p->first;
563 std::string component_sss_default_target_button = comp_name +
"_sss_default_target_button";
564 n_.
getParam(component_sss_default_target_button,component_sss_default_target_button_temp);
565 if (component_sss_default_target_button_temp == -1)
567 ROS_DEBUG(
"%s_sss_default_target_button parameter not defined",comp_name.c_str());
569 if(component_sss_default_target_button_temp>=0 && component_sss_default_target_button_temp<(
int)joy_msg->buttons.size() && joy_msg->buttons[component_sss_default_target_button_temp]==1)
575 std::string saytext =
"Move " + comp_name +
" to " +
script_goal_.parameter_name;
576 std::replace(saytext.begin(), saytext.end(),
'_',
' ');
586 ROS_DEBUG(
"Mode 3: Move the actuators using the group velocity controller");
590 int component_joint_button_temp = -1;
591 std::string comp_name = p->first;
593 for(
int i=0; i < size; ++i)
595 std::ostringstream component_joint_button_stream;
596 component_joint_button_stream << comp_name <<
"_joint" << i+1 <<
"_button";
597 std::string component_joint_button = component_joint_button_stream.str();
598 n_.
getParam(component_joint_button,component_joint_button_temp);
599 std_msgs::Float64MultiArray vel_cmd;
601 if(!(comp_name.find(
"left") != std::string::npos) && !(comp_name.find(
"right") != std::string::npos))
603 if(component_joint_button_temp>=0 && component_joint_button_temp<(
int)joy_msg->buttons.size() && joy_msg->buttons[component_joint_button_temp]==1 && joy_msg->buttons[
right_indicator_button_]==0 && joy_msg->buttons[
left_indicator_button_]==0)
606 ROS_INFO(
"%s velocity mode",comp_name.c_str());
622 else if(!(comp_name.find(
"left") != std::string::npos) && (comp_name.find(
"right") != std::string::npos))
624 if(component_joint_button_temp>=0 && component_joint_button_temp<(
int)joy_msg->buttons.size() && joy_msg->buttons[component_joint_button_temp]==1 && joy_msg->buttons[
right_indicator_button_]==1)
627 ROS_INFO(
"%s velocity mode",comp_name.c_str());
643 else if((comp_name.find(
"left") != std::string::npos) && !(comp_name.find(
"right") != std::string::npos))
645 if(component_joint_button_temp>=0 && component_joint_button_temp<(
int)joy_msg->buttons.size() && joy_msg->buttons[component_joint_button_temp]==1 && joy_msg->buttons[
left_indicator_button_]==1)
648 ROS_INFO(
"%s velocity mode",comp_name.c_str());
671 ROS_DEBUG(
"Mode 4: Move the actuators using the twist controller");
674 int component_twist_button_temp = -1;
675 std::string comp_name = p->first;
676 std::string component_twist_button = comp_name +
"_twist_button";
677 n_.
getParam(component_twist_button,component_twist_button_temp);
678 geometry_msgs::Twist twist_cmd;
679 if (component_twist_button_temp>=0 && component_twist_button_temp<(
int)joy_msg->buttons.size() && joy_msg->buttons[component_twist_button_temp]==1)
682 ROS_INFO(
"%s twist mode",comp_name.c_str());
686 twist_cmd.linear.x =0.0;
690 twist_cmd.linear.y =0.0;
694 twist_cmd.linear.z =0.0;
698 twist_cmd.angular.x =0.0;
702 twist_cmd.angular.y =0.0;
706 twist_cmd.angular.z =0.0;
721 ROS_ERROR(
"parameter components does not exist on ROS Parameter Server, aborting...");
779 cob_light::LightMode light;
780 light.mode = cob_light::LightModes::FLASH;
783 std_msgs::ColorRGBA
color;
789 light.colors.push_back(color);
795 light.colors.clear();
796 light.colors.push_back(color);
801 int main(
int argc,
char** argv)
808 while(cob_teleop.
n_.
ok())
std::string twist_safety_topic_name
std::vector< double > joint_velocity
std::vector< double > vel_base_
std::vector< double > vel_req_
ros::Publisher twist_controller_publisher_
std::string sss_default_target
std::string vel_group_topic_name
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
ros::Publisher twist_safety_controller_publisher_
SetLightClient_ * setlight_client_
ros::Subscriber joint_states_sub_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
std::string sound_action_name_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
UndockClient_ * undock_client_
actionlib::SimpleActionClient< cob_actions::SetStringAction > UndockClient_
std::string twist_topic_name
Type const & getType() const
void joy_cb(const sensor_msgs::Joy::ConstPtr &joy_msg)
std::vector< double > twist_max_vel
void init()
Initializes node to get parameters, subscribe to topics.
int right_indicator_button_
void say(std::string text, bool blocking)
XmlRpc::XmlRpcValue LEDS_
actionlib::SimpleActionClient< cob_sound::SayAction > SayClient_
actionlib::SimpleActionClient< cob_actions::SetStringAction > DockClient_
actionlib::SimpleActionClient< cob_light::SetLightModeAction > SetLightClient_
ros::Publisher vel_group_controller_publisher_
ScriptClient_ * sss_client_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
cob_light::SetLightModeGoal error_light_goal_
std::string undock_action_name_
std::vector< double > vel_old_
std::string getText() const
std::vector< double > twist_max_acc
std::string dock_action_name_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
#define ROS_DEBUG_STREAM(args)
cob_script_server::ScriptGoal script_goal_
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
actionlib::SimpleActionClient< cob_script_server::ScriptAction > ScriptClient_
sensor_msgs::JoyFeedbackArray switch_mode()
DockClient_ * dock_client_
bool getParam(const std::string &key, std::string &s) const
std::map< std::string, component_config > component_config_
std::string light_action_name_
cob_light::SetLightModeGoal confirm_light_goal_
SimpleClientGoalState getState() const
bool hasParam(const std::string &key) const
ResultConstPtr getResult() const
int left_indicator_button_
ROSCPP_DECL void spinOnce()
XmlRpc::XmlRpcValue components_
void getConfigurationFromParameters()
XmlRpc::XmlRpcValue led_mode_