0
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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
$\endgroup$
3
  • $\begingroup$ 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" $\endgroup$
    – L.P.
    Commented Nov 13, 2016 at 23:51
  • $\begingroup$ 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? $\endgroup$
    – L.P.
    Commented Nov 13, 2016 at 23:55
  • $\begingroup$ 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. $\endgroup$
    – Photon
    Commented Nov 26, 2016 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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