0

I am using a Jupyter notebook for my project with a Xbox controller to control a robot in real time.

import ipywidgets.widgets as widgets is used

it works directly assigning them to sliders or motors using traitlets, but I do not how to do calculations with them beforehand.

If I assign these values to variables, it gets the current value at the time of running the cell.

Here is working code that assigns directly to motor:

left_link = traitlets.dlink((controller.axes[1], 'value'), (robot.left_motor, 'value'), transform=lambda x: -x)

However, I need to calculate the angle I want to go, therefore calculating arctan2 of two axes of joystick values (the transform: lambda does not suffice I think?).

I do not understand how I should take on this problem, as I have never worked with always updating variables, like the Xbox controller variables. Please tell me if you need any more information.

1 Answers1

1

The thing I was looking for was Observe() like here:

import ipywidgets.widgets as widgets

int_range = widgets.IntSlider()
display(int_range)
def on_value_change(change):
    print(change)
    print(change['new'])
int_range.observe(on_value_change, names='value')

This allows reassigning the variable value everytime the controller changes it's value.