Looking for Caresses
SoRo project to let Miro interact as a pet would do
 All Classes Functions Variables Pages
A_awakening.cpp
1 #include "std_msgs/String.h"
2 #include <cstdlib>
3 #include <iostream>
4 #include "../header/A_awakening.h"
5 
11 A_awakening::A_awakening(ros::NodeHandle nh, ros::Publisher pubPlat){
12  notRead = true;
13  touched = false;
14  this->nh = nh;
15  this->pubPlat = pubPlat;
16 }
17 
18 
23 void A_awakening::subTouchCallback(const look_caresses_pkg::platform_sensors &msg){
24  for(int i=0; i<4;i++){
25  if (msg.touch_head[i] == 1 || msg.touch_body[i] == 1){
26  touched = true;
27  ROS_INFO("[A] Hey, you woke me up!");
28  return;
29  }
30  }
31 }
32 
33 
41 int A_awakening::main(int loneliness)
42 {
43 
44  notRead = true;
45  touched = false;
46 
47  ROS_INFO("[A] Started");
48  subTopics();
49 
50  ROS_INFO("[A] I have a Loneliness value of: [%d]", loneliness);
51 
52 
55  // to publish kinematic and cosmetic thing to make miro look asleep
56  ROS_INFO("[A] I go to sleep");
57  look_caresses_pkg::platform_control plat_msgs_sleeping;
58  plat_msgs_sleeping.eyelid_closure = 0.8;
59  float body_config_sleeping[4] = {0.0, 1.0, 0, -0.1}; // head down
60  float body_config_speed_sleeping[4] = {0.0, -1.0, -1.0, -1.0};
61  for (int i =0; i<4; i++){
62  plat_msgs_sleeping.body_config[i] = body_config_sleeping[i];
63  plat_msgs_sleeping.body_config_speed[i] = body_config_speed_sleeping[i];
64  }
65 
67  ros::Rate loop_rate(2); // 1 Hz
68  srand(time(NULL));
69  while(ros::ok() && !touched){
70 
71  if (loneliness > (50 + rand() % 50)){
72  break;
73  }
74 
75  if (loneliness < 100){
76  loneliness++;
77  }
78  pubPlat.publish(plat_msgs_sleeping);
79  ros::spinOnce(); // need to receive touchedCallback
80  ROS_INFO("[A] Sleeping... loneliness = %d", loneliness);
81  loop_rate.sleep();
82  }
83 
84  ROS_INFO("[A] I am awake =) with Loneliness value of: %d", loneliness);
85 
89  look_caresses_pkg::platform_control plat_msgs_awake;
90  plat_msgs_awake.eyelid_closure = 0.1;
91 
92  //put miro head s.t. camera can work properly for face detection
93  float body_config_awake[4] = {0.0, 0.6, 0, -0.1};
94  float body_config_speed_awake[4] = {0.0, -1.0, -1.0, -1.0};
95  for (int i =0; i<4; i++){
96  plat_msgs_awake.body_config[i] = body_config_awake[i];
97  plat_msgs_awake.body_config_speed[i] = body_config_speed_awake[i];
98  }
99  //sligtly move ears and tails to catture user attention
100  plat_msgs_awake.tail = -0.2;
101  plat_msgs_awake.ear_rotate[0] = 0.2;
102  plat_msgs_awake.ear_rotate[1] = 0.2;
103  srand(time(NULL));
104 
105  //publish cosmetic thing to show awakening
106  ros::Rate loop_rate2(1);
107  for (int i =0; i<5; i++){
108  plat_msgs_awake.blink_time = 5 + rand()%20;
109  //plat_msgs_awake.sound_index_P1 = rand()%32; // mammal alien sound
110  plat_msgs_awake.sound_index_P2 = rand()%20; //pirate sound
111  pubPlat.publish(plat_msgs_awake);
112  //ros::spinOnce();
113  loop_rate2.sleep();
114  }
115 
116  unsubTopics();
117 
118  ROS_INFO("[A] Finished");
119  return loneliness;
120 }
121 
125 void A_awakening::subTopics(){
126 
127  //Subscribed topics
128 
129  // sub to see if miro is touched while sleeping
130  subTouched = nh.subscribe("/miro/rob01/platform/sensors", 1000, &A_awakening::subTouchCallback, this);
131 }
132 
133 
137 void A_awakening::unsubTopics(){
138  subTouched.shutdown();
139 }
int main(int loneliness)
Phase A: awakening. This fucntion randomly awake MiRo basising on loneliness value. While sleeping, loneliness increases, thus probability of awakening increases. Plus, if MiRo is touched, it wakes up immediately.
Definition: A_awakening.cpp:41
A_awakening(ros::NodeHandle nh, ros::Publisher pubPlat)
Costructor for phase A task.
Definition: A_awakening.cpp:11