Looking for Caresses
SoRo project to let Miro interact as a pet would do
 All Classes Functions Variables Pages
C_interaction.cpp
1 #include <string>
2 #include "../header/C_interaction.h"
3 
9 C_interaction::C_interaction(ros::NodeHandle nh, ros::Publisher pubPlat) {
10  notRead = true;
11  positiveApproach = 0;
12  negativeApproach = 0;
13  counterSound = 0;
14 
15  this->nh = nh;
16  this->pubPlat = pubPlat;
17 
18 }
19 
37 void C_interaction::classCallback(const std_msgs::String &pattern)
38 {
39 
40  if (!strcmp(pattern.data.c_str() , "CarBottomTop") || !strcmp(pattern.data.c_str() , "CarTopBottom")){
41  positiveApproach++;
42 
43  } else if (!strcmp(pattern.data.c_str() , "PatHead") || !strcmp(pattern.data.c_str() , "FixedHead")){
44  negativeApproach++;
45  }
46 
47 }
48 
49 
69 void C_interaction::showHappiness(int loneliness){
71  look_caresses_pkg::platform_control plat_msgs_happy;
72 
73  //sligtly move ears and tails to catture user attention
74  plat_msgs_happy.tail = 1 - (loneliness/100.0); //move tail faster if loneliness goes down
75  //TODO continuosly moving ears
76  //plat_msgs_awake.ear_rotate[0] = 0.2;
77  //plat_msgs_awake.ear_rotate[1] = 0.2;
78 
79  plat_msgs_happy.eyelid_closure = 0.4;
80 
81  srand(time(NULL));
82 
83  if (counterSound == 5){ //to not send too many sound consecutevely
84 
85  plat_msgs_happy.sound_index_P1 = 12 + rand()%5; // mammal alien sound
86  //plat_msgs_awake.sound_index_P2 = rand()%20; //pirate sound
87  counterSound = 0;
88  } else {
89  counterSound++;
90  }
91 
92  pubPlat.publish(plat_msgs_happy);
93 }
94 
101 int C_interaction::main(int loneliness)
102 {
103  notRead = true;
104  positiveApproach = 0;
105  negativeApproach = 0;
106  counterSound = 0;
107 
108  ROS_INFO("[C] Started");
109 
110  bool miroHappy = false;
111  subTopics();
112 
113  ROS_INFO("[C] I have a Loneliness value of: [%d]", loneliness);
114 
115  look_caresses_pkg::platform_control plat_msgs_caresses;
116  float body_config_caresses[4] = {0.0, 0.85, -0.25, -0.25}; // head down
117  float body_config_speed_caresses[4] = {0.0, -1.0, -1.0, -1.0};
118  for (int i =0; i<4; i++){
119  plat_msgs_caresses.body_config[i] = body_config_caresses[i];
120  plat_msgs_caresses.body_config_speed[i] = body_config_speed_caresses[i];
121  }
122 
123  ros::Rate loop_rate3(1);
124  for (int i =0; i<3; i++){
125  plat_msgs_caresses.sound_index_P1 = 12 + rand()%5; // mammal alien sound
126  pubPlat.publish(plat_msgs_caresses);
127  loop_rate3.sleep();
128  }
129 
131  srand(time(NULL));
132 
133  ros::Rate loop_rate(2); //0.5 s
134  while (ros::ok()){
135  /* positive approch increment at high rate: if a single caresses is given to miro,
136  the callback find (7-8?) times the pattern, so we increment loneliness only when positive approach
137  is sufficently high */
138  if (positiveApproach > 10){
139  loneliness--;
140  ROS_INFO("[C] I am becoming happier :) (loneliness:%d)", loneliness);
141  showHappiness(loneliness);
142 
143  positiveApproach = 0; //reset positive counter
144  }
145  if (negativeApproach > 25){ // 25 to be sure that the user DONT want to interact
146  //miroHappy = false;
147  ROS_INFO("[C] I'm going away :'( (loneliness: %d)", loneliness);
148  break; //exit because user does not want to interact
149  }
150  if (loneliness < (20 - rand() % 10)) {
151  ROS_INFO("[C] I am satisfied! (loneliness:%d)", loneliness);
152  //miroHappy = true;
153  break; //exit because miro is satisfied
154  }
155 
156  ros::spinOnce();
157  loop_rate.sleep();
158 
159  }
160 
161  unsubTopics();
162 
164  look_caresses_pkg::platform_control msg;
165  msg.body_vel.linear.x = -30; // good choiche for the linear velocity
166  msg.body_vel.angular.z = -0.05; // because miro turns unwanted
167  ros::Rate loop_rate2(1);
168  for (int i = 0; i<4; i++){
169  pubPlat.publish(msg);
170  loop_rate2.sleep();
171  }
172 
173  ROS_INFO("[C] Finished");
174  return loneliness;
175 
176 }
180 void C_interaction::subTopics(){
182  subClass = nh.subscribe("/miro/look4caresses/classifyGesture", 1000, &C_interaction::classCallback, this);
183 
184 }
185 
189 void C_interaction::unsubTopics(){
190  subClass.shutdown();
191 }
int main(int loneliness)
Main for Task C. The task updates the loneliness value if MiRo receive caresses, and make MiRo acts h...
C_interaction(ros::NodeHandle nh, ros::Publisher pubPlat)
Costructor for phase C task.