From 2faf7c6e5757ba1eae5f07fd1b39eb470077a96f Mon Sep 17 00:00:00 2001 From: Kiru Park Date: Wed, 24 May 2017 16:48:08 +0200 Subject: [PATCH 1/4] added gripper control to uarm_core --- scripts/uarm_core.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/uarm_core.py b/scripts/uarm_core.py index ae895aa..607d8c0 100755 --- a/scripts/uarm_core.py +++ b/scripts/uarm_core.py @@ -211,6 +211,7 @@ def controlFcn(): print 'mt x y z speed - move to a point with speed(mm/s)' print ' for example: mt 0 12 12 10' print 'pp 1/0 - pump on/off' + print 'gp 1/0 - gripper on/off' print 'ss - status of stopper' print 'at - attach uarm' print 'de - detach uarm' @@ -273,6 +274,20 @@ def controlFcn(): print 'Incorrect inputs, should input 1 / 0 / HIGH / LOW / ON / OFF' pass + elif commands_split[0] == 'gripper' or commands_split[0] == 'gp': + if len(commands_split) == 1: + print 'Status should be input' + elif len(commands_split) >2: + print 'Too many inputs' + else: + if commands_split[1] == '1' or commands_split[1].lower() == 'high' or commands_split[1].lower() == 'on': + uarm.set_gripper(1) + elif commands_split[1] == '0' or commands_split[1].lower() == 'low'or commands_split[1].lower() == 'off': + uarm.set_gripper(0) + else: + print 'Incorrect inputs, should input 1 / 0 / HIGH / LOW / ON / OFF' + pass + # Current Coordinates elif commands_split[0] == 'currentCoords' or commands_split[0] == 'cc': if len(commands_split) == 1: From 2233430166bb472a92aa4e6e59d0d7d73d21a19a Mon Sep 17 00:00:00 2001 From: Kiru Park Date: Wed, 24 May 2017 17:05:00 +0200 Subject: [PATCH 2/4] added gripper control node, add subscriber of gripper and fixed subscriber of the pump --- scripts/gripper_node.py | 59 +++++++++++++++++++++++++++++++++++++++++ scripts/uarm_core.py | 40 +++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 4 deletions(-) create mode 100755 scripts/gripper_node.py diff --git a/scripts/gripper_node.py b/scripts/gripper_node.py new file mode 100755 index 0000000..14969f8 --- /dev/null +++ b/scripts/gripper_node.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +''' +# File Name : gripper_node.py +# Author : Kiru Park, Mainly refered from Joey Song's pump_node.py +# Version : V1.0 +# Date : 24 May, 2017 +# Modified Date : 24 May, 2017 +# Description : This documents is for uarm ROS Library and ROS package +''' + +# All libraries needed to import +# Import system library + +import rospy +import sys +from std_msgs.msg import String + +# raise error +def raiseError(): + print 'ERROR: Input Incorrect' + print 'ERROR: Input off / low / 0 or on / high / 1' + +# main exection function +def execute(): + + # define publisher and its topic + pub = rospy.Publisher('gripper_str_control',String,queue_size = 10) + rospy.init_node('gripper_node',anonymous = True) + rate = rospy.Rate(10) + + # process different inputs + if len(sys.argv) == 2: + data_input = sys.argv[1] + + # control pump on + if data_input.lower() == 'on' or data_input == '1' or data_input.lower() == 'high': + pub.publish('on') + + # control pump off + elif data_input.lower() == 'off' or data_input == '0' or data_input.lower() == 'low': + pub.publish('off') + else: + raiseError() + else: + raiseError() + + rate.sleep() + + +# main function +if __name__ == '__main__': + try: + execute() + except: + print '==========================================' + print 'ERROR: exectuion error' + raiseError() + pass diff --git a/scripts/uarm_core.py b/scripts/uarm_core.py index 607d8c0..1999e7f 100755 --- a/scripts/uarm_core.py +++ b/scripts/uarm_core.py @@ -339,10 +339,10 @@ def pumpCallack(data): data_input = data.data if data_input == 0: - uarm.pump_control(0) + uarm.set_pump(0) print 'Pump: Off' elif data_input == 1: - uarm.pump_control(1) + uarm.set_pump(1) print 'Pump: On' else: pass @@ -355,15 +355,44 @@ def pumpStrCallack(data): print data_input if data_input.lower() == 'low' or data_input.lower() == 'off': - uarm.pump_control(0) + uarm.set_pump(0) print 'Pump: Off' elif data_input.lower() == 'on' or data_input.lower() == 'high': - uarm.pump_control(1) + uarm.set_pump(1) print 'Pump: On' else: pass +def gripperCallback(data): + + data_input = data.data + + if data_input == 0: + uarm.set_gripper(0) + print 'Gripper: Off' + elif data_input == 1: + uarm.set_gripper(1) + print 'Gripper: On' + else: + pass + + +# pump str control function once received data from topic +def gripperStrCallback(data): + + data_input = data.data + print data_input + + if data_input.lower() == 'low' or data_input.lower() == 'off': + uarm.set_gripper(0) + print 'Gripper: Off' + elif data_input.lower() == 'on' or data_input.lower() == 'high': + uarm.set_gripper(1) + print 'Gripper: On' + else: + pass + # angles control function once received data from topic def writeAnglesCallback(servos): @@ -498,6 +527,9 @@ def listener(): rospy.Subscriber("pump_control",UInt8, pumpCallack) rospy.Subscriber("pump_str_control",String, pumpStrCallack) + rospy.Subscriber("gripper_control",UInt8, gripperCallback) + rospy.Subscriber("gripper_str_control",String, gripperStrCallback) + rospy.Subscriber("read_coords",Int32, currentCoordsCallback) rospy.Subscriber("read_angles",Int32, readAnglesCallback) rospy.Subscriber("stopper_status",Int32, stopperStatusCallback) From 3b293d2da1064094ab6e74b546e8b666a5dab7e3 Mon Sep 17 00:00:00 2001 From: Kiru Park Date: Wed, 24 May 2017 17:08:13 +0200 Subject: [PATCH 3/4] Modified readme for the gripper node --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 2dfe824..d0d60cd 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,16 @@ source ~/.bashrc rosrun uarm pump_node.py off ``` +- `gripper_node.py` is the node which can control the pump on or off. + + Use this node in the **monitor-mode** of `uarm_core.py` node + ```bash + # pump on + rosrun uarm gripper_node.py on + # pump off + rosrun uarm gripper_node.py off + ``` + - `report_angles_node.py` is the node which will report current angles. Use this node in the **monitor-mode** of `uarm_core.py` node From e3954e103eab7f24c09e754358120dc865206b37 Mon Sep 17 00:00:00 2001 From: Kiru Park Date: Wed, 24 May 2017 17:09:07 +0200 Subject: [PATCH 4/4] fixed error in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0d60cd..9ba622f 100644 --- a/README.md +++ b/README.md @@ -137,9 +137,9 @@ source ~/.bashrc Use this node in the **monitor-mode** of `uarm_core.py` node ```bash - # pump on + # gripper on rosrun uarm gripper_node.py on - # pump off + # gripper off rosrun uarm gripper_node.py off ```