I have a Raspberry Pi with a robotic kit and I would like to control it using a PS4 controller but using analog input. I have successfully connected the controller and I can read events and program the motors to answer binary input. The documentation (pyPS4Controller), however, is not explicit about using analog values (Ex: 50% press on R2 outputs 0.5 forward).
Could someone please help me figure out how to make this?
Thanks in advance!
# This is the example for binary buttons
from pyPS4Controller.controller import Controller
class MyController(Controller):
def __init__(self, **kwargs):
Controller.__init__(self, **kwargs)
def on_x_press(self):
print("Forward")
def on_x_release(self):
print("Stop")
# --> The objective is having some way to capture the "intensity" of the button press to use the motors accordingly
controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False)
controller.listen()
After some tweaking and trial and error I ended up finding a solution. The analog functions receive an input called
value
containing the analog value of the input given to the controller.