Roban2 Docs
Roban2 (ROS1) Legacy VersionsFeature ExamplesGeneral Examples

Keyboard Control Example

Description

  • Control the robot's motion using the keyboard

Example Code

  • Controlling robot motion with the keyboard:

    • ~/kuavo-ros-opensource/src/humanoid-control/humanoid_interface_ros/scripts/joystickSimulator.py

Program Logic

  1. Program initialization

    • At startup, the program initializes a ROS node named simulated_joystick
  • Creates an instance of the SimulatedJoystick class
    • Subscribes to the /stop_robot topic to receive signals for stopping the robot
  • Uses the termios library to set keyboard input to non-blocking mode so that keyboard input can be read in real time
    • Whole-body motion control

      • Publishes the /joy topic to send simulated joystick signals
  1. Keyboard input handling

    • getKey function:

      Uses the select library to monitor keyboard input, with a timeout of 0.1 seconds

      If there is keyboard input, reads a single character and returns it; otherwise returns an empty string

      If the keyboard input is ctrl+c, restores the original keyboard settings and exits the program

    • update_joy function:

      • Arm movement control

        Updates the end effector's position control (XYZ) and orientation control (RPY) parameter values according to keyboard input

      • Whole-body motion control

        Updates the simulated joystick's state (button and stick signals) according to keyboard input

  2. Control command publishing

    • Main loop:

      In the run function, the program enters the main loop and continuously monitors keyboard input.

    • Whole-body motion control

      If there is keyboard input, calls the update_joy function to update the joystick state.

      Publishes the updated joystick signal joy_msg to the /joy topic.

    • Exit conditions:

      If ctrl-c is pressed, the program exits the main loop.

      If a message is received on the /stop_robot topic, the program calls rospy.signal_shutdown to shut down the ROS node.

  3. Program exit

    • Resource cleanup:

      On program exit, restores the original keyboard settings to avoid keyboard input anomalies.

Parameter Description

  • joystick_sensitivity: sensitivity, unitless.

  • Modification path: ~/kuavo-ros-opensource/src/humanoid-control/humanoid_controllers/launch/joy/joy_control_sim.launch

Build

cd ~/kuavo-ros-opensource
sudo su
catkin build kuavo_sdk motion_capture_ik kuavo_msgs

Run

  • Start the robot

    • Note: joystick_type must not be set to bt2pro, otherwise the keyboard control mapping will have problems
    cd ~/kuavo-ros-opensource
    sudo su
    source devel/setup.bash
    # Run in simulation
    roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch 
    # Run on the real robot
    roslaunch humanoid_controllers load_kuavo_real.launch 
  • Start the keyboard control example

    • Note: make sure the BETOP controller receiver is not plugged into the robot
    cd kuavo-ros-opensource
    sudo su
    source devel/setup.bash
    python3 src/humanoid-control/humanoid_interface_ros/scripts/joystickSimulator.py
    # or
    rosrun humanoid_interface_ros joystickSimulator.py 
  • Operating instructions

    • The WASD keys act as the left joystick, controlling forward/backward and left/right strafing; each press increases or decreases the value by 10%;
    • The IK and JL/QE keys act as the right joystick, controlling up/down and turning left/right; each press increases or decreases the value by 10%;
    • The R key is walk (stepping in place); C is stance (standing in place);
    • The spacebar resets the left and right joystick inputs to zero.

Running Result

  • Controlling robot movement with the keyboard