Mixing multiple inputs from the gamepad controller

Hi all, in the teleoperation notebook I’m trying to setup the gamepad such that controller.axes[1].value is encoding forward/backward and controller.axes[2].value left/right. Thus, I tried:

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

However, although there is no error, the robot is not moving. My guess is therefore that traitlets tracks the member variables in controllor.axes[i] but not in controller. Any suggestions how this simple transformation from two controller axes to the motor could best be implemented?

Thanks in advance!

I don’t have answer right now, you can try to contact the author to ses if they can have suggestions.
May othere developers help to share experiences.


1 Like

I have no experience with jetbot teleoperation, so I tried it as a learning experience.
Jetbot is spin turn like ROS Turtlebot3, so the same theory can be used to control it.

Connect a gamepad like Logitech F710 to my PC running Google Chrome browser and open jetbot teleoperation.ipynb.

In my case, the F710 gamepad is index=0.

import ipywidgets.widgets as widgets

controller = widgets.Controller(index=0)  # replace with index of your controller


Next, use observe instead of dlink.

from jetbot import Robot
import traitlets

robot = Robot()

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

class Vel(traitlets.HasTraits):
    lin = traitlets.Float(default_value=0.0)
    ang = traitlets.Float(default_value=0.0)

vel = Vel()
wheel_separation = 1.0

lin_link =  traitlets.dlink((controller.axes[1], 'value'), (vel, 'lin'), transform=lambda x: -x)
ang_link = traitlets.dlink((controller.axes[2], 'value'), (vel, 'ang'), transform=lambda x: -x)

def control_vel(change):
    robot.left_motor.value = vel.lin - (vel.ang * wheel_separation / 2);
    robot.right_motor.value  = vel.lin + (vel.ang * wheel_separation / 2);

vel.observe(control_vel, names=('lin', 'ang'))

My jetbot, this worked.

Turtlebot3 linear_vel and angular_vel: turtlebot3/turtlebot3_teleop_key at 41816940d626eaa1efcd3ed05ce62bdac12f6d35 · ROBOTIS-GIT/turtlebot3 · GitHub

Turtlebot3 left/right motor control: OpenCR/turtlebot3_motor_driver.cpp at d807729a866c3f4e52a289c09f6fe6ab954c0e87 · ROBOTIS-GIT/OpenCR · GitHub

Hi @naisy,
thanks so much for your answer – it works perfectly! I’ve tried something similar before, but it wasn’t working as I wasn’t calling .observe(…).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.