|
@@ -5,6 +5,7 @@
|
|
|
# Description: 通过键盘遥控小车行进、抓取。
|
|
|
# History:
|
|
|
# 20200317 增加小车抓取功能 by jally
|
|
|
+# 20200408 增加小车可通过“7”“8”数字键控制夹爪张开闭合角度
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
@@ -15,6 +16,8 @@ from geometry_msgs.msg import Twist
|
|
|
import sys, select, termios, tty
|
|
|
|
|
|
from ros_arduino_msgs.srv import GripperControl
|
|
|
+from ros_arduino_msgs.srv import GripperAngle
|
|
|
+import time
|
|
|
|
|
|
msg = """
|
|
|
Reading from the keyboard and Publishing to Twist!
|
|
@@ -38,6 +41,7 @@ anything else : stop
|
|
|
q/z : increase/decrease max speeds by 10%
|
|
|
w/x : increase/decrease only linear speed by 10%
|
|
|
e/c : increase/decrease only angular speed by 10%
|
|
|
+7/8 : increase/decrease angle by 5°
|
|
|
|
|
|
1 : open the gripper and down
|
|
|
2 : stop
|
|
@@ -78,12 +82,26 @@ speedBindings={
|
|
|
'c':(1,.9),
|
|
|
}
|
|
|
|
|
|
-gripperBindings={
|
|
|
+
|
|
|
+#gripperBindings={
|
|
|
+# '1':(),
|
|
|
+# '2':(),
|
|
|
+# '3':(),
|
|
|
+# '4':(),
|
|
|
+# '5':(),
|
|
|
+# }
|
|
|
+
|
|
|
+gripperupBindings={
|
|
|
'1':(),
|
|
|
+ }
|
|
|
+gripperdownBindings={
|
|
|
'2':(),
|
|
|
- '3':(),
|
|
|
- '4':(),
|
|
|
- '5':(),
|
|
|
+ }
|
|
|
+gripperopenBindings={
|
|
|
+ '4':(5),
|
|
|
+ }
|
|
|
+grippercloseBindings={
|
|
|
+ '5':(-5),
|
|
|
}
|
|
|
|
|
|
def getKey():
|
|
@@ -97,12 +115,20 @@ def getKey():
|
|
|
def vels(speed,turn):
|
|
|
return "currently:\tspeed %s\tturn %s " % (speed,turn)
|
|
|
|
|
|
+def angles(angle):
|
|
|
+ return "currently:\tangle %s " % (angle)
|
|
|
+
|
|
|
+
|
|
|
#调用service: mobilebase_arduino/gripper_control
|
|
|
def client_srv():
|
|
|
rospy.wait_for_service("mobilebase_arduino/gripper_control")
|
|
|
+ rospy.wait_for_service("mobilebase_arduino/gripper_angle")
|
|
|
try:
|
|
|
gripper_client = rospy.ServiceProxy("mobilebase_arduino/gripper_control",GripperControl)
|
|
|
- resp = gripper_client.call(int(key))
|
|
|
+ gripper2_client = rospy.ServiceProxy("mobilebase_arduino/gripper_angle",GripperAngle)
|
|
|
+# resp = gripper_client.call(int(key))
|
|
|
+ resp = gripper_client.call(command)
|
|
|
+ resp = gripper2_client.call(angle)
|
|
|
except rospy.ServiceException, e:
|
|
|
rospy.logwarn("Service call failed: %s"%e)
|
|
|
|
|
@@ -121,6 +147,8 @@ if __name__=="__main__":
|
|
|
z = 0
|
|
|
th = 0
|
|
|
status = 0
|
|
|
+ angle = 10
|
|
|
+ command = 2
|
|
|
|
|
|
try:
|
|
|
print(msg)
|
|
@@ -139,13 +167,56 @@ if __name__=="__main__":
|
|
|
print(vels(speed,turn))
|
|
|
if (status == 14):
|
|
|
print(msg)
|
|
|
- status = (status + 1) % 15
|
|
|
- elif key in gripperBindings.keys():
|
|
|
+ status = (status + 1) % 15
|
|
|
+# elif key in gripperBindings.keys():
|
|
|
+# x = 0
|
|
|
+# y = 0
|
|
|
+# z = 0
|
|
|
+# th = 0
|
|
|
+# client_srv()
|
|
|
+ elif key in gripperupBindings.keys():
|
|
|
x = 0
|
|
|
y = 0
|
|
|
z = 0
|
|
|
th = 0
|
|
|
+ command = 3
|
|
|
+ print("currently:\tgo up")
|
|
|
client_srv()
|
|
|
+ time.sleep(0.2)
|
|
|
+ command = 2
|
|
|
+ print("currently:\tstop !")
|
|
|
+ client_srv()
|
|
|
+ elif key in gripperdownBindings.keys():
|
|
|
+ x = 0
|
|
|
+ y = 0
|
|
|
+ z = 0
|
|
|
+ th = 0
|
|
|
+ command = 1
|
|
|
+ print("currently:\tgo down")
|
|
|
+ client_srv()
|
|
|
+ time.sleep(0.2)
|
|
|
+ command = 2
|
|
|
+ print("currently:\tstop !")
|
|
|
+ client_srv()
|
|
|
+ elif key in gripperopenBindings.keys():
|
|
|
+ x = 0
|
|
|
+ y = 0
|
|
|
+ z = 0
|
|
|
+ th = 0
|
|
|
+ print(angles(angle))
|
|
|
+ if (angle < 65 and angle >=0):
|
|
|
+ angle = angle + gripperopenBindings[key]
|
|
|
+ client_srv()
|
|
|
+ elif key in grippercloseBindings.keys():
|
|
|
+ x = 0
|
|
|
+ y = 0
|
|
|
+ z = 0
|
|
|
+ th = 0
|
|
|
+ print(angles(angle))
|
|
|
+ if (angle <= 65 and angle >0):
|
|
|
+ angle = angle + grippercloseBindings[key]
|
|
|
+ client_srv()
|
|
|
+
|
|
|
else:
|
|
|
x = 0
|
|
|
y = 0
|