-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions_motions.py
executable file
·125 lines (85 loc) · 3.94 KB
/
actions_motions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from hermes_python.ontology import *
import actions_leds
import serial
import time
# open serial port
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600, timeout=1)
class Motions(object):
"""Class used to define which command(s) to send to robot
"""
# --> Sub callback function, one per intent
def move_forward(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# send command to bot
ser.write(b'\xFF\x55\x01\xFE\x00\xFF')
# terminates action at one step
ser.write(b'\xFF\x55\x00\xFF\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "Going forward", "")
def move_back(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# send command to bot
ser.write(b'\xFF\x55\x02\xFD\x00\xFF')
ser.write(b'\xFF\x55\x00\xFF\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "Backing up", "")
def turn_right(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# send command to bot
ser.write(b'\xFF\x55\x08\xF7\x00\xFF')
ser.write(b'\xFF\x55\x00\xFF\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "Turning right", "")
def turn_left(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# send command to bot
ser.write(b'\xFF\x55\x04\xFB\x00\xFF')
ser.write(b'\xFF\x55\x00\xFF\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "Turning left", "")
def do_handstand(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# send command to bot
ser.write(b'\xFF\x55\x18\xE7\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "I can do a handstand", "")
def do_pushup(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# send command to bot
ser.write(b'\xFF\x55\x14\xEB\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "I will do three pushups", "")
def pound_chest(hermes, intent_message):
# terminate the session first if not continue
hermes.publish_end_session(intent_message.session_id, "")
# action code goes here...
print('[Received] intent: {}'.format(intent_message.intent.intent_name))
# Smile
actions_leds.smile()
# send command to bot
ser.write(b'\xFF\x55\x21\xDE\x00\xFF')
# if need to speak the execution result by tts
hermes.publish_start_session_notification(intent_message.site_id, "I am a proud robot", "")
time.sleep(2)
# Return to neutral face
actions_leds.straight_face()