question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do you setup a Controller?

See original GitHub issue

Consider I want to setup a gamepad controller to control a simulated robot:

gamepad = ipywidgets.Controller()
gamepad.buttons[0].observe(lambda data: self.robot.device["gripper"].open())
gamepad.buttons[1].observe(lambda data: self.robot.device["gripper"].close())
gamepad.axes[1].observe(lambda data: self.robot.move(-data["new"], 0), 'value')

But I can’t do that (I guess) because the gamepad hasn’t been initialized yet. When should I hook up the buttons to the functions? Is there a callback for after the controller has been initialized?

BTW, here is the simulator: https://github.com/Calysto/jyro/blob/master/docs/Jyro Simulator.ipynb

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
SylvainCorlaycommented, Mar 16, 2017

The flight simulator example does:

pad.links = []

def setup():
    if pad.connected:
        pad.links.append(dlink((pad.axes[1], 'value'), (fly_controls, 'pitch'), affine(0.0, factor)))
        pad.links.append(dlink((pad.axes[0], 'value'), (fly_controls, 'roll'), affine(0.0, -factor)))
        pad.links.append(dlink((pad.axes[3], 'value'), (fly_controls, 'forward_speed'), affine(0.0, 2 * factor)))
        pad.links.append(dlink((pad.axes[2], 'value'), (fly_controls, 'yaw'), affine(0.0, factor)))
        pad.links.append(dlink((pad.buttons[5], 'value'), (surf, 'scale'), lambda x: (10, 10, 1 - x)))
    if not pad.connected:
        for l in pad.links:
            l.unlink()
        pad.links = []

pad.observe(setup, names=['connected'])
setup()
1reaction
jasongroutcommented, Mar 16, 2017

Oh, I forgot about the .connected observable attribute. I’d rather just observe that, like you did above, without adding another function. That way we’re consistent in how to trigger actions - just use observe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Your Gaming Controllers With Your Computer
You may think that your Xbox One or PS4 controller will always stay ... Head into Settings then Controller Settings and make sure...
Read more >
[Steam] How to set up a controller for ... - University at Albany
No information is available for this page.
Read more >
How to Connect an Xbox Controller to a PC | PCMag
Plug one end of your USB-to-micro USB or USB-to-USB-C (depending on the version of controller) cable into the controller. Plug the other end...
Read more >
Connect an Xbox Wireless Controller to your console
The controller will automatically connect to the Bluetooth device you were just using. Once you connect your controller to your console, make sure...
Read more >
Setup Gamepad - Parsec
Once you create the profile, double-click it in the list to start configuring which keys on the keyboard will trigger a button on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found