update game controllers and keyboard interfaces + example with quadcopter and wheeled robot

This commit is contained in:
Brian Delhaisse
2019-06-21 03:26:36 +02:00
parent f512d42d31
commit c356c062bb
18 changed files with 1475 additions and 164 deletions
+5 -1
View File
@@ -12,6 +12,8 @@ from pyrobolearn.tools.interfaces.mouse_keyboard import MouseKeyboardInterface
sim = prl.simulators.Bullet()
# create mouse keyboard interface
# Note that to give the simulator `sim` to the interface can be optional especially if there is only one simulator.
# The interface will look in the memory to check the instantiated simulators and take the first one if it exists.
interface = MouseKeyboardInterface(sim)
# run interface
@@ -20,8 +22,10 @@ for _ in count():
interface.step()
# print pressed keys
if len(interface.key_pressed) > 0:
print("Keys that are pressed: {}".format(interface.key_pressed))
if len(interface.key_down) > 0:
print("Keys that are pressed: {}".format(interface.key_down))
print("Keys that are down: {}".format(interface.key_down))
# perform a step with the simulator
sim.step(sleep_time=sim.dt)
+14 -4
View File
@@ -1,23 +1,33 @@
#!/usr/bin/env python
"""Load the Playstation game controller interface
How to run:
```
$ python playstation.py --help # for help
$ python playstation.py --controller ps # to use any PS game controller (by default)
$ python playstation.py --controller ps3 # to use PS3 game controller
$ python playstation.py --controller ps4 # to use PS4 game controller
```
"""
import time
from itertools import count
import argparse
from pyrobolearn.tools.interfaces.controllers.playstation import PS3ControllerInterface, PS4ControllerInterface
from pyrobolearn.tools.interfaces.controllers.playstation import *
# create parser to select the game controller
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--controller', help='The Playstation game controller to use (ps3 or ps4)', type=str,
choices=['ps3', 'ps4'], default='ps4')
parser.add_argument('-c', '--controller', help='The Playstation game controller to use (ps, ps3, or ps4)', type=str,
choices=['ps', 'ps3', 'ps4'], default='ps')
args = parser.parse_args()
# load corresponding Playstation controller interface
if args.controller == 'ps':
controller = PSControllerInterface(verbose=False)
if args.controller == 'ps3':
controller = PS3ControllerInterface(verbose=True)
controller = PS3ControllerInterface(verbose=False)
elif args.controller == 'ps4':
controller = PS4ControllerInterface(verbose=False)
else: