-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav.py
executable file
·742 lines (587 loc) · 31 KB
/
nav.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#!/usr/bin/env python3
# This file executes the beer bot code for the Kinova arm using the python API - the IP address needs to be specified correctly in the utilities.py file
import sys
import os
import time
import rospy
import geometry_msgs.msg
from geometry_msgs.msg import Pose
from std_msgs.msg import Bool, UInt8
from math import pi, cos, sin
# Import the utilities helper module
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import utilities
from kortex_api.autogen.client_stubs.BaseClientRpc import BaseClient
from kortex_api.autogen.messages import Base_pb2, Common_pb2, ControlConfig_pb2
class KinovaNav(object):
"""KinovaNav"""
def __init__(self):
# Parse arguments
self.args = utilities.parseConnectionArguments()
self.total_time = 0
rospy.init_node("kinova_nav")
self.pour_drink_sub = rospy.Subscriber("/pour_drink", UInt8, self.callback_pour, queue_size=1)
self.beer_position_sub = rospy.Subscriber("/beer_position", Pose, self.callback_beer_position, queue_size=1)
self.drink_poured_pub = rospy.Publisher('/drink_poured', Bool, queue_size=1)
self.arm_in_position_pub = rospy.Publisher("/arm_in_position", UInt8, queue_size=1)
print("initialised correctly")
def example_move_to_home_position(self):
# Make sure the arm is in Single Level Servoing mode
base_servo_mode = Base_pb2.ServoingModeInformation()
base_servo_mode.servoing_mode = Base_pb2.SINGLE_LEVEL_SERVOING
self.base.SetServoingMode(base_servo_mode)
# Move arm to ready position
print("Moving the arm to a safe position")
action_type = Base_pb2.RequestedActionType()
action_type.action_type = Base_pb2.REACH_JOINT_ANGLES
action_list = self.base.ReadAllActions(action_type)
action_handle = None
for action in action_list.action_list:
if action.name == "Home":
action_handle = action.handle
if action_handle == None:
print("Can't reach safe position. Exiting")
sys.exit(0)
self.base.ExecuteActionFromReference(action_handle)
time.sleep(5) # Leave time to action to complete
def move_to_joints(self, a_0,a_1,a_2,a_3,a_4,a_5,a_6, timeout=10):
print("Starting angular action movement ...")
action = Base_pb2.Action()
action.name = "Example angular action movement"
action.application_data = ""
actuator_count = self.base.GetActuatorCount()
joint_angles = {0:a_0,1:a_1,2:a_2,3:a_3,4:a_4,5:a_5,6:a_6}
# Place arm straight up
for joint_id in range(actuator_count.count):
joint_angle = action.reach_joint_angles.joint_angles.joint_angles.add()
joint_angle.joint_identifier = joint_id
# print(joint_angle.value)
joint_angle.value = joint_angles[joint_id]
# print(joint_angle.value)
print("Executing action")
self.base.ExecuteAction(action)
print("Waiting 10 seconds for movement to finish ...")
time.sleep(timeout)
# print(self.base.GetMeasuredJointAngles())
print("Angular movement completed")
def nequiv_coord(self, x, y):
if (x > y):
if (x-y <= 0.01):
return False
else :
if (y-x <= 0.01):
return False
return True
def nequiv_angle(self, x, y):
if (x > y):
if (x-y <= 0.75):
return False
else :
if (y-x <= 0.75):
return False
return True
def reach_position(self, x, y, z, angle_x=0, angle_y=0, angle_z=0, timeout=20, log=False):
print("Starting movement to pick up bottle")
action = Base_pb2.Action()
action.name = "Picking up Bottle"
action.application_data = ""
cartesian_pose = action.reach_pose.target_pose
cartesian_pose.x = x
cartesian_pose.y = y
cartesian_pose.z = z
cartesian_pose.theta_x = angle_x
cartesian_pose.theta_y = angle_y
cartesian_pose.theta_z = angle_z
print(cartesian_pose)
print("Executing action")
self.base.ExecuteAction(action)
p = self.base.GetMeasuredCartesianPose()
start=time.time()
while(time.time() - start < 17 and (self.nequiv_coord(p.x, x) or self.nequiv_coord(p.y, y) or self.nequiv_coord(p.z, z) or self.nequiv_angle(p.theta_x, angle_x) or self.nequiv_angle(p.theta_y, angle_y) or self.nequiv_angle(p.theta_z, angle_z))):
# time.sleep(5)
# if(log):
# print(self.nequiv_coord(p.x, x))
# print(self.nequiv_coord(p.y, y))
# print(self.nequiv_coord(p.z, z))
# print(self.nequiv_angle(p.theta_x, angle_x))
# print(self.nequiv_angle(p.theta_y, angle_y))
# print(self.nequiv_angle(p.theta_z, angle_z))
# print("current position")
# print(p)
# print("desired position")
# print(cartesian_pose)
# print(time.time()-start)
p = self.base.GetMeasuredCartesianPose()
if(time.time()-start > 17):
print("movement timed out")
time.sleep(0.5)
print("Cartesian movement completed")
def reach_position2(self, x, y, z, angle_x=0, angle_y=0, angle_z=0, timeout=20):
print("Starting movement to pick up bottle")
action = Base_pb2.Action()
action.name = "Picking up Bottle"
action.application_data = ""
cartesian_pose = action.reach_pose.target_pose
cartesian_pose.x = x
cartesian_pose.y = y
cartesian_pose.z = z
cartesian_pose.theta_x = angle_x
cartesian_pose.theta_y = angle_y
cartesian_pose.theta_z = angle_z
print(cartesian_pose)
print("Executing action")
self.base.ExecuteAction(action)
time.sleep(timeout)
print("Cartesian movement completed")
# you should use this function instead of reach_position most of the time
def go_position(self, x, y, z, yaw, upside_down = False, timeout=20):
if(upside_down):
self.reach_position(x, y, z, -90, 0, yaw-180, timeout)
else:
self.reach_position(x, y, z, 90, 0, yaw, timeout)
def go_upside_down(self):
print("Starting angular action movement ...")
action = Base_pb2.Action()
action.name = "Example angular action movement"
action.application_data = ""
actuator_count = self.base.GetActuatorCount()
# print(self.base.GetMeasuredJointAngles())
# Place arm straight up
for joint_id in range(actuator_count.count):
print(joint_id)
joint_angle = action.reach_joint_angles.joint_angles.joint_angles.add()
joint_angle.joint_identifier = joint_id
joint_angle.value = 0
print("Executing action")
self.base.ExecuteAction(action)
print("Waiting 10 seconds for movement to finish ...")
time.sleep(10)
print("Angular movement completed")
def go_to_bottle(base):
constrained_pose = Base_pb2.ConstrainedPose()
cartesian_pose = constrained_pose.target_pose
cartesian_pose.x = 0.76 # (meters)
cartesian_pose.y = 0.12 # (meters)
cartesian_pose.z = 0.08 # (meters)
cartesian_pose.theta_x = 90 # (degrees)
cartesian_pose.theta_y = 0 # (degrees)
cartesian_pose.theta_z = 90 # (degrees)
print("Reaching cartesian pose...")
base.PlayCartesianTrajectory(constrained_pose)
print("Waiting 10 seconds for movement to finish ...")
time.sleep(10)
def reach_gripper_position(self, x):
# Create the GripperCommand we will send
gripper_command = Base_pb2.GripperCommand()
finger = gripper_command.gripper.finger.add()
# Close the gripper with position increments
print("Performing gripper test in position...")
gripper_command.mode = Base_pb2.GRIPPER_POSITION
finger.finger_identifier = 1
finger.value = x
self.base.SendGripperCommand(gripper_command)
time.sleep(3)
def section_position(self):
x = 0.514
z = 0.193
camera_offset = 0.04
if (self.table_num == 1):
y = -0.21
elif (self.table_num == 2):
y = -0.07
elif (self.table_num == 3):
y = 0.07
else:
y = 0.21
v1 = Pose()
v1.position.x = x
v1.position.y = y - camera_offset
v1.position.z = z
return v1
def move_to_section(self):
# go to the correct section
section_pose = self.section_position()
print(section_pose)
print(self.base.GetMeasuredCartesianPose())
self.go_position(section_pose.position.x, section_pose.position.y, section_pose.position.z, 90, timeout=10)
def convert_camera(self, msg):
current_position = self.section_position()
v1 = Pose()
v1.position.x = msg.position.z
v1.position.y = -msg.position.x
v1.position.z = msg.position.y
v2 = Pose()
v2.position.x = -0.19
v2.position.y = 0.04
v2.position.z = -0.07
pose_msg = Pose()
pose_msg.position.x = v1.position.x + v2.position.x + current_position.position.x
pose_msg.position.y = v1.position.y + v2.position.y + current_position.position.y
pose_msg.position.z = v1.position.z + v2.position.z + current_position.position.z
print("translated_bottle x: {}".format(pose_msg.position.x))
print("translated_bottle y: {}".format(pose_msg.position.y))
print("translated_bottle z: {}".format(pose_msg.position.z))
return pose_msg
def get_bottle_height(self):
if (self.table_num == '1'): # hop house
height = 0.2
elif (self.table_num == '2'): # san miguel
height = 0.225
elif (self.table_num == '3'): # birra moretti
height = 0.22
else: # becks
height = 0.215
return height
def open_bottle(self):
# height = self.get_bottle_height()
reference = 0.215
dif = 0.025
self.move_to_joints(331.74,108.09,201.49,306.35,143.18,115.53,96.57,timeout=8)
# self.reach_position(0.2, 0.156, -0.132, -90, -179.99, 90)
# print("open bottle:")
# print(self.base.GetMeasuredCartesianPose())
# reach open position
# self.reach_position(0.162, 0.164, -0.09+reference-height, -90, -180, 93, timeout=10)
self.reach_position(0.162, 0.164, -0.09-0.025, -90, -180, 93, timeout=10)
print("4")
# print(self.base.GetMeasuredJointAngles())
# self.reach_position(0.162, 0.164+0.010, -0.09+0.005+reference-height, -90, -180, 93, timeout=5)
self.reach_position(0.165, 0.164+0.007, -0.09-0.025, -90, -180, 93, timeout=5)
print("5")
# print(self.base.GetMeasuredJointAngles())
# self.reach_position(0.162, 0.164+0.010, -0.09+0.003+reference-height, -90, -178, 93, timeout=5)
self.reach_position(0.165, 0.164+0.007, -0.09-0.03, -90, -160, 93, timeout=1)
print("6")
# print(self.base.GetMeasuredJointAngles())
self.reach_gripper_position(1)
# self.reach_position(0.162, 0.164+0.010, -0.09+0.003-0.05+reference-height, -90, -175, 93, timeout=5)
self.reach_position(0.165, 0.164, -0.09-0.025, -90, -170, 93, timeout=5)
self.reach_position(0.165, 0.164+0.007, -0.09-0.025, -90, -170, 93, timeout=5)
# self.reach_position(0.165, 0.164+0.008, -0.09-0.055, -90, -170, 93, timeout=5)
# print(self.base.GetMeasuredJointAngles())
self.move_to_joints(325.84, 109.29, 202.15, 303.52, 140.48, 112.98, 88.20, timeout=4)
# --------------------------------------------------------------------------------------
# self.reach_position(0.162, 0.164, -0.09-0.027, -90, -180, 93, timeout=10)
# print("4")
# # print(self.base.GetMeasuredJointAngles())
# # self.reach_position(0.162, 0.164+0.010, -0.09+0.005+reference-height, -90, -180, 93, timeout=5)
# self.reach_position(0.165, 0.164+0.007, -0.09-0.027, -90, -180, 93, timeout=5)
# print("5")
# # print(self.base.GetMeasuredJointAngles())
# # self.reach_position(0.162, 0.164+0.010, -0.09+0.003+reference-height, -90, -178, 93, timeout=5)
# self.reach_position(0.165, 0.164+0.007, -0.09-0.027, -90, -160, 93, timeout=1)
# print("6")
# # print(self.base.GetMeasuredJointAngles())
# self.reach_gripper_position(1)
# # self.reach_position(0.162, 0.164+0.010, -0.09+0.003-0.05+reference-height, -90, -175, 93, timeout=5)
# self.reach_position(0.165, 0.164, -0.09-0.027, -90, -170, 93, timeout=5)
# self.reach_position(0.165, 0.164+0.007, -0.09-0.027, -90, -170, 93, timeout=5)
# self.move_to_joints(325.84, 109.29, 202.15, 303.52, 140.48, 112.98, 88.20, timeout=4)
# self.move_to_joints(325.84, 109.29, 202.15, 303.52, 140.48, 112.98, 88.20)
# time.sleep(20)
print("7")
# print(self.base.GetMeasuredJointAngles())
self.reach_position(0.165+0.05, 0.164+0.008, -0.09-0.055, -90, -175, 93, timeout=5)
# 0.0493
print("8")
# print(self.base.GetMeasuredJointAngles())
def opening_demo(self):
# go towards the bottle
self.go_position(pose_msg.position.x - 0.1 + 0.02, pose_msg.position.y, 0.09, 90, timeout=10)
self.reach_gripper_position(0)
self.go_position(pose_msg.position.x + 0.02, pose_msg.position.y, 0.09, 90, timeout=10)
self.reach_gripper_position(1)
self.go_position(pose_msg.position.x + 0.02, pose_msg.position.y, 0.40, 90, timeout=5)
# self.move_to_section()
# pouring
self.example_move_to_home_position()
# self.reach_gripper_position(1)
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# self.reach_position(-0.583, -0.416, 0.15, -90,180,90, timeout=10)
self.move_to_joints(88.38,93.75,252.25,268.96,267.93,17.62,87.91)
self.reach_position(-0.578, -0.416, 0.068, -90,180,90, timeout=10)
self.reach_gripper_position(0)
self.reach_position(-0.578+0.1, -0.416, 0.068, -90,180,90, timeout=10)
self.example_move_to_home_position()
def callback_beer_position(self, msg):
print('recieved from goerge')
st = time.time()
pose_msg = self.convert_camera(msg)
# Create connection to the device and get the router
with utilities.DeviceConnection.createTcpConnection(self.args) as router:
self.base = BaseClient(router)
# go towards the bottle
self.go_position(pose_msg.position.x - 0.1 + 0.02, pose_msg.position.y, 0.09, 90, timeout=7)
# print("1")
# print(self.base.GetMeasuredJointAngles())
self.reach_gripper_position(0)
self.go_position(pose_msg.position.x + 0.02, pose_msg.position.y, 0.09, 90, timeout=7)
self.reach_gripper_position(1)
# print("2")
# print(self.base.GetMeasuredJointAngles())
self.go_position(pose_msg.position.x + 0.02, pose_msg.position.y, 0.40, 90, timeout=5)
# print("3")
# print(self.base.GetMeasuredJointAngles())
# self.move_to_section()
# pouring
# move home
# self.move_to_joints(360, 15, 180, 230, 360, 55, 90)
# self.example_move_to_home_position()
self.reach_position(0.577, 0.00136, 0.4336, 90, 0, 90)
print("going home:")
print(self.base.GetMeasuredCartesianPose())
print("selection : {}".format(self.selection))
if(self.selection != 4):
self.open_bottle()
# move home
self.move_to_joints(360, 15, 180, 230, 360, 55, 90, timeout=7)
# self.example_move_to_home_position()
# self.reach_position(0.577, 0.00136, 0.4336, 90, 0, 90)
# self.pour_bottle()
self.move_to_joints(96.92, 117.56, 280.03, 288.72, 332.69, 345.76, 358.18, timeout=5)
print("dropping bottle")
self.reach_gripper_position(0)
#time.sleep(3)
self.move_to_joints(74.59, 78.12, 274.34, 259.09, 349.91, 355.85, 22.69, timeout=5)
self.example_move_to_home_position()
self.drink_poured_pub.publish(True)
# self.reach_gripper_position(1)
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# self.reach_position(-0.583, -0.416, 0.15, -90,180,90, timeout=10)
# self.move_to_joints(88.38,93.75,252.25,268.96,267.93,17.62,87.91)
# self.reach_position(-0.578, -0.416, 0.068, -90,180,90, timeout=10)
# self.reach_gripper_position(0)
# self.reach_position(-0.578+0.1, -0.416, 0.068, -90,180,90, timeout=10)
# self.example_move_to_home_position()
# self.reach_position(-0.583, -0.416, 0.17, -90,180,90, timeout=10)
# self.reach_position(-0.583, -0.416, 0.17, -90,-107.5,90, timeout=20)
# self.reach_position(-0.583, -0.38, 0.17, -90,-95,90, timeout=10)
# self.reach_position(-0.583, -0.36, 0.17, -90,-90,90, timeout=10)
# self.reach_position(-0.583, -0.416, 0.17, -90,180,90, timeout=20)
# self.example_move_to_home_position()
# # go towards the opener
# self.reach_position(0.314, 0.148, -0.145, -90, -180, 0, timeout=20)
# self.reach_position(0.199, 0.156, -0.132, -90, -180, 90, timeout=20)
# # # san miguel open position
# self.open_bottle()
# # move to bottle opening
# self.example_move_to_home_position()
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# # self.reach_position(-0.575, -0.001, 0.434, -90,180,90, timeout=10)
# # self.reach_position(-0.575, -0.001, 0.07, -90,180,90, timeout=10)
# # self.reach_gripper_position(0)
# self.move_by_x_y_z(z=-0.1)
# self.open_bottle()
# print("--- %s seconds ---" % (time.time() - self.start_time))
# pose = self.scene.get_object_poses(['opener_tip'])['opener_tip']
# self.reach_position(pose.position.x,pose.position.y, pose.position.z-0.4, pi/2,0, -pi/2)
# self.reach_position(pose.position.x,pose.position.y, pose.position.z-0.1, pi/2,0, -pi/2)
# self.reach_position(0.55,0, 0.09,pi/2,0, pi/2)
# time.sleep(2)
# self.reach_position(0.55,0, 0.09,pi/2,0, pi/2)
self.total_time += time.time() - st
print("total time: {0}", self.total_time)
self.pour_drink_sub = rospy.Subscriber("/pour_drink", UInt8, self.callback_pour, queue_size=1)
# except:
# self.drink_poured_pub.publish(False)
def pour_bottle(self):
# with utilities.DeviceConnection.createTcpConnection(self.args) as router:
# Create required services
# self.base = BaseClient(router)
# height = self.get_bottle_height()
reference = 0.245
self.move_to_joints(88.38,93.75,252.25,268.96,267.93,17.62,87.91, timeout=5.5)
print("pouring:")
# print(self.base.GetMeasuredCartesianPose())
# print("pour1")
self.reach_position(-0.583, -0.416, 0.185, -90,180,90, timeout=10, log=True)
print("pour2")
self.reach_position(-0.583, -0.405, 0.185, -90,-115,90, timeout=10, log = True)
# start pouring
self.reach_position2(-0.583, -0.405, 0.185, -90,-93,90, timeout=6)
self.reach_position2(-0.583, -0.405, 0.185, -90,-101,90, timeout=3)
self.reach_position2(-0.583, -0.395, 0.185, -90,-101,90, timeout=3)
self.reach_position2(-0.583, -0.395, 0.185, -90,-90,90, timeout=2.2)
self.reach_position2(-0.583, -0.395, 0.185, -90,-98,90, timeout=3)
self.reach_position2(-0.583, -0.385, 0.185, -90,-98,90, timeout=7)
self.reach_position2(-0.583, -0.385, 0.185, -90,-87.5,90, timeout=2.2)
self.reach_position2(-0.583, -0.385, 0.185, -90,-95,90, timeout=3)
self.reach_position2(-0.583, -0.376, 0.185, -90,-95,90, timeout=3)
self.reach_position2(-0.583, -0.376, 0.185, -90,-85,90, timeout=2)
self.reach_position(-0.583, -0.416, 0.185, -90,180,90, timeout=10, log = True)
# self.reach_position(-0.583, -0.41, 0.185, -90,-110,90, timeout=3, log = True)
# self.reach_position(-0.583, -0.38, 0.185, -90,-110,90, timeout=3, log=True)
# self.reach_position(-0.583, -0.38, 0.185, -90,-95,90, timeout=3, log=True)
# self.reach_position(-0.583, -0.38, 0.185, -90,-100,90, timeout=3, log=True)
# self.reach_position(-0.583, -0.365, 0.185, -90,-93,90, timeout=3, log=True)
# self.reach_position(-0.583, -0.365, 0.185, -90,-96,90, timeout=3, log=True)
# print("pour3")
# self.reach_position(-0.583, -0.38, 0.19, -90,-95,90, timeout=5, log=True)
# time.sleep(0.5)
# print("pour4")
# self.reach_position(-0.583, -0.365, 0.18, -90,-93,90, timeout=5, log=True)
# print("pour5")
# time.sleep(0.75)
# self.reach_position(-0.583, -0.35, 0.18, -90,-89,90, timeout=5,log=True)
# print("pour7")
# time.sleep(0.75)
# # self.reach_position(-0.583, -0.335, 0.18, -90,-89,90, timeout=5,log=True)
# # print("pour8")
# # time.sleep(2)
# self.reach_position(-0.583, -0.335, 0.27, -90,-88,90, timeout=5,log=True)
# print("pour9")
# time.sleep(0.5)
# self.reach_position(-0.583, -0.3, 0.35, -90,-95,90, timeout=5,log=True)
# # self.reach_position(-0.583, -0.22, 0.40, -90, 180,90, timeout=5,log=True)
# # print(self.base.GetMeasuredJointAngles())
# self.move_to_joints(93.07, 62.45, 271.32, 239.69, 5.02, 33.13, 23.25, timeout=5)
# print("pour10")
# self.reach_position(-0.583, -0.416, 0.50, -90,180,90, timeout=20,log=True)
# self.move_to_joints(85.81, 61.43, 272.54, 275.02, 356.46, 351.28, 32.18)
def callback_pour(self, msg):
self.pour_drink_sub.unregister()
print("navigating to section " + str(msg.data))
self.selection=msg.data
st = time.time()
# Create connection to the device and get the router
with utilities.DeviceConnection.createTcpConnection(self.args) as router:
# Create required services
self.base = BaseClient(router)
self.table_num = msg.data
# go towards the opener
# move home
# print("joint speed limits:")
# print(self.base.GetAllJointsSpeedHardLimitation())
# print("joint torque limits:")
# print(self.base.GetAllJointsTorqueSoftLimitation())
# print("joint twist limits:")
# print(self.base.GetTwistSoftLimitation())
# print("joint wrench limits:")
# print(self.base.GetWrenchSoftLimitation())
# print("end of limits")
# print(self.base.GetMeasuredCartesianPose().x)
# print(self.base.GetMeasuredJointAngles().joint_angles.value[0])
# self.move_to_joints(360, 15, 180, 230, 360, 55, 90, timeout=7)
# print(self.base.GetMeasuredCartesianPose())
# print(self.base.GetMeasuredCartesianPose().x)
# self.example_move_to_home_position()
# print("let's see the angles after going home")
# print(self.base.GetMeasuredJointAngles())
# print("these are the angles")
# self.move_to_joints(331.74,108.09,201.49,306.35,143.18,115.53,96.57)
# print("let's see the angles of the angular move")
# print(self.base.GetMeasuredJointAngles())
# print("these are the angles")
# print("let's see the angles of the angular move")
# print(self.base.GetMeasuredJointAngles())
# print("these are the angles")
# self.open_bottle()
# self.reach_position(0.314, 0.148, -0.145, -90, -180, 0, timeout=20)
# self.move_to_joints(331.74,108.09,201.49,306.35,143.18,115.53,96.57)
# self.reach_position(0.199, 0.156, -0.132, -90, -180, 90, timeout=20)
# self.open_bottle()
# self.example_move_to_home_position()
# self.reach_gripper_position(0)
# self.go_position(0.752, 0.089, 0.09, 90, timeout=15)
# self.reach_gripper_position(1)
# self.example_move_to_home_position()
self.move_to_section()
# self.pour_bottle()
# if (self.table_num == '1'): # hop house
# height = 0.2
# elif (self.table_num == '2'): # san miguel
# height = 0.225
# elif (self.table_num == '3'): # birra moretti
# height = 0.22
# else: # becks
# height = 0.215
# reference = 0.215
# self.example_move_to_home_position()
# self.example_angular_action_movement()
# self.example_move_to_home_position()
# self.reach_gripper_position(0)
# self.go_position(0.752, 0.089, 0.09, 90, timeout=15)
# self.reach_gripper_position(1)
# self.example_move_to_home_position()
# # move to bottle opening
# self.example_move_to_home_position()
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# self.example_move_to_home_position()
# bottle opening
# self.example_move_to_home_position()
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# self.reach_position(0.314, 0.148, -0.145, -90, -180, 0, timeout=20)
# self.reach_position(0.199, 0.156, -0.132, -90, -180, 90, timeout=20)
# go towards the opener
# self.reach_position(0.314, 0.148, -0.145, -90, -180, 0, timeout=20)
# self.reach_position(0.199, 0.156, -0.132, -90, -180, 90, timeout=20)
# self.open_bottle()
# pouring
# self.example_move_to_home_position()
# self.reach_gripper_position(1)
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# self.reach_position(-0.583, -0.416, 0.15, -90,180,90, timeout=10)
# self.reach_position(0.752, 0.089, 0.184, 90,-75,90, timeout=10)
# self.reach_position(0.752, 0.089, 0.184, 90,-85,90, timeout=15)
# self.reach_position(0.752, 0.079, 0.184, 90,-85,90, timeout=10)
# self.reach_position(0.752, 0.079, 0.184, 90,-90,90, timeout=10)
# self.reach_position(0.752, 0.065, 0.184, 90,-90,90, timeout=10)
# self.reach_position(0.752, 0.065, 0.184, 90,-93,90, timeout=10)
# self.reach_position(0.752, 0.065, 0.184, 90,0,90, timeout=10)
# self.reach_position(0.314, 0.148, -0.145, -90, -180, 0, timeout=20)
# self.reach_position(0.199, 0.156, -0.132, -90, -180, 90, timeout=20)
# san miguel open position
# self.reach_position(0.153, 0.164, -0.105, -90, -180, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.008, -0.105+0.005, -90, -180, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.008, -0.105+0.005, -90, -173, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.008, -0.105+0.005-0.05, -90, -173, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.01, -0.105+0.002-0.05, -90, -173, 90, timeout=20)
# san miguel open position
# self.reach_position(0.153, 0.164, -0.105, -90, -180, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.013, -0.105+0.002, -90, -180, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.01, -0.105+0.002, -90, -173, 90, timeout=20)
# self.reach_position(0.153, 0.164+0.01, -0.105+0.002-0.05, -90, -173, 90, timeout=20)
# self.go_position(0.634, -0.20, 0.09, 90, timeout=4)
# # self.reach_gripper_position(1)
# self.go_position(0.634, -0.20, 0.3, 90, timeout=4)
# self.go_position(0.634, -0.20, 0.09, 90, timeout=4)
# # self.reach_gripper_position(1)
# self.go_position(0.634, -0.20, 0.3, 90, timeout=4)
# self.reach_position(-0.475, -0.12, 0.08, -90,-180,90, timeout=20)
# self.go_position(0.485, -0.294, 0.432, 69.3)
# self.go_position(0.099, -0.564, 0.432, 3.9)
# self.reach_position(-0.285, -0.421, 0.286, -90,-180,132.2)
# self.reach_position(-0.474, -0.139, 0.189, -90,-180,90)
# self.reach_position(-0.474, -0.139, 0.07, -90,-180,90)2)
# move to bottle opening
# self.reach_position(0.333, -0.471, 0.434, 90,0,35.1, timeout=10)
# self.reach_position(-0.044, -0.575, 0.434, -90,180,175.5, timeout=10)
# self.reach_position(-0.467, -0.338, 0.434, -90,180,125.7, timeout=10)
# self.reach_position(-0.575, -0.001, 0.434, -90,180,90, timeout=10)
# self.reach_position(-0.575, -0.001, 0.07, -90,180,90, timeout=10)
# self.reach_gripper_position(0)
# self.go_position(0, -0.52, 0.08, 0, timeout=20)
# self.example_move_to_home_position()
# self.go_upside_down()
# self.go_position(0.49, 0, 0.1, pi/2, upside_down=True)
self.total_time = time.time() - st
self.arm_in_position_pub.publish(msg)
print("published to george")
def main():
kinova = KinovaNav()
# kinova.pour_bottle()
rospy.spin()
if __name__ == "__main__":
main()