-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_Hanazono.py
More file actions
executable file
·216 lines (182 loc) · 6.19 KB
/
demo_Hanazono.py
File metadata and controls
executable file
·216 lines (182 loc) · 6.19 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from pickle import TRUE
from ws_utilze import *
import time
from cylinder_movement import *
# from upbody_movements import *
from body_movement import *
import threading
import rospy
from geometry_msgs.msg import Twist
import numpy as np
import os
import asyncio
import websockets
import signal
import sys
from SimpleWebSocketServer import WebSocket, SimpleWebSocketServer, SimpleSSLWebSocketServer
#print('resetting the cylinder, will be finished in 5 sec ...')
#os.system('python3 Horizontal_reset.py')
# print('finished')
# commu_ip = '192.168.100.9'
commu_ip = '10.186.42.31'
commu_port = 11920
ws_commu = create_connection("ws://%s:%s/command"%(commu_ip,commu_port))
EMOTION = "talking"
SCALE = 0.5
SPEED = 0.2
status = "trun_around"
moving_time = 0
FO = 0
ENERGY = 0
F0_COM = 0
ENERGY_COM = 0
period = 0
MAX_TIME = 15
elapsed_time = 0
st = time.time()
status = "moving"
# status = "stop"
twist = None
UPPER_FLAG = True
global_status_dictionary = {
"status": "moving"
}
def callback(twist_):
global twist
twist = twist_
def signal_handler(signal, frame):
# close the socket here
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
rospy.init_node('emotional_walk')
# wsc-json-hanazono.pyでは capf_navigation ノードを作成します
pub = rospy.Publisher('rover_twist', Twist, queue_size=10)
rate = rospy.Rate(30)
sub = rospy.Subscriber("rover_twist", Twist, callback)
global_status_defintion_outside(global_status_dictionary)
class SimpleEcho(WebSocket):
def handleMessage(self):
global EMOTION, status, SCALE,elapsed_time,st, moving_time, UPPER_FLAG
# async for message in websocket:
data = json.loads(self.data)
print(data)
if data["command"] == "change_state":
status = data["status"]
global_status_dictionary["status"] = data["status"]
elapsed_time = 0
if status=="stop":
move_multi_joint_stop([5, 3, 4, 2, 7, 8, 1, 0, 6],
[0, 0, -90, -90, 0, 0, 0, 0, 0, 0],
[50,50,50,50,50,5,5,5,5], ws_commu)
st = time.time()
moving_time = 0
elif data["command"]== "change_emotion":
EMOTION = data["emotion"]
moving_time = 0
elif data["command"] == "change_scale":
SCALE = data["scale"]
elif data["command"] == "upper_flag":
UPPER_FLAG = 1==data["upper_flag"]
def handleConnected(self):
print(self.address, "connected")
def handleClose(self):
print(self.address, "close")
def ws():
server = SimpleWebSocketServer("0.0.0.0", 11925, SimpleEcho)
server.serveforever()
def rover_thread():
global period, elapsed_time, twist, status, EMOTION, SCALE, SPEED, moving_time, status
twist = Twist()
while not rospy.is_shutdown():
cylinder_v, period = cylinderg_parameters(emotion = EMOTION, x = elapsed_time, speed = SPEED, scale=SCALE)
# cylinder_v, period = cylinderg_parameters(emotion = 'neutral', x = elapsed_time, speed = SPEED, scale=SCALE)
twist.linear.z = cylinder_v
# twist.linear.x = 0.
if status == "stop":
for _ in range(10):
twist.linear.z = -0.2
# twist.linear.x = 0.
pub.publish(twist)
rate.sleep()
twist.linear.z = 0
twist.angular.z = 0
if status == 'turn_around':
# twist.linear.x = 0.
if moving_time<150:
twist.angular.z = 0.6
moving_time += 1
# elif moving_time>=150 and moving_time<350:
# twist.angular.z = -0.6
# moving_time += 1
# elif moving_time<430:
# twist.angular.z = 0.6
# moving_time += 1
elif moving_time>=150 and moving_time<280:
twist.angular.z = -0.6
moving_time += 1
else:
twist.angular.z = 0
# if EMOTION=='talking':
# if moving_time<50:
# twist.linear.x = 0.1
# moving_time += 1
# else:
# twist.linear.x = 0
# if EMOTION=='no_talking':
# if moving_time<50:
# twist.linear.x = -0.1
# moving_time += 1
# else:
# twist.linear.x = 0.
pub.publish(twist)
rate.sleep()
def robot_thread():
global period, elapsed_time, EMOTION, status, SCALE, UPPER_FLAG, ws_commu
# stop_conduct = False
# commu_ip = '192.168.1.167'
# commu_port = 11920
# ws_commu = create_connection("ws://%s:%s/command"%(commu_ip,commu_port))
while True:
if status=="stop":
# if not stop_conduct:
# move_multi_joint([5, 3, 4, 2, 7, 8, 1, 0, 6],
# [0, 0, -90, -90, 0, 0, 0, 0, 0, 0],
# [50,50,50,50,50,5,5,5,5], ws_commu)
# stop_conduct = True
continue
if UPPER_FLAG:
print('**robot doing// period %f, time %f'%(period, elapsed_time))
body_movements(f0 = FO,
energy = ENERGY,
period = period,
emotion = EMOTION,
f0_com = F0_COM,
eneragy_com = ENERGY_COM,
ws_commu = ws_commu,
scale = SCALE)
# stop_conduct = False
time.sleep(0.1)
def time_thread():
global elapsed_time,st
while True:
#while elapsed_time<=MAX_TIME:
et = time.time()
elapsed_time = np.round((et - st),1)
T0 = threading.Thread(target=time_thread)
T1 = threading.Thread(target=rover_thread)
T2 = threading.Thread(target=robot_thread)
T_ws = threading.Thread(target=ws)
T0.start()
T1.start()
T2.start()
T_ws.start()
T0.join()
T1.join()
T2.join()
T_ws.join()
# commu_ip = '192.168.1.167'
# commu_port = 11920
# ws_commu = create_connection("ws://%s:%s/command"%(commu_ip,commu_port))
move_multi_joint_stop([5, 3, 4, 2, 7, 8, 1, 0, 6],
[0, 0, -90, -90, 0, 0, 0, 0, 0, 0],
[30,30,20,20,20,5,5,5,5], ws_commu)