Code activity 1 in NAO robot in Python 2.7.18
Abstract
Code activity 1 in NAO robot in Python 2.7.18
Full text
Uses of robotics to improve the instrumental skills of students with Autism Spectrum Disorder through the development of new inclusive contexts (DivInTech) NAO’s code of DivInTech 1 NAO File 1: main.py 1# ! / usr / bin / env pyt h on 2# −*− enco ding : UTF−8 −*− 3import logging 4import threading 5import signal 6 7from tad_conNAO import * 8from tad_conActivity import * 9from tad_conCamera import * 10 11 " " "++++++++++++++++++++++++++++++++++++++ 12 Class 13 Name : G r a c e f u l K i l l e r 14 Func t i o n : d e t e c t t h e s i g i n t and s i g t e r m t o f i n i s h t h e program 15 Paramete rs : − 16 Retu rn : − 17 ++++++++++++++++++++++++++++++++++++++" " " 18 class GracefulKiller : 19 def _ _ i n i t _ _ ( s e l f , mutex ) : 20 s i g n a l . s i g n a l ( s i g n a l . SIGINT , s e l f . e x i t _ g r a c e f u l l y ) 21 s i g n a l . s i g n a l ( s i g n a l . SIGTERM, s e l f . e x i t _ g r a c e f u l l y ) 22 s e l f . mutex = mutex 23 s e l f . k i l l _ n o w = F a l s e 24 def exit_gracefully(self , *a r g s ) : 25 s e l f . mutex . a c q u i r e ( ) This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
26 s e l f . k i l l _ n o w = True 27 s e l f . mutex . r e l e a s e ( ) 28 29 " " "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 30 Name : main 31 Func t i o n : main o f t he p r o j e c t 32 Paramete rs : − 33 Retu rn : − 34 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−" " " 35 def main ( ) : 36 # C re at e t h e mutex 37 k i l l e r _ m u t e x = t h r e a d i n g . Lock ( ) 38 message_mutex = t h r e a d i n g . Lock ( ) 39 cam_message_mutex = t h r e a d i n g . Lock ( ) 40 image_mutex = t h r e a d i n g . Lock ( ) 41 42 # Creat e CTRL + C d e t e c t o r 43 k i l l e r = G r a c e f u l K i l l e r ( k i l l e r _ m u t e x ) 44 45 # Creat e t he l o g f i l e 46 l o g g i n g . b a s i c C o n f i g ( f i l e n a m e = ’ myapp . l og ’ , l e v e l = l o g g i n g . INFO ,format= ’%( c r e a t e d ) f %(message ) s ’ ) 47 # TODO: g i v e t h e l o g g i n g t o t h e t a d s t o show an e r r o r o f c o n n e c t i o n 48 49 # C re at e t h e TADs 50 tad_NAO = TAD_conNAO( loggin g , message_mutex , image_mutex , cam_message_mutex ) 51 t a d _ a c t i v i t y = TAD_conActivity ( l og gi ng , k i l l e r , k i l l e r _ m u t e x , message_mutex , tad_NAO ) 52 tad_ c amera = TAD_conCamera_Image ( l ogging , k i l l e r , k i l l e r _ m u t e x , image_mutex , tad_NAO ) 53 tad_com_camera = TAD_conCamera ( l og gi ng , k i l l e r , k i l l e r _ m u t e x , cam_message_mutex , tad_NAO ) 54 55 # Creat e t he a c t i v i t y t h re a d 56 l o g g in g . i n f o ( " Main : b e f o r e r u nnin g t h r e a d a c t i v i t y " ) 57 t a d _ a c t i v i t y . s t a r t ( ) 58 l o g g in g . i n f o ( " Main : r u n ning t h r e a d a c t i v i t y " ) 59 60 # C re ate t h e camera t h r e a d 61 l o g g i n g . i n f o ( " Main : b e f o r e r u nn ing t h r e a d camera " ) 62 tad_ c amera . s t a r t ( ) 63 l o g g i n g . i n f o ( " Main : r u nn ing t h r e a d camera " ) 64 65 # C re ate t h e com camera t h r e a d 66 l o g g i n g . i n f o ( " Main : b e f o r e r u nn ing t h r e a d com_camera " ) 67 tad_com_camera . s t a r t ( ) 68 l o g g i n g . i n f o ( " Main : r u nn ing t h r e a d com_camera " ) This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
69 70 # Main loo p 71 k i l l e r _ m u t e x . a c q u i r e ( ) 72 while not k i l l e r . k i l l _ n o w : 73 k i l l e r _ m u t e x . r e l e a s e ( ) 74 tad_NAO . motor ( ) 75 76 k i l l e r _ m u t e x . a c q u i r e ( ) 77 k i l l e r _ m u t e x . r e l e a s e ( ) 78 79 # Wait t h e t h r e a d t o end 80 l o g g i n g . i n f o ( " Main : w a it f o r t h e t h r e a d s t o f i n i s h " ) 81 t a d _ a c t i v i t y . j o i n ( ) 82 tad_ c amera . j o i n ( ) 83 tad_com_camera . j o i n ( ) 84 l o g g i n g . i n f o ( " Main : a l l done " ) 85 86 i f __name__ == " __main__ " : 87 main ( ) This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
File 2: tad_conActivity.py 1# ! / usr / bin / env pyt h on 2# −*− enco ding : UTF−8 −*− 3""" ///////////////////////////////////////////////////////////////////////////// 4Name : t a d _ c o n A c t i v i t y . py 5F un c ti o n : F i l e w it h t h e TAD t h a t makes t h e s o c k e t c o n n e c t i o n w i t h t h e a c t i v i t y . 6L as t m o d i f i e d : 0 1 /0 1 /2 0 23 7Create d by : SCV 8///////////////////////////////////////////////////////////////////////////// """ 9 10 11 " " "++++++++++++++++++++++++++++++++++++++ 12 Libraries 13 ++++++++++++++++++++++++++++++++++++++" " " 14 # General 15 import s u b p r o c e s s 16 import socket 17 import threading 18 19 " " "++++++++++++++++++++++++++++++++++++++ 20 ENUM 21 ++++++++++++++++++++++++++++++++++++++" " " 22 class STATE ( ) : 23 INIT_CONNECTION = 0 # I n i t s o c k e t 24 WAIT_MESSAGE = 1 # Wait a message from t h e a c t i v i t y 25 WAIT_TO_RESPONSE = 2 # Wait u n t i l t h e u s e r a ns wer s 26 SEND_MESSAGE = 3 #Send a message t o t h e a c t i v i t y 27 28 " " "++++++++++++++++++++++++++++++++++++++ 29 Class 30 ++++++++++++++++++++++++++++++++++++++" " " 31 32 class TAD_conActivity ( t h r e a d i n g . Thread ) : 33 34 MAX_TIMES_TRYING_TO_RECONNECT = 5 35 36 " " "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 37 Name : _ _ i n i t _ _ 38 Func t i o n : i n i t o f t he c l a s s 39 Par amet er s : l o g g i n g : w r i t e s i n a l o g f i l e 40 k i l l e r : d e t e c t o r o f CTRL + C 41 k i l l e r _ m u t e x : mutex f o r t h e k i l l e r 42 message_mutex : mutex f o r t h e message 43 tad_NAO : nao c l a s s This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
44 Retu rn : − 45 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−" " " 46 def _ _ i n i t _ _ ( s e l f , l og gi ng , k i l l e r , k i l l e r _ m u t e x , message_mutex , tad_NAO ) : 47 super( TAD_conActivity , s e l f ) . _ _ i n i t _ _ ( group=None , t a r g e t = None , 48 name=None , v e r b o s e =None ) 49 self . logging = logging 50 s e l f . k i l l e r = k i l l e r 51 s e l f . k i l l e r _ m u t e x = k i l l e r _ m u t e x 52 self . message_mutex = message_mutex 53 s e l f . tad_NAO = tad_NAO 54 # S o c k e t C re at e 55 s e l f . s e r v e r _ s o c k e t = s o c k e t . s o c k e t ( s o c k e t . AF_INET , s o c k e t .SOCK_STREAM) 56 # s e l f . s e r v e r _ s o c k e t . s e t t i m e o u t ( 5 . 0 ) 57 s e l f . host_name = s o c k e t . gethost name ( ) 58 s e l f . h o s t _ i p = s o c k e t . getho stby name ( s e l f . host_name ) 59 # C o nnect i on t o a c t i v i t y 60 s e l f . h o s t _ i p = raw_input ( " I n t r o d u c e t h i s computer IP ( d e f a u l t = 1 9 2 . 1 6 8 . 1 . 1 0 4 ) : \ n " ) 61 i f s e l f . h o s t _ i p == " " : 62 s e l f . h o s t _ i p = " 1 9 2 . 1 6 8 . 1 . 1 0 4 " 63 print( ’HOST IP : ’ , s e l f . h o s t _ i p ) 64 s e l f . p o r t = 8080 65 s e l f . s o c k e t _ a d d r e s s = ( s e l f . h o st _ip , s e l f . p o r t ) 66 # S o c k e t Bind 67 s e l f . s e r v e r _ s o c k e t . bind ( s e l f . s o c k e t _ a d d r e s s ) 68 s e l f . s t a t e = STATE . INIT_CONNECTION 69 70 " " "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 71 Name : motor 72 Func t i o n : motor o f t h e c l a s s 73 Paramete rs : − 74 Retu rn : − 75 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−" " " 76 def run ( s e l f ) : 77 s e l f . k i l l e r _ m u t e x . a c q u i r e ( ) 78 while not s e l f . k i l l e r . k i l l _ n o w : 79 s e l f . k i l l e r _ m u t e x . r e l e a s e ( ) 80 try : 81 i f s e l f . s t a t e == STATE . INIT_CONNECTION : 82 83 # S o ck e t L i s t e n 84 s e l f . s e r v e r _ s o c k e t . l i s t e n ( 5 ) 85 s e l f . c l i e n t _ s o c k e t , s e l f . add r = s e l f . s e r v e r _ s o c k e t . a c c e p t ( ) 86 # TODO: Try i f i t works 87 # s e l f . c l i e n t _ s o c k e t . s e t t i m e o u t ( 5 . 0 ) This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
88 s e l f . l o g g i n g . i n f o ( " A c t i v i t y : Ac cepted " ) 89 s e l f . message_mutex . a c q u i r e ( ) 90 i f s e l f . tad_NAO . message == "OK\ 0 " : 91 s e l f . s t a t e = STATE .SEND_MESSAGE 92 e l i f s e l f . tad_NAO . message == " " : 93 s e l f . s t a t e = STATE .WAIT_MESSAGE 94 else : 95 s e l f . s t a t e = STATE . WAIT_TO_RESPONSE 96 s e l f . message_mutex . r e l e a s e ( ) 97 98 e l i f s e l f . s t a t e == STATE .WAIT_MESSAGE: 99 s e l f . message_mutex . a c q u i r e ( ) 100 # TODO: Try i f i t works 101 s e l f . c l i e n t _ s o c k e t . s e t b l o c k i n g ( 0 ) 102 103 s e l f . tad_NAO . message = s e l f . c l i e n t _ s o c k e t . r e c v ( 5 0 0 ) . decode ( " u t f −8 " ) 104 i f s e l f . tad_NAO . message != −1: 105 s e l f . l o g g i n g . i n f o ( " A c t i v i t y : R ecei ved : " + s e l f . tad_NAO . message . decode ( " hex " ) ) 106 else : 107 s e l f . tad_NAO . message = " " 108 # i f s e l f . tad_NAO . message [ 0 : 2 ] . decode ( " hex " ) == ’E ’ : 109 # s e l f . s t a t e = STATE . INIT_CONNECTION 110 # e l s e : 111 # s e l f . s t a t e = STATE . WAIT_TO_RESPONSE 112 i f s e l f . tad_NAO . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’F ’ : 113 s e l f . k i l l e r . k i l l _ n o w = True 114 115 s e l f . message_mutex . r e l e a s e ( ) 116 s e l f . s t a t e = STATE . WAIT_TO_RESPONSE 117 118 119 e l i f s e l f . s t a t e == STATE . WAIT_TO_RESPONSE : 120 s e l f . message_mutex . a c q u i r e ( ) 121 i f s e l f . tad_NAO . message == "OK\ 0 " . encode ( ’ hex ’ ) : 122 s e l f . s t a t e = STATE .SEND_MESSAGE 123 e l i f s e l f . tad_NAO . message == "CONTINUE\ 0 " . encode ( ’ hex ’ ) : 124 s e l f . tad_NAO . message = " " 125 s e l f . s t a t e = STATE .WAIT_MESSAGE 126 e l i f s e l f . tad_NAO . message == "SOMETHING\ 0 " . encode ( ’ hex ’ ) : 127 s e l f . c l i e n t _ s o c k e t . send ( "PP \0 " . encode ( ’ hex ’ ) ) This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
128 s e l f . tad_NAO . message = " " 129 s e l f . s t a t e = STATE .WAIT_MESSAGE 130 s e l f . message_mutex . r e l e a s e ( ) 131 132 e l i f s e l f . s t a t e == STATE .SEND_MESSAGE: 133 s e l f . c l i e n t _ s o c k e t . send ( "OK\ 0 " . encode ( ’ hex ’ ) ) 134 print( " A c t i v i t y : S ent : OK" ) 135 s e l f . l o g g i n g . i n f o ( " A c t i v i t y : S ent : OK" ) 136 s e l f . message_mutex . a c q u i r e ( ) 137 s e l f . tad_NAO . message = " " 138 s e l f . message_mutex . r e l e a s e ( ) 139 s e l f . s t a t e = STATE .WAIT_MESSAGE 140 exce pt Runt i meErro r : 141 s e l f . l o g g i n g . e r r o r ( " A c t i v i t y : D i s co nn ec t e d " ) 142 print( "ERROR, Dis c o nnect e d from t h e a c t i v i t y . . . \ n " ) 143 s e l f . s t a t e = STATE . INIT_CONNECTION 144 exce pt s o c k e t . e r r o r as e : 145 i f s e l f . tad_NAO . message == "OK\ 0 " . encode ( ’ hex ’ ) : 146 s e l f . s t a t e = STATE .SEND_MESSAGE 147 else : 148 s e l f . s t a t e = STATE .WAIT_MESSAGE 149 s e l f . message_mutex . r e l e a s e ( ) 150 s e l f . c l i e n t _ s o c k e t . s e t b l o c k i n g ( 1 ) 151 152 153 s e l f . k i l l e r _ m u t e x . a c q u i r e ( ) 154 155 s e l f . k i l l e r _ m u t e x . r e l e a s e ( ) This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
File 3: tad_conCamera.py 1# ! / usr / bin / env pyt h on 2# −*− enco ding : UTF−8 −*− 3""" ///////////////////////////////////////////////////////////////////////////// 4Name: tad_conCamera . py 5F un c ti o n : F i l e w it h t h e TAD t h a t makes t h e s o c k e t c o n n e c t i o n t o send images from 6t h e NAO camera . 7L as t m o d i f i e d : 3 0 /0 1 /2 0 23 8Create d by : SCV 9///////////////////////////////////////////////////////////////////////////// """ 10 11 12 " " "++++++++++++++++++++++++++++++++++++++ 13 Libraries 14 ++++++++++++++++++++++++++++++++++++++" " " 15 # General 16 import s u b p r o c e s s 17 import socket 18 import pickle 19 import struct 20 import threading 21 22 " " "++++++++++++++++++++++++++++++++++++++ 23 ENUM 24 ++++++++++++++++++++++++++++++++++++++" " " 25 class STATE ( ) : 26 INIT_CONNECTION = 0 # I n i t s o c k e t 27 SEND_IMAGE = 1 # Send a image t o t he camera v i s i o n 28 CHECK_MESSAGE = 2 #Check message o f t h e a c t i v i t y 29 WAIT_RESPONSE = 3 30 31 " " "++++++++++++++++++++++++++++++++++++++ 32 Class 33 ++++++++++++++++++++++++++++++++++++++" " " 34 35 class TAD_conCamera_Image ( t h r e a d i n g . Thread ) : 36 37 MAX_TIMES_TRYING_TO_RECONNECT = 5 38 39 " " "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 40 Name : _ _ i n i t _ _ 41 Func t i o n : i n i t o f t he c l a s s 42 Par amet er s : l o g g i n g : w r i t e s i n a l o g f i l e 43 k i l l e r : d e t e c t o r o f CTRL + C This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
44 k i l l e r _ m u t e x : mutex f o r t h e k i l l e r 45 image_mutex : mutex f o r t h e images 46 tad_NAO : nao c l a s s 47 Retu rn : − 48 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−" " " 49 def _ _ i n i t _ _ ( s e l f , l og gi ng , k i l l e r , k i l l e r _ m u t e x , image_mutex , tad_NAO ) : 50 super( TAD_conCamera_Image , s e l f ) . _ _ i n i t _ _ ( group=None , t a r g e t =None , 51 name=None , v e r b o s e =None ) 52 self . logging = logging 53 s e l f . k i l l e r = k i l l e r 54 s e l f . k i l l e r _ m u t e x = k i l l e r _ m u t e x 55 s e l f . image_mutex = image_mutex 56 s e l f . tad_NAO = tad_NAO 57 # S o c k e t C re at e 58 s e l f . s e r v e r _ s o c k e t = s o c k e t . s o c k e t ( s o c k e t . AF_INET , s o c k e t .SOCK_STREAM) 59 # s e l f . s e r v e r _ s o c k e t . s e t t i m e o u t ( 5 . 0 ) 60 s e l f . host_name = s o c k e t . gethost name ( ) 61 s e l f . h o s t _ i p = s o c k e t . getho stby name ( s e l f . host_name ) 62 # s e l f . h o s t _ i p = " 1 9 2 . 1 6 8 . 1 . 1 0 4 " 63 print( ’HOST IP : ’ , s e l f . h o s t _ i p ) 64 s e l f . p o r t = 9999 65 s e l f . s o c k e t _ a d d r e s s = ( s e l f . h o st _ip , s e l f . p o r t ) 66 s e l f . s t a t e = STATE . INIT_CONNECTION 67 68 " " "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− 69 Name : run 70 Func t i o n : motor o f t h e c l a s s 71 Paramete rs : − 72 Retu rn : − 73 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−" " " 74 def run ( s e l f ) : 75 s e l f . k i l l e r _ m u t e x . a c q u i r e ( ) 76 while not s e l f . k i l l e r . k i l l _ n o w : 77 s e l f . k i l l e r _ m u t e x . r e l e a s e ( ) 78 try : 79 i f s e l f . s t a t e == STATE . INIT_CONNECTION : 80 # S o c k e t Bind 81 s e l f . s e r v e r _ s o c k e t . bind ( s e l f . s o c k e t _ a d d r e s s ) 82 # S o ck e t L i s t e n 83 s e l f . s e r v e r _ s o c k e t . l i s t e n ( 5 ) 84 s e l f . c l i e n t _ s o c k e t , s e l f . add r = s e l f . s e r v e r _ s o c k e t . a c c e p t ( ) 85 # s e l f . c l i e n t _ s o c k e t . s e t t i m e o u t ( 5 . 0 ) 86 s e l f . l o g g i n g . i n f o ( " Camera : Accepte d " ) 87 s e l f . s t a t e = STATE .SEND_IMAGE 88 This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
126 s e l f . l o g g i n g . e r r o r ( "NAO : Can ’ t c o n ne ct " ) 127 #Show a message 128 print( " Can ’ t c o n n e c t t o NAO a t IP " + s e l f . i p + " on p o r t " + s t r ( s e l f . p o r t ) + " . \ n " ) 129 #And i n c r e a s e s i n 1 t h e c o u n t e r o f t h e e r r o r s 130 s e l f . t i m e s _ r e t r i e d _ r e c o n n e c t += 1 131 132 # S t a t e t o i n i t t h e pr o x y s r e q u i r e d f o r t h e i n t e r a c t i o n 133 e l i f s e l f . s t a t e == STATE . INIT_PROXYS : 134 try : 135 # Connect t o Autonomous L i f e 136 s e l f . autono mousLif e = Nao_AutonomousLife ( s e l f . session) 137 s e l f . autono mousLif e . s e t _ a u t o n o m o u s _ l i f e ( AUTONOMOUSLIFE_STATES . DISABLED) 138 # Connect t o LEDs 139 s e l f . naoLeds = Nao_Leds ( s e l f . s e s s i o n ) 140 # Conn ect t o S e n s o r s 141 s e l f . n a o S e n s o r s = Nao_Sensors ( s e l f . s e s s i o n , [ SENSORS_LIST .TOUCH] ) 142 # Connect t o V i s i o n 143 s e l f . naoVisio n = Nao_Vision ( s e l f . s e s s i o n ) 144 s e l f . naoVisio n . s e t P e o p l e R e c o g n i t i o n ( F al s e ) 145 # Connect t o Motion 146 s e l f . naoMotion = Nao_Motion ( s e l f . s e s s i o n ) 147 # Connect t o Audio P l a y er 148 s e l f . naoA u dioPla y er = Nao_AudioPlayer ( s e l f . s e s s i o n , " . / musi c2send . j s o n " ) 149 # Connect t o Speech 150 s e l f . naoSpeech = Nao_Speech ( s e l f . s e s s i o n ) 151 152 s e l f . l og g i n g . i n f o ( "NAO : Proxys i n i t i a l i z e d " ) 153 154 # F i n a l l y , we go t o t h e CROUCH s t a t e 155 i f s e l f . f i r s t T i m e : 156 s e l f . s t a t e = STATE . CLOSE_EYES 157 s e l f . f i r s t T i m e = F al se 158 else : 159 s e l f . s t a t e = s e l f . o l d _ s t a t e 160 161 # I f any e r r o r happens 162 exce pt Runt i meErro r : 163 print( " E r r o r while c o n n e c t i n g t o p ro xy s \ n " ) 164 #Go to t h e f i r s t s t a t e 165 s e l f . s t a t e = STATE . INIT_CONNECTION 166 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 167 168 # S t a t e t o p u t t h e r o bo t i n a crouch p o s i t i o n 169 e l i f s e l f . s t a t e == STATE .CROUCH: This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
170 try : 171 s e l f . o l d _ s t a t e = STATE .CROUCH 172 173 s e l f . naoMotion . s e t S t i f f n e s s ( 0 . 2 ) 174 175 s e l f . l o g g i n g . i n f o ( "NAO : Crouch p o s i t i o n " ) 176 177 #We change t h e s t a t e t o GET_IMAGE 178 s e l f . s t a t e = STATE .GET_IMAGE 179 180 181 # I f an e r r o r happens 182 exce pt Runt i meErro r : 183 #Go to t h e f i r s t s t a t e 184 s e l f . s t a t e = STATE . INIT_CONNECTION 185 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 186 187 # S t a t e t o g et t h e image from NAO and i n d i c a t e i t i t s socket 188 e l i f s e l f . s t a t e == STATE .GET_IMAGE: 189 try : 190 s e l f . o l d _ s t a t e = STATE . GET_IMAGE 191 s e l f . image_mutex . a c q u i r e ( ) 192 # Get t h e image 193 s e l f . image = s e l f . naoVisio n . get_opencv _image ( ) 194 s e l f . image_mutex . r e l e a s e ( ) 195 196 #Change t he s t a t e and go t o CHECK_ACTION 197 s e l f . s t a t e = STATE .CHECK_ACTION 198 199 # I f an e r r o r happens 200 exce pt Runt i meErro r : 201 #Go to t h e f i r s t s t a t e 202 s e l f . s t a t e = STATE . INIT_CONNECTION 203 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 204 205 # S t a t e t o check i f t h e r e i s a message from t h e a c t i v i t y 206 e l i f s e l f . s t a t e == STATE .CHECK_ACTION: 207 try : 208 s e l f . o l d _ s t a t e = STATE .CHECK_ACTION 209 s e l f . message_mutex . a c q u i r e ( ) 210 i f s e l f . message == " " : 211 s e l f . message_mutex . r e l e a s e ( ) 212 s e l f . s t a t e = STATE .GET_IMAGE 213 e l i f s e l f . message == "OK\ 0 " . encode ( ’ hex ’ ) : 214 s e l f . message_mutex . r e l e a s e ( ) 215 s e l f . s t a t e = STATE .GET_IMAGE 216 else : 217 print("received") This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
218 print( s e l f . message . s t r i p ( ) . decode ( " hex " ) ) 219 220 i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’A’ : 221 s e l f . s t a t e = STATE . DO_ANTICIPATORY_KEY 222 s e l f . cam_message_mutex . a c q u i r e ( ) 223 s e l f . cam_message = s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) 224 s e l f . cam_message_mutex . r e l e a s e ( ) 225 226 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’T ’ : 227 s e l f . m e s sage_2 _ t a l k = s e l f . message [ 2 : ] . s t r i p ( ) . decode ( " hex " ) 228 s e l f . s t a t e = STATE .TALK 229 230 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’H’ : 231 s e l f . s t a t e = STATE .CHECK_TOUCH_HAND 232 233 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’D’ : 234 s e l f . m e s sage_2 _ t a l k = s e l f . message [ 2 : ] . s t r i p ( ) . decode ( " hex " ) 235 s e l f . song_dance = s e l f . m essage _ 2 _ t alk . s p l i t ( ’+ ’ ) 236 s e l f . s t a t e = STATE .DANCE_SAMBA 237 238 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’F ’ : 239 s e l f . s t a t e = STATE . DELETE_AUDIOS 240 241 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’E ’ : 242 s e l f . s t a t e = STATE . OPEN_EYES 243 244 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’S ’ : 245 s e l f . s t a t e = STATE .STAND_UP 246 247 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’B ’ : 248 s e l f . s t a t e = STATE .WAVE 249 250 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’ I ’ : 251 s e l f . m e s sage_2 _ t a l k = s e l f . message [ 2 : ] . s t r i p ( ) . decode ( " hex " ) 252 s e l f . s t a t e = STATE . VOICE_IMITATION This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
253 254 s e l f . message = " " 255 s e l f . message_mutex . r e l e a s e ( ) 256 257 # I f an e r r o r happens 258 exce pt Runt i meErro r : 259 #Go to t h e f i r s t s t a t e 260 s e l f . s t a t e = STATE . INIT_CONNECTION 261 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 262 263 # S t a t e t o perform t h e a n t i c i p a t o r y key 264 e l i f s e l f . s t a t e == STATE . DO_ANTICIPATORY_KEY : 265 try : 266 s e l f . o l d _ s t a t e = STATE . DO_ANTICIPATORY_KEY 267 s e l f . l o gg i ng . i n f o ( "NAO : A n t i c i p a t o r y key " ) 268 # I n i t t h e movement 269 s e l f . naoMotion . performDefinedMovement ( DEFINED_MOVEMENTS_CHOREGRAPH. INITIAL_MOVE_INTERACTION) 270 # Turn o f t h e l e d s o f t h e e y e s 271 s e l f . naoLeds . f a d e (NAMES_LEDS_GROUPS . EYES_FULL , 0 . 0 , 0 . 5 , F a l s e ) 272 # Turn on t h e l e d s o f t h e e y e s 273 s e l f . naoLeds . f a d e (NAMES_LEDS_GROUPS . EYES_FULL , 1 . 0 , 0 . 5 , F a l s e ) 274 # Turn o f f t h e l e d s o f t h e e y e s 275 s e l f . naoLeds . f a d e (NAMES_LEDS_GROUPS . EYES_FULL , 0 . 0 , 0 . 5 , F a l s e ) 276 # Turn on t h e l e d s o f t h e e y e s 277 s e l f . naoLeds . f a d e (NAMES_LEDS_GROUPS . EYES_FULL , 1 . 0 , 0 . 5 , F a l s e ) 278 s e l f . message_mutex . a c q u i r e ( ) 279 s e l f . message = "CONTINUE\ 0 " . encode ( ’ hex ’ ) 280 s e l f . message_mutex . r e l e a s e ( ) 281 # Put t h e head w i t h a d e t e r m i n e d a n gl e 282 s e l f . naoMotion . moveJoi ntsToAngles ( [ JOINTS . HEAD_PITCH] , [ 0 . 2 1 ] , 0 . 1 ) # head l o o k i n g down a t an a n gl e 1 2 .2 deg 283 s e l f . s t a t e = STATE .WAIT_CAM_RESPONSE_OR_END_WAIT 284 # I f an e r r o r happens 285 exce pt Runt i meErro r : 286 #Go to t h e f i r s t s t a t e 287 s e l f . s t a t e = STATE . INIT_CONNECTION 288 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 289 290 e l i f s e l f . s t a t e == STATE .WAIT_CAM_RESPONSE_OR_END_WAIT: 291 # Send message t o a c t i v i t y t o i n d i c a t e i t can continue 292 s e l f . o l d _ s t a t e = STATE . This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
WAIT_CAM_RESPONSE_OR_END_WAIT 293 s e l f . message_mutex . a c q u i r e ( ) 294 i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’V ’ : 295 s e l f . cam_message_mutex . a c q u i r e ( ) 296 s e l f . cam_message = s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) 297 s e l f . cam_message_mutex . r e l e a s e ( ) 298 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 299 #And go back t o t h e g e t image s t a t e 300 s e l f . s t a t e = STATE .GET_IMAGE 301 e l i f s e l f . message [ 0 : 2 ] . s t r i p ( ) . decode ( " hex " ) == ’A’ : 302 s e l f . message = "SOMETHING\ 0 " . encode ( ’ hex ’ ) 303 s e l f . s t a t e = STATE . DO_ANTICIPATORY_KEY 304 s e l f . message_mutex . r e l e a s e ( ) 305 s e l f . cam_message_mutex . a c q u i r e ( ) 306 i f s e l f . cam_message == "OK\ 0 " : 307 s e l f . message_mutex . a c q u i r e ( ) 308 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 309 s e l f . message_mutex . r e l e a s e ( ) 310 #And go back t o t h e g e t image s t a t e 311 s e l f . s t a t e = STATE .GET_IMAGE 312 s e l f . cam_message_mutex . r e l e a s e ( ) 313 314 s e l f . image_mutex . a c q u i r e ( ) 315 # Get t h e image 316 s e l f . image = s e l f . naoVisio n . get_opencv _image ( ) 317 s e l f . image_mutex . r e l e a s e ( ) 318 319 320 321 322 # S t a t e t o t a l k 323 e l i f s e l f . s t a t e == STATE .TALK: 324 try : 325 s e l f . o l d _ s t a t e = STATE .TALK 326 s e l f . l o g g i n g . i n f o ( "NAO : Taked : " + s e l f . message_2_talk ) 327 s e l f . naoSpeech . anim_say ( s e l f . messa g e_2_t alk , True , CONFIGURATION .CONTEXTUAL) 328 # Send message t o a c t i v i t y t o i n d i c a t e i t can continue 329 tim e . s l e e p ( 2 ) 330 s e l f . message_mutex . a c q u i r e ( ) 331 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 332 s e l f . message_mutex . r e l e a s e ( ) 333 # Put t h e head w i t h a d e t e r m i n e d a n gl e 334 s e l f . naoMotion . moveJoi ntsToAngles ( [ JOINTS . This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
HEAD_PITCH] , [ 0 . 2 1 ] , 0 . 1 ) # head l o o k i n g down a t an a n gl e 1 2 .2 deg 335 #And go back t o t h e g e t image s t a t e 336 s e l f . s t a t e = STATE .GET_IMAGE 337 338 # I f an e r r o r happens 339 exce pt Runt i meErro r : 340 #Go to t h e f i r s t s t a t e 341 s e l f . s t a t e = STATE . INIT_CONNECTION 342 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 343 344 #TODO: Makes no s e n s e i f t h e autonomous l i f e i s d e s a c t i v a t e d ! ! 345 # S t a t e t o che ck i f t h e hand has been touched 346 e l i f s e l f . s t a t e == STATE .CHECK_TOUCH_HAND: 347 #TODO: 348 try : 349 s e l f . o l d _ s t a t e = STATE .CHECK_TOUCH_HAND 350 # Get t h e s e n s o r s t ou ch ed 351 s e n s o r s _ t o u c h e d = s e l f . n aoSensors . t ouch . check_touch_sensors_status (True) 352 print(sensors_touched ) 353 #TODO: m ir ar s i t o c a ma ! 354 s e n s o r s _ t o u c h e d = True 355 i f s e n s o r s _ t o u c h e d != F a l s e : 356 #TODO: che ck i f t h e hand has been t ouc h ed as sensors_touched is a list 357 # Check i f v a l u e s : 358 #LHand / Touch / L e f t 359 #LHand / Touch / Back 360 #LHand / Touch / R i g h t 361 #RHand / Touch / L e f t 362 #RHand / Touch / Back 363 #RHand / Touch / R i g h t 364 # are t h e r e t u r n e d 365 touched = True 366 i f t o u ched : 367 s e l f . l o g g i n g . i n f o ( "NAO : Hand t o uc h ed " ) 368 #And go back t o t h e g e t image s t a t e 369 s e l f . s t a t e = STATE .GET_IMAGE 370 time . s l e e p ( 1 0 ) 371 #TODO: send a message t o t h e a c t i v i t y 372 time . s l e e p ( 2 ) 373 s e l f . message_mutex . a c q u i r e ( ) 374 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 375 s e l f . message_mutex . r e l e a s e ( ) 376 377 # I f an e r r o r happens This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
378 exce pt Runt i meErro r : 379 #Go to t h e f i r s t s t a t e 380 s e l f . s t a t e = STATE . INIT_CONNECTION 381 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 382 383 # S t a t e t o dance t he samba 384 e l i f s e l f . s t a t e == STATE .DANCE_SAMBA: 385 #TODO: 386 try : 387 s e l f . o l d _ s t a t e = STATE .DANCE_SAMBA 388 s e l f . l o g g i n g . i n f o ( "NAO : Dance " ) 389 # I n i t song 390 s e l f . n ao Aud i oP lay e r . p l a y _ a u d i o ( s e l f . song_d ance [ 0 ] + " . wav " ) 391 392 # I n i t t h e movement 393 s e l f . naoMotion . performDefinedMovement ( s e l f . song_dance [ 1 ] ) 394 #TODO: w a i t t i m e 395 tim e . s l e e p ( 2 0 ) 396 s e l f . naoA udi oPla yer . s t o p _ a u d i o ( ) 397 398 # I n d i c a t e t o t he a c t i v i t y t h a t i t has f i n i s h e d 399 tim e . s l e e p ( 2 ) 400 s e l f . message_mutex . a c q u i r e ( ) 401 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 402 s e l f . message_mutex . r e l e a s e ( ) 403 404 #And go back t o t h e g e t image s t a t e 405 s e l f . s t a t e = STATE .GET_IMAGE 406 407 # I f an e r r o r happens 408 exce pt Runt i meErro r : 409 #Go to t h e f i r s t s t a t e 410 s e l f . s t a t e = STATE . INIT_CONNECTION 411 s e l f . l o g g i n g . e r r o r ( "NAO : D is co n n e ct e d " ) 412 413 # S t a t e t o d e l e t e t h e a u dios i n case i t i s g oing t o end 414 #the comunication 415 e l i f s e l f . s t a t e == STATE . DELETE_AUDIOS : 416 try : 417 s e l f . o l d _ s t a t e = STATE . DELETE_AUDIOS 418 s e l f . naoA u dioPla y er . d e l e t e _ a l l _ a u d i o s _ i n _ r o b o t ( ) 419 s e l f . s t a t e = STATE .END 420 exce pt Runt i meErro r : 421 print( " Could not e r a s e t h e a u dio s i n s i d e NAO\ n " ) 422 s e l f . s t a t e = STATE .END 423 424 # S t a t e t o end This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
425 e l i f s e l f . s t a t e == STATE .END: 426 s e l f . o l d _ s t a t e = STATE .END 427 pass 428 429 # S t a t e t o t u r n on t h e e y e s 430 e l i f s e l f . s t a t e == STATE . CLOSE_EYES : 431 s e l f . o l d _ s t a t e = STATE . CLOSE_EYES 432 s e l f . l o g g i n g . i n f o ( "NAO : Eyes c l o s e d " ) 433 s e l f . naoLeds . t u r n _ o f f _ g r o u p (NAMES_LEDS_GROUPS. EYES_FULL ) 434 s e l f . naoLeds . s e t _ i n t e n s i t y (NAMES_LEDS_GROUPS . EYES_FULL , 0 ) 435 436 s e l f . s t a t e = STATE .CROUCH 437 438 # S t a t e t o t u r n on t h e e y e s 439 e l i f s e l f . s t a t e == STATE . OPEN_EYES : 440 s e l f . o l d _ s t a t e = STATE . OPEN_EYES 441 s e l f . naoLeds . tu r n _ o n _ g r ou p (NAMES_LEDS_GROUPS. EYES_FULL ) 442 s e l f . naoLeds . s e t _ i n t e n s i t y (NAMES_LEDS_GROUPS . EYES_FULL , 1 ) 443 s e l f . l o g g i n g . i n f o ( "NAO : Eyes opened " ) 444 # Send message t o a c t i v i t y t o i n d i c a t e i t can continue 445 tim e . s l e e p ( 2 ) 446 s e l f . message_mutex . a c q u i r e ( ) 447 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 448 s e l f . message_mutex . r e l e a s e ( ) 449 450 s e l f . s t a t e = STATE .GET_IMAGE 451 452 # S t a t e t o s t a n d up t h e r o b o t 453 e l i f s e l f . s t a t e == STATE .STAND_UP : 454 s e l f . o l d _ s t a t e = STATE . STAND_UP 455 # S t an ds t h e r o b o t 456 s e l f . naoMotion . go ToPo stur e (ROBOT_POSTURES .STAND) 457 #And make i t a l i v e 458 s e l f . naoMotion . turnOnOf f B r e a t hAnimation ( True ) 459 s e l f . l o g g i n g . i n f o ( "NAO : S ta nd p o s i t i o n " ) 460 461 # Send message t o a c t i v i t y t o i n d i c a t e i t can continue 462 tim e . s l e e p ( 2 ) 463 s e l f . message_mutex . a c q u i r e ( ) 464 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 465 s e l f . message_mutex . r e l e a s e ( ) 466 467 # Put t h e head w i t h a d e t e r m i n e d a n gl e This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
468 s e l f . naoMotion . moveJoi ntsToAngles ( [ JOINTS . HEAD_PITCH ] , [ 0 . 2 1 ] , 0 . 1 ) # head l o o k i n g down a t an angle 12.2 deg 469 470 s e l f . s t a t e = STATE .GET_IMAGE 471 472 # S t a t e t o move t h e arm s a y i n g good_bye 473 e l i f s e l f . s t a t e == STATE .WAVE: 474 s e l f . o l d _ s t a t e = STATE .WAVE 475 s e l f . naoMotion . performDefinedMovement ( DEFINED_MOVEMENTS_CHOREGRAPH.WAVE) 476 s e l f . l o g g i n g . i n f o ( "NAO : Wave p er fo rm ed " ) 477 478 # Send message t o a c t i v i t y t o i n d i c a t e i t can continue 479 tim e . s l e e p ( 2 ) 480 s e l f . message_mutex . a c q u i r e ( ) 481 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 482 s e l f . message_mutex . r e l e a s e ( ) 483 484 #TODO: CANT GO HERE BECAUSE THE HAND STOPS SUDDENTLY ! 485 # Put t h e head w i t h a d e t e r m i n e d a n gl e 486 # s e l f . naoMotion . m o v e J o intsToAng l e s ( [ JOINTS . HEAD_PITCH] , [ 0 . 2 1 ] , 0 . 1 ) # head l o o k i n g down a t an a n g l e 12.2 deg 487 488 s e l f . s t a t e = STATE .GET_IMAGE 489 490 # S t a t e t o i m i t a t e a v o i c e 491 e l i f s e l f . s t a t e == STATE . VOICE_IMITATION : 492 s e l f . o l d _ s t a t e = STATE . VOICE_IMITATION 493 s e l f . n ao Aud i oP lay e r . p l a y _ a u d i o ( s e l f . m e ss ag e _ 2 _t al k +" . wav " ) 494 495 # Put t h e head w i t h a d e t e r m i n e d a n gl e 496 s e l f . naoMotion . moveJoi ntsToAngles ( [ JOINTS . HEAD_PITCH ] , [ 0 . 2 1 ] , 0 . 1 ) # head l o o k i n g down a t an angle 12.2 deg 497 498 tim e . s l e e p ( 2 0 ) 499 s e l f . naoA udi oPla yer . s t o p _ a u d i o ( ) 500 501 # I n d i c a t e t o t he a c t i v i t y t h a t i t has f i n i s h e d 502 tim e . s l e e p ( 2 ) 503 s e l f . message_mutex . a c q u i r e ( ) 504 s e l f . message = "OK\ 0 " . encode ( ’ hex ’ ) 505 s e l f . message_mutex . r e l e a s e ( ) 506 This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).
507 #And go back t o t h e g e t image s t a t e 508 s e l f . s t a t e = STATE .GET_IMAGE This research was supported by the Spanish National Program of Projects of Knowledge Generation 2022 with the reference PID2022-140284OB-I00, of the Program to Boost Scientific and Technical Research and its Transfer, from the Spanish National Plan for Scientific, Technical, and Innovation Research 2021-2023, titled “Uses of robotics to improve the instrumental skills of students with autism spectrum disorder through the development of new inclusive contexts. (DivInTech)”. (AEI/FEDER, UE).