21     if (mapActionHandler == 
nullptr) {
    22         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] the mapActionHandler in not initialized");
    38     std::string graspingActionsSrvName, actionInfoServiceName, 
    39       selectablePairInfoServiceName, handInfoServiceName, newGraspingActionServiceName;
    41     _nh->param<std::string>(
"/rosee/grasping_action_srv_name", graspingActionsSrvName, 
"grasping_actions_available");
    42     _nh->param<std::string>(
"/rosee/primitive_aggregated_srv_name", actionInfoServiceName, 
"primitives_aggregated_available");
    43     _nh->param<std::string>(
"/rosee/selectable_finger_pair_info", selectablePairInfoServiceName, 
"selectable_finger_pair_info");
    44     _nh->param<std::string>(
"/rosee/hand_info", handInfoServiceName, 
"hand_info");
    45     _nh->param<std::string>(
"/rosee/new_grasping_action_srv_name", newGraspingActionServiceName, 
"new_generic_grasping_action");
    66     rosee_msg::GraspingActionsAvailable::Request& request,
    67     rosee_msg::GraspingActionsAvailable::Response& response) {
    69     switch (request.action_type) {
    75             if (request.primitive_type == 0) { 
    77                 if (request.action_name.size() == 0 ) {            
    81                         for (
auto primitive : primitiveContainers.second) {
    87                     if (request.elements_involved.size() == 0) {
    95                         auto primitive =
_mapActionHandler->getPrimitive(request.action_name, request.elements_involved);
   102                 if (request.elements_involved.size() == 0) {
   106                             static_cast<ROSEE::ActionPrimitive::Type>(request.primitive_type-1))) {
   108                         for (
auto primitive : primitives) {
   116                             static_cast<ROSEE::ActionPrimitive::Type>(request.primitive_type-1), request.elements_involved)) {
   129             if (request.action_name.size() == 0) {
   141             if (request.action_name.size() == 0) {
   153             ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] request.actionType can only be 0(ALL), 1(PRIMITIVE), "   154                 << 
"2(GENERIC_and_COMPOSED), or 3(TIMED); I have received " << request.action_type);
   165     rosee_msg::GraspingAction primitiveMsg;
   167     if (primitive == 
nullptr) {
   173     primitiveMsg.primitive_type = primitive->getPrimitiveType();
   175     auto elements = primitive->getKeyElements();
   176     primitiveMsg.elements_involved.assign(elements.begin(), elements.end());
   183     rosee_msg::GraspingAction genericActionMsg;
   184     if (
generic == 
nullptr) {
   185         return genericActionMsg;
   190     genericActionMsg.primitive_type = genericActionMsg.PRIMITIVE_NONE;
   193     if ( composedCasted != 
nullptr) {
   197     return genericActionMsg;
   202     rosee_msg::GraspingAction timedActionMsg;
   203     if (timed == 
nullptr) {
   204         return timedActionMsg;
   209     timedActionMsg.primitive_type = timedActionMsg.PRIMITIVE_NONE;
   211     timedActionMsg.inner_actions = timed->getInnerActionsNames();
   213     for (
auto innerMargin : timed->getAllActionMargins()){
   214         timedActionMsg.before_time_margins.push_back(innerMargin.first);
   215         timedActionMsg.after_time_margins.push_back(innerMargin.second);
   218     return timedActionMsg;
   222                                                                rosee_msg::GraspingAction* graspingMsg) {
   224     graspingMsg->action_type = action->getType();
   225     graspingMsg->action_name = action->getName();
   228     for ( 
auto motorCount : action->getJointsInvolvedCount()) { 
   229         motorCountMsg.name.push_back(motorCount.first);
   230         motorCountMsg.count.push_back(motorCount.second);
   232     graspingMsg->action_motor_count = motorCountMsg;
   234     for ( 
auto motorPosMultiple : action->getAllJointPos()) {
   237         rosee_msg::MotorPosition motorPosMsg;
   238         for ( 
auto motorPos : motorPosMultiple) { 
   239             motorPosMsg.name.push_back(motorPos.first);
   240             motorPosMsg.position.push_back(motorPos.second.at(0)); 
   243         graspingMsg->action_motor_positions.push_back(motorPosMsg); 
   246     for (
auto elementInvolved : action->getFingersInvolved()) {
   247         graspingMsg->elements_involved.push_back(elementInvolved);
   252     rosee_msg::GraspingPrimitiveAggregatedAvailable::Request& request,
   253     rosee_msg::GraspingPrimitiveAggregatedAvailable::Response& response) {
   255      if (request.primitive_type == 0) { 
   257         if (request.action_name.size() == 0 ) {
   266             if (request.elements_involved.size() == 0) {
   274                 auto primitive =
_mapActionHandler->getPrimitive(request.action_name, request.elements_involved);
   281         if (request.elements_involved.size() == 0) {
   285                     static_cast<ROSEE::ActionPrimitive::Type>(request.primitive_type-1))) {
   294                     static_cast<ROSEE::ActionPrimitive::Type>(request.primitive_type-1), request.elements_involved)) {
   307     rosee_msg::GraspingPrimitiveAggregated primitiveMsg;
   309     primitiveMsg.action_name = primitiveMap.begin()->second->getName();
   310     primitiveMsg.primitive_type = primitiveMap.begin()->second->getPrimitiveType();
   314     primitiveMsg.max_selectable = primitiveMap.begin()->first.size();
   316     primitiveMsg.selectable_names =
   325     rosee_msg::GraspingPrimitiveAggregated primitiveMsg;
   326     primitiveMsg.action_name = primitive->getName();
   327     primitiveMsg.primitive_type = primitive->getPrimitiveType();
   329     auto elements = primitive->getKeyElements();
   330     primitiveMsg.max_selectable = elements.size();
   331     primitiveMsg.selectable_names.assign(elements.begin(), elements.end());
   338     rosee_msg::SelectablePairInfo::Request& request,
   339     rosee_msg::SelectablePairInfo::Response& response) {
   341     std::set<std::string> companionFingers;
   342     if (request.action_name.compare (
"pinchTight") == 0) {
   345                 ROSEE::ActionPrimitive::Type::PinchTight) ;
   347     } 
else if (request.action_name.compare (
"pinchLoose") == 0) {
   350                 ROSEE::ActionPrimitive::Type::PinchLoose) ;
   353         ROS_ERROR_STREAM ( 
"Received" << request.action_name << 
" that is not" <<
   354             "a recognizible action name to look for finger companions" );
   358     if (companionFingers.size() == 0) {
   363     for (
auto fing : companionFingers ) {
   364         response.pair_elements.push_back (fing);
   371         rosee_msg::HandInfo::Request& request,
   372         rosee_msg::HandInfo::Response& response) {
   374     if (! ros::service::exists(
"/EEHalExecutor/hand_info", 
false) ) {
   378     ros::ServiceClient handInfoClient = 
   379         _nh->serviceClient<rosee_msg::HandInfo>(
"/EEHalExecutor/hand_info");
   380     rosee_msg::HandInfo handInfoMsg;
   383     handInfoMsg.request = request;
   384     if (handInfoClient.call(handInfoMsg)) {
   386         response = handInfoMsg.response;
   398         rosee_msg::NewGenericGraspingActionSrv::Request& request,
   399         rosee_msg::NewGenericGraspingActionSrv::Response& response){
   401     response.accepted = 
false;
   402     response.emitted = 
false;
   404     if (request.newAction.action_name.empty()) {
   406         response.error_msg = 
"action_name can not be empty";
   407         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] " << response.error_msg);
   411     if (request.newAction.action_motor_position.name.size() == 0 ||
   412         request.newAction.action_motor_position.position.size() == 0 ||
   413         request.newAction.action_motor_position.position.size() != request.newAction.action_motor_position.name.size()) {
   415         response.error_msg = 
"action_motor_position is empty or badly formed";
   416         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] " << response.error_msg);
   421     if (request.newAction.action_motor_count.name.size() != request.newAction.action_motor_count.count.size()) {
   423         response.error_msg = 
"action_motor_count is badly formed, name and count have different sizes";
   424         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] " << response.error_msg);
   432     if (
_mapActionHandler->getGeneric(request.newAction.action_name, 
false) != 
nullptr) {
   434         response.error_msg = 
"A generic action with name '" + request.newAction.action_name + 
"' already exists";
   435         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] " << response.error_msg);
   444     std::set<std::string> elementInvolved;
   446     for (
int i = 0; i < request.newAction.action_motor_position.name.size(); i++){
   448         std::vector<double> one_dof{request.newAction.action_motor_position.position.at(i)};        
   449         jp.insert(std::make_pair(request.newAction.action_motor_position.name.at(i),
   453     for (
int i = 0; i < request.newAction.action_motor_count.name.size(); i++){
   455         jic.insert(std::make_pair(request.newAction.action_motor_count.name.at(i),
   456                                   request.newAction.action_motor_count.count.at(i)));
   459     for (
int i = 0; i< request.newAction.elements_involved.size(); i++) {
   461         elementInvolved.insert(request.newAction.elements_involved.at(i));  
   465     try { newAction = std::make_shared<ROSEE::ActionGeneric>(request.newAction.action_name,
   472         response.error_msg = 
"action_motor_position and action_motor_count have different names element. They must be the same because they refer to actuator of the end-effector";
   473         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] " << response.error_msg);
   482         response.error_msg = 
"error by mapActionHandler when inserting the new generic action";
   483         ROS_ERROR_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] " << response.error_msg);
   488     ROS_INFO_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] The new action '"<< newAction->getName() << 
"' is inserted in the system");
   491     if (request.emitYaml) {
   495         ROS_INFO_STREAM ( 
"[RosServiceHandler " << __func__ << 
" ] The received new action '"<< newAction->getName() << 
"' has been stored in " << path);
   496         response.emitted = 
true;
   499     response.accepted = 
true;
 std::map< std::string, std::vector< double > > JointPos
The map to describe the position of all actuated joints. 
bool graspingActionsCallback(rosee_msg::GraspingActionsAvailable::Request &request, rosee_msg::GraspingActionsAvailable::Response &response)
std::map< std::string, unsigned int > JointsInvolvedCount
The map to describe, how many times a joint is set by the action. 
std::shared_ptr< ActionComposed > Ptr
bool handInfoCallback(rosee_msg::HandInfo::Request &request, rosee_msg::HandInfo::Response &response)
RosServiceHandler(ros::NodeHandle *nh, ROSEE::MapActionHandler::Ptr, std::string path2saveYamlGeneric)
Default constructor. 
bool newGraspingActionCallback(rosee_msg::NewGenericGraspingActionSrv::Request &request, rosee_msg::NewGenericGraspingActionSrv::Response &response)
ros::ServiceServer _serverNewGraspingAction
A ActionComposed, which is formed by one or more Primitives (or even other composed). 
static std::vector< std::string > extract_keys_merged(std::map< std::set< std::string >, T > const &input_map, unsigned int max_string_number=0)
Extract all the string in the set keys of a map. 
MapActionHandler::Ptr _mapActionHandler
std::shared_ptr< ActionGeneric > Ptr
void fillCommonInfoGraspingActionMsg(ROSEE::Action::Ptr action, rosee_msg::GraspingAction *msg)
Internal function called by each of the fillGraspingActionMsg, it fills the GraspingAction message wi...
std::shared_ptr< ActionPrimitive > Ptr
std::string _path2saveYamlGeneric
std::vector< std::string > getInnerActionsNames() const 
std::shared_ptr< MapActionHandler > Ptr
rosee_msg::GraspingAction fillGraspingActionMsg(ROSEE::ActionPrimitive::Ptr primitive)
std::shared_ptr< ActionTimed > Ptr
std::shared_ptr< Action > Ptr
bool init(unsigned int nFinger)
ros::ServiceServer _serverPrimitiveAggregated
rosee_msg::GraspingPrimitiveAggregated fillPrimitiveAggregatedMsg(ROSEE::MapActionHandler::ActionPrimitiveMap primitiveMap)
ros::ServiceServer _serverHandInfo
ros::ServiceServer _server_selectablePairInfo
std::map< std::set< std::string >, ROSEE::ActionPrimitive::Ptr > ActionPrimitiveMap
ros::ServiceServer _serverGraspingActions
bool primitiveAggregatedCallback(rosee_msg::GraspingPrimitiveAggregatedAvailable::Request &request, rosee_msg::GraspingPrimitiveAggregatedAvailable::Response &response)
std::string createYamlFile(const std::map< std::set< std::string >, ActionPrimitive * > mapOfActions, const std::string actionName, std::string pathFolder)
Create/overwrite yaml file and emit info on it about each ActionPrimitive inside the given mapOfActio...
bool selectablePairInfoCallback(rosee_msg::SelectablePairInfo::Request &request, rosee_msg::SelectablePairInfo::Response &response)