mirror of
https://github.com/wassname/pyrobolearn.git
synced 2026-09-09 11:31:38 +08:00
update game controllers and keyboard interfaces + example with quadcopter and wheeled robot
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user