From IPRE Wiki
Revision as of 19:46, 9 November 2009 by Ttthomas (Talk | contribs) ('''Using Your Game Pad to Drive Your Robot Around''')

Jump to: navigation, search

Lab 10: The Gamepad


  • Explore the different functions of the game pad

Using Your Game Pad to Drive Your Robot Around

In lab 02, you saw how you could use your game pad to control your robot's movements. You should ensure that your game pad is plugged into a USB port before starting IDLE. The annotated image below shows a game pad similar to the one you will be using.


To use the game pad, type the following at the prompt:


You should see the following options when you do this:

        Pad   Action
     ------   -------
 Left/Right   turnLeft() and turnRight()
    Up/Down   forward() and backward()

     Button   Action
     ------   -------
          1   stop()
          2   takePicture()
          3   beep(.25, 523)
          4   beep(.25, 587)
          5   beep(.25, 659)
          6   speak('Hello. My name is Dribbler.')
          7   speak('Ouch! I'm a sensitive robot.')
          8   speak('I'm hungry. Do you have any batteries?')

Gamepad is now running... Press button 1 to stop.

You can then use the buttons on your game pad to move your robot around as well as to explore additional features of your robot (e.g. taking a picture, beeping or speaking).

Useful Gamepad Details

  1. getGamepad("count") - returns (immediately) the number of gamepads connected
  2. getGamepad(ID, ITEM, ...) - return the ITEMs for gamepad ID. ID can be left out and will default to 0, the first one. If you request more than one ITEM, then they come back in a dictionary. Just request one ITEM and you'll get the value (as a list, string, or number).
  3. getGamepad([ID1, ID2...], ITEM, ...) - return the ITEMs for gamepad IDs as a list of lists of ID, RESULTS. For example:
    >>> getGamepad([0, 1], "button", "axis")
    [[0, {'button': [0, 0, 0, 0, 0, 0, 0, 0], 'axis': [0.0, 1.0]}], [1, {'button': [1, 1, 0, 0, 0, 0, 0, 0], 'axis': [-1.0, -1.0]}]]
    >>> getGamepad([0, 1], "axis")
    [[0, [0.0, 1.0]], [1, [-1.0, -1.0]]]
  4. getGamepad() has one keyword argument, "wait" for setting a sleep value between gamepad polls. Default is 0.05 seconds. Setting to zero will have small latency, but may eat up your CPU.

ITEM can be:

  1. "count" - returns (immediately) number of gamepads plugged in
  2. "robot" - returns axis values (floats) ready to be used by move() Myro command as [translate, rotate]
  3. empty - if nothing is passed in, it returns all of the following as a dictionary
  4. "init" - has this gamepad been initialized? as boolean
  5. "name" - name of gamepad, as string
  6. "axis" - returns values of axis controller in a list (as floats)
  7. "ball" - returns values of ball controller in a list
  8. "button" - returns values of buttons in a list (as integers)
  9. "hat" - returns values of hat in a list