I'm attempting to do a quick and dirty autonomous path with the create2. I'm using the tethered driving program seen here.

I set my own buttons just to make it rotate 90° and go forward one "pulse". I'd like to know, does anyone have any ideas on how to trick the attached Create2_TetheredDrive.py into thinking it's seeing a series of keyboard entries?

You can try putting your series of commands (or keyboard entries) as an array. After which, you can assign a for loop for this button, which will then run through the array of instructions.

The array might look something like this:

cmds = ['self.callbackKeyRight', 'self.callbackKeyDown',  'self.callbackKeyDown']

and the for loop code to run the array might look something like this:

 if event.type == '2': # KeyPress; need to figure out how to get constant
        if k == 'Z':   # Set some key here
            for i in range(len(cmds)):
                cmds[i] = True
                motionChange = True
                print 'Cmd number: ' + i
  • I implemented that code as you wrote it. I get the following error: Exception in Tkinter callback Traceback (most recent call last): File "usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in call return self.func(*args) File "Home/pi/Desktop/FILE", line 240, in callback Key cmds[i]=True NameError: Global name 'cmds1" not defined Is there a particular place I should put the array to define it as global? Right now I put it under "def callbackKey...global cmds1" – L.P. Nov 13 '16 at 23:51
  • However, if I just declare cdms1 within the command (under "elif k=='1':), and comment out the line "cmds1[i]=True", the shell displays the array, but doesn't actually carry out the command (convert it to the ASCII characters for the create). Any ideas? – L.P. Nov 13 '16 at 23:55
  • Maybe you can try writing a function with args that calls the callbackkey through the array instead of calling the keys directly from the array. – Photon Nov 26 '16 at 7:57

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.