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
gbb_miro.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 
10 import miro_msgs
11 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
12 
13 import math
14 import numpy
15 import time
16 import sys
17 from miro_constants import miro
18 
19 from datetime import datetime
20 
21 ## \file gbb_miro.py
22 ## \brief The node gbb_miro.py subscribes to the linear and angular velocity mapped in the imu_data_map node and publish a platform_control message
23 ## @n A platform_control message contains linear and angular velocities, the lightening pattern of miro's body and other tipes of messages @n.
24 ## @n More in details:
25 ## @n Subscribe to the topic /imu_mapping
26 ## @n Read from that topic the value from the smartwatch correctly mapped into miro body velocity
27 ## @n Publish on /gbb a platform_control msg containing miro body velocity and a lightening pattern based on smartwatch commands
28 ## @n For example: if the command of the smartwatch is a rotation towards right miro will turn right and the right part of its body will lit
29 
30 ##\brief The class GestureBased implements the Gesture based behavior
31 
32 class GestureBased():
33  ## Constructor
34  def __init__(self):
35 
36  ## Linear and Angular velocities that will be part of the platform_control message
37  self.body_vel=Twist()
38 
39  ## Subscriber to the topic /imu_mapping a message of type Twist
40  self.sub_imu_mapping = rospy.Subscriber('/imu_mapping',Twist,self.callback_gbb,queue_size=1)
41 
42  ## Publisher on the topic /gbb a message of type platform_control which corresponds to the Gesture Based Behavior
43  self.pub_platform_control = rospy.Publisher('/gbb', platform_control, queue_size=0)
44 
45 
46  ## Callback function that receive the Twist message and set the miro's body lightening pattern to construct the platform_control message to publish
47 
48  def callback_gbb(self,vel_msg):
49 
50  q=platform_control()
51 
52 
53  self.body_vel.linear.x = vel_msg.linear.x
54  self.body_vel.angular.z = vel_msg.angular.z
55 
56  q.body_vel = self.body_vel
57 
58  #lightening pattern
59 
60  if -5< vel_msg.linear.x < 5 and -0.1 < vel_msg.angular.z<0.1 :
61  q.lights_raw = [0,255,255,0,255,255,0,255,255,0,255,255,0,255,255,0,255,255]
62 
63  if vel_msg.angular.z > 0 and vel_msg.angular.z > 0.1 :
64  q.lights_raw = [0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0]
65 
66  if vel_msg.angular.z < 0 and vel_msg.angular.z < - 0.1 :
67  q.lights_raw = [0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255]
68 
69  self.pub_platform_control.publish(q)
70 
71 
72  #rospy.loginfo(sonar_msg.sonar_range)
73 
74  def main (self):
75  rospy.spin()
76 
77 if __name__== '__main__':
78  rospy.init_node('gbb_miro')
79  gesture_based = GestureBased()
80 gesture_based.main()
pub_platform_control
Publisher on the topic /gbb a message of type platform_control which corresponds to the Gesture Based...
Definition: gbb_miro.py:43
def callback_gbb
Callback function that receive the Twist message and set the miro's body lightening pattern to constr...
Definition: gbb_miro.py:48
The class GestureBased implements the Gesture based behavior.
Definition: gbb_miro.py:32
sub_imu_mapping
Subscriber to the topic /imu_mapping a message of type Twist.
Definition: gbb_miro.py:40
body_vel
Linear and Angular velocities that will be part of the platform_control message.
Definition: gbb_miro.py:37
def __init__
Constructor.
Definition: gbb_miro.py:34