Control of the vacuum gripper plugin with the keyboard

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

joeced gravatar image

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

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 = {
        'w':(0.01,0,0),
        's':(-0.01,0,0),
        'd':(0,0.01,0),
        'a':(0,-0.01,0),
        'r':(0,0,0.01),
        'f':(0,0,-0.01),
    }

def getKey():
    tty.setraw(sys.stdin.fileno())
    select.select([sys.stdin], [], [], 0)
    key = sys.stdin.read(1)
    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)
    rospy.init_node('teleop_keyboard')

    x = 0
    y = 0
    z = 0

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

Comments

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 imagePeteBlackerThe3rd ( 2019-05-22 10:31:43 -0600 )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 imagejoeced ( 2019-05-22 10:53:45 -0600 )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 imagePeteBlackerThe3rd ( 2019-05-22 11:04:20 -0600 )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 imagejoeced ( 2019-05-22 11:35:31 -0600 )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 imagePeteBlackerThe3rd ( 2019-05-23 06:43:08 -0600 )edit