Control of the vacuum gripper plugin with the keyboard

asked 2019-05-18 07:43:29 -0500

joeced gravatar image

updated 2019-05-23 06:35:03 -0500

Hello, I am trying to control my whole robot with my keyboard and I am having a problem with controlling the vacuum gripper. I already know that the vacuum gripper is a client to the server '/vacuum_gripper' and I have to create the service server that will request the status of the gripper (True if gripper is on and False if gripper is off). I got stuck while creating my node and I am not quite sure how to proceed. I have created the moveBindings keys where a key would turn on the vacuum and another key would turn it off. I just don't know if I should use SetBool.srv as the type of my service and how should the vacuum gripper plugin wait for me to send a request on it. Can anyone help with how should I proceed or did anyone ever used the plugin and controlled it from keyboard? If so, can you share your code so I could proceed on my project?

Thank you in advance.

Update: Python source code of key binding node so far.

moveBindings = {

def getKey():
    tty.setraw(sys.stdin.fileno())[sys.stdin], [], [], 0)
    key =
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
    return key

if __name__=="__main__":
    settings = termios.tcgetattr(sys.stdin)

    pub = rospy.Publisher('Keyboard_Control', Twist, queue_size = 10)

    x = 0
    y = 0
    z = 0

            key = getKey()
            if key in moveBindings.keys():
                x = moveBindings[key][0]
                y = moveBindings[key][1]
                z = moveBindings[key][2]
            print (x, y, z)
                    x = 0
                    y = 0
                    z = 0
            print (x, y, z)
                    if (key == '\x03'):
edit retag flag offensive close merge delete


This doesn't make sense. The gripper would have to be the server, so that a client can be used to control it. Server's cannot initiate a request to a client, only a client to a server.

Are you talking about an action server or a service server here?

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-22 10:31:43 -0500 )edit

Since the vacuum gripper plugin is the server, can't a client (which is the keyboard in our case) send a request to the server?

joeced gravatar image joeced  ( 2019-05-22 10:53:45 -0500 )edit

the vacuum gripper is a client to the server

Sorry this was confusing me somewhat. If the gripper is being directly controlled by an service server. Then yes you can make a node which contains a server client to control it, and attaches to key bindings. Can you describe where you're up to and show us any code you have so far.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-22 11:04:20 -0500 )edit

This is the key bindings node that can identify any key pressed and then send the data to other nodes. can we implement it the client and send request from the same node?

joeced gravatar image joeced  ( 2019-05-22 11:35:31 -0500 )edit

Yes you certainly can, the python service client example here, shows you how to set this up. You simply need to test for the extra key codes and use the rospy.ServiceProxy method to call the service server.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-23 06:43:08 -0500 )edit