MiRo-Training
The aim of the project is to develop a software architecture for interacting with Miro using vocal and gestural commands.
 All Classes Files Functions Variables
good.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ################################################################
4 
5 import rospy
6 from std_msgs.msg import String
7 from sensor_msgs.msg import Image,CompressedImage,Range,Imu
8 from geometry_msgs.msg import Twist,Pose
9 import random
10 
11 import miro_msgs
12 from miro_msgs.msg import platform_config,platform_sensors,platform_state,platform_mics,platform_control,core_state,core_control,core_config,bridge_config,bridge_stream
13 
14 import opencv_apps
15 from opencv_apps.msg import CircleArrayStamped
16 
17 import math
18 import numpy
19 import time
20 import sys
21 from miro_constants import miro
22 
23 from datetime import datetime
24 
25 ## Function used for conversion from byteArray to String (The values that we get for the head touch sensors are byteArrays)
26 def fmt(x, f):
27  s = ""
28  x = bytearray(x)
29  for i in range(0, len(x)):
30  if not i == 0:
31  s = s + ", "
32  s = s + f.format(x[i])
33  return s
34 
35 ## \file good.py
36 ## \brief The node good.py implements the action corresponding to the command "Good".
37 ## @n The Robot moves up its head and move its tail.
38 ## @n The node subscribes to /platform/sensors and reads the values of the capacitive sensors on Miro's body and head.
39 ## @n When the user touches Miro it changes behavior and lightening pattern.
40 
41 ## The class GoodMode implements a cheerful behavior and allows to interact with Miro's capacitive body
42 
43 class GoodMode():
44 
45  def __init__(self):
46  ## Node rate
47  self.rate = rospy.get_param('rate',200)
48 
49  ## Initialization of head capacitive sensors
50  self.h1 = 0
51  self.h2 = 0
52  self.h3 = 0
53  self.h4 = 0
54  ## Initialization of bodycapacitive sensors
55  self.b1 = 0
56  self.b2 = 0
57  self.b3 = 0
58  self.b4 = 0
59 
60  ## Subscriber to the topic /miro/rob01/platform/sensors a message of type platform_sensors that cointains the information about the capacitive sensors.
61  self.sub_sensors_touch = rospy.Subscriber('/miro/rob01/platform/sensors', platform_sensors, self.callback_touch,queue_size =1)
62  ## Publisher to the topic /miro_good a message of type platform_control which corresponds to the "Good" action.
63  self.pub_platform_control = rospy.Publisher('/miro_good',platform_control,queue_size=0)
64 
65  ## Callback function that saves in class' attributes the capacitive sensor readings converted
66  def callback_touch(self, datasensor):
67 
68  self.h1 = int(fmt(datasensor.touch_head, '{0:.0f}')[0])
69  self.h2 = int(fmt(datasensor.touch_head, '{0:.0f}')[3])
70  self.h3 = int(fmt(datasensor.touch_head, '{0:.0f}')[6])
71  self.h4 = int(fmt(datasensor.touch_head, '{0:.0f}')[9])
72  self.b1 = int(fmt(datasensor.touch_body, '{0:.0f}')[0])
73  self.b2 = int(fmt(datasensor.touch_body, '{0:.0f}')[3])
74  self.b3 = int(fmt(datasensor.touch_body, '{0:.0f}')[6])
75  self.b4 = int(fmt(datasensor.touch_body, '{0:.0f}')[9])
76 
77 
78  ## Function that implements different behavior and lightening pattern depending on where it is touched
79 
80  def miro_good(self):
81 
82  r = rospy.Rate(self.rate)
83  q = platform_control()
84  count = 0
85  while not rospy.is_shutdown():
86 
87  q.sound_index_P1 = 1
88 
89  if self.h1 == 1 or self.h2 == 1 or self.h3 == 1 or self.h4 == 1:
90  q.eyelid_closure = 0.4
91  q.lights_raw = [255,64,64,255,64,64,255,64,64,255,64,64,255,64,64,255,64,64]
92  q.tail = 0.0
93  q.body_config = [0.2,0.5,0.2,-0.5]
94  q.body_config_speed = [0.0,-1.0,-1.0,-1.0]
95 
96  elif self.b1 == 1 or self.b2 == 1 or self.b3 == 1 or self.b4 == 1:
97  q.eyelid_closure = 0.1
98  q.lights_raw = [255,129,0,255,129,0,255,129,0,255,129,0,255,129,0,255,129,0]
99  q.tail = 0.0
100  q.body_config = [0.0,0.29,-0.6,-0.26]
101  q.body_config_speed = [0.0,-1.0,-1.0,-1.0]
102  q.ear_rotate = [0.5,0.5]
103  else:
104  q.eyelid_closure = 0.0
105  q.body_config = [0.0,0.25,0.0,-0.25]
106  q.body_config_speed = [0.0,-1.0,-1.0,-1.0]
107  q.tail = 68
108  q.lights_raw = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
109  q.ear_rotate = [0.0,0.0]
110  self.pub_platform_control.publish(q)
111 
112  r.sleep()
113 
114 
115 if __name__== '__main__':
116  rospy.init_node('good')
117  good = GoodMode()
118  good.miro_good()
b1
Initialization of bodycapacitive sensors.
Definition: good.py:55
h1
Initialization of head capacitive sensors.
Definition: good.py:50
def callback_touch
Callback function that saves in class' attributes the capacitive sensor readings converted.
Definition: good.py:66
The class GoodMode implements a cheerful behavior and allows to interact with Miro's capacitive body...
Definition: good.py:43
def miro_good
Function that implements different behavior and lightening pattern depending on where it is touched...
Definition: good.py:80
rate
Node rate.
Definition: good.py:47
sub_sensors_touch
Subscriber to the topic /miro/rob01/platform/sensors a message of type platform_sensors that cointain...
Definition: good.py:61
pub_platform_control
Publisher to the topic /miro_good a message of type platform_control which corresponds to the "Good" ...
Definition: good.py:63