yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ROS USB Handle📖
Wired Handle Tutorial
Raspberry Pi Tutorial
  • 1.Install jupyterLab
  • 2.Basic course
  • 3.Control DOFBOT
Jetson nano tutorial
  • 1. Install jupyterLab
  • 2.Basic course
  • 3.Control DOFBOT
  • 4.Control Jetbot
Wireless Handle Tutorial
Basic Control Cases
  • 1. Install JupyterLab
  • 2. Basic course
ROS1 Course
  • 1. ROS1 Course
ROS2 course
  • 1. Environment Construction
  • 2.Handle controlled robot
Download
  • Code
  • APP(Android/iOS)
Download ZIP

Welcome to ROS USB Handle repository

2. Basic course

1. Installing the handle

Insert the USB port of the wireless controller into the USB port of the host (Jetson Nano or Raspberry Pi). (If you are logging in using remote jupyter lab, you need to plug it into the USB port of the computer you are logging in to remotely.)

image.png 

Open the battery compartment of the wireless handle, install the battery, cover it, and then turn on the wireless handle switch (set to ON).

image.png  

Finally, press the START button to connect the wireless controller. Due to the power saving function of the wireless controller, after a period of inactivity, it automatically enters sleep and requires pressing the START key to activate the connection.

image.png 

2. View the handle device number

Open http://html5gamepad.com Website, and then use the joystick to view the device number. Normally, only one joystick device number is connected and defaults to 0. You can see data changes on the joystick buttons.

image.png  

2. Run handle control code

The following code content needs to be executed according to each actual step, and cannot be run all at once.

# Handle remote control
In this example, we will use a gamepad controller connected to a web browser machine to print the remote control data of the handle.

### Create a handle controller
The first thing we need to do is create an instance of the 'Controller' widget, which we will use to drive our USB controller.
The 'Controller' widget accepts an 'index' parameter that specifies the number of controllers. If you have multiple controllers, or some game controllers appear in the form of multiple controllers, this is very useful. If only one handle is connected, the default index is 0. If there are multiple handles, the corresponding handle number needs to be entered based on the actual situation:
1. Open[ http://html5gamepad.com ]( http://html5gamepad.com )This webpage
2. Press the button of the handle you are using
3. Remember the corresponding index number that pops up when you press the button
Next, we will use this index to create and display controllers.

import ipywidgets.widgets as widgets
controller = widgets.Controller(index=0)  #Replace with the index number of the controller you have just tested and are currently using
display(controller)

import threading
import time
# Thread function operation library
import inspect
import ctypes

#Create a method for actively stopping processes
def _async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed"""
    tid = ctypes.c_long(tid)
    if not inspect.isclass(exctype):
        exctype = type(exctype)
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble,
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
        
def stop_thread(thread):
    _async_raise(thread.ident, SystemExit)

# Method of Creating a Handle Remote Rod to Receive and Print Data
##If the simulation mode of the handle is turned on (by pressing the ANALOG key), and the red light is on, the left direction key will not work, and both joysticks will output analog values. The left joystick will have sliding bars 0 and 1, and the right joystick will have sliding bars 2 and 3.
##Program functions:
1. Print which key is pressed each time.

def USB_Handle():
    delay_time = 0.01
    while 1:
        #Due to individual differences in the joystick handle, the reset value of the remote lever may not necessarily be zero, so it is necessary to filter with 0.1 to avoid misoperation.
    #Print data for the left joystick and directional keys
#A1 upper negative lower positive
        if controller.axes[1].value > 0.1: 
            print('L_DOWN=%.2f'%(controller.axes[1].value))
        elif controller.axes[1].value < -0.1: 
            print('L_UP=%.2f'%(controller.axes[1].value))
        time.sleep(delay_time)
 
        if controller.axes[0].value > 0.1: 
            print('L_RIGHT=%.2f'%(controller.axes[0].value))
            time.sleep(delay_time)
        elif controller.axes[0].value < -0.1: 
            print('L_LEFT=%.2f'%(controller.axes[0].value))
            time.sleep(delay_time)
            
        if controller.buttons[10].value == True:
            print('L_PRESS') 
            time.sleep(delay_time)
        
        if controller.axes[2].value > 0.1:
            print('R_UP=%.2f'%(controller.axes[2].value))
            time.sleep(delay_time)
        elif controller.axes[2].value < -0.1:
            print('R_DOWN=%.2f'%(controller.axes[2].value))
            time.sleep(delay_time)
 
        if controller.axes[5].value > 0.1:
            print('R_RIGHT=%.2f'%(controller.axes[5].value))
            time.sleep(delay_time)
        elif controller.axes[5].value < -0.1:
            print('R_LEFT=%.2f'%(controller.axes[5].value))
            time.sleep(delay_time)
        
        if controller.buttons[11].value == True:
            print('R_PRESS') 
            time.sleep(delay_time)
            
        
        # NUM1=B0,NUM2=B1,NUM3=B2,NUM4=B3
        if controller.buttons[0].value == True:
            print('NUM1')
            time.sleep(delay_time)
        if controller.buttons[1].value == True:
            print('NUM2')
            time.sleep(delay_time)
        if controller.buttons[2].value == True:
            print('NUM3')
            time.sleep(delay_time)
        if controller.buttons[3].value == True:
            print('NUM4')
            time.sleep(delay_time)
 
        # R1=B5,R2=B7
        if controller.buttons[5].value == True:
            print('R1')
            time.sleep(delay_time)
        if controller.buttons[7].value == True:
            print('R2')  
            time.sleep(delay_time)
 
        # L1=B4,L2=B6
        if controller.buttons[4].value == True:
            print('L1')
            time.sleep(delay_time)
        elif controller.buttons[6].value == True:
            print('L2') 
            time.sleep(delay_time)
        
        # SELECT=B8
        if controller.buttons[8].value == True:
            print('SELECT') 
            time.sleep(delay_time)
        # START=B9
        if controller.buttons[9].value == True:
            print('START') 
            time.sleep(delay_time)

#Start the thread of the handle by running the following cell code
#Wait for the handle control thread to start before operating the handle.
thread = threading.Thread(target=Arm_Handle)
thread.setDaemon(True)
thread.start()

#End handle thread.
#If a thread fails to start or end,
#Please restart the kernel and run it step by step again.
stop_thread(thread)

 3. Use handle

Click on the debugging information window in the bottom left corner, and a debugging information window will pop up. Pressing different keys will print the corresponding data.

image.png 

image.png 

At the same time, the plugin above will display the operation of the handle in a graphical manner.

image.png 

 

 


Install JupyterLab
ROS1 Course

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文