1
+ #!/usr/bin/env python
2
+
3
+ # Author: Hisashi Ishida, Anton Deguet
4
+ # Created on: 2023-04-01
5
+ #
6
+ # Copyright (c) 2015-2023 Johns Hopkins University, University of Washington, Worcester Polytechnic Institute
7
+ # Released under MIT License
8
+
9
+ # Start a single arm using
10
+ # > rosrun dvrk_robot dvrk_console_json -j <console-file>
11
+
12
+ # To communicate with the arm using ROS topics, see the python based example dvrk_arm_test.py:
13
+ # > rosrun crtk_python_client crtk_arm_test.py <arm-name>
14
+
15
+ import crtk
16
+ import math
17
+ import sys
18
+ import rospy
19
+ import numpy as np
20
+ import PyKDL
21
+
22
+
23
+ # example of application using device.py
24
+ class crtk_servo_cv_example :
25
+
26
+ # configuration
27
+ def configure (self , device_namespace ):
28
+ # ROS initialization
29
+ if not rospy .get_node_uri ():
30
+ rospy .init_node ('crtk_servo_cv_example' , anonymous = True , log_level = rospy .WARN )
31
+
32
+ print (rospy .get_caller_id () + ' -> configuring crtk_device_test for: ' + device_namespace )
33
+ # populate this class with all the ROS topics we need
34
+ self .crtk_utils = crtk .utils (self , device_namespace )
35
+ self .crtk_utils .add_operating_state ()
36
+ self .crtk_utils .add_setpoint_cp ()
37
+ self .crtk_utils .add_servo_cv ()
38
+ # for all examples
39
+ self .duration = 10 # 10 seconds
40
+ self .rate = 200 # aiming for 200 Hz
41
+ self .samples = self .duration * self .rate
42
+
43
+ def run_servo_cv (self ):
44
+ if not self .enable (60 ):
45
+ print ("Unable to enable the device, make sure it is connected." )
46
+ return
47
+
48
+ # create a new goal swith constant speed
49
+ for i in range (self .samples ):
50
+ vel = np .array ([0.05 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ]) # move 5 cm/sec along x direction
51
+ self .servo_cv (vel )
52
+ rospy .sleep (1.0 / self .rate )
53
+
54
+ # send the zero velcity to stop the robot
55
+ vel = np .array ([0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ])
56
+ self .servo_cv (vel )
57
+
58
+ # use the class now, i.e. main program
59
+ if __name__ == '__main__' :
60
+ try :
61
+ if (len (sys .argv ) != 2 ):
62
+ print (sys .argv [0 ], ' requires one argument, i.e. crtk device namespace' )
63
+ else :
64
+ example = crtk_servo_cv_example ()
65
+ example .configure (sys .argv [1 ])
66
+ example .run_servo_cv ()
67
+
68
+ except rospy .ROSInterruptException :
69
+ pass
0 commit comments