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
-
Program initialization
- At startup, the program initializes a ROS node named
simulated_joystick
- At startup, the program initializes a ROS node named
- Creates an instance of the SimulatedJoystick class
- Subscribes to the
/stop_robottopic to receive signals for stopping the robot
- Subscribes to the
- 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
/joytopic to send simulated joystick signals
- Publishes the
-
-
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)andorientation 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
-
-
-
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
/joytopic. -
Exit conditions:
If
ctrl-cis pressed, the program exits the main loop.If a message is received on the
/stop_robottopic, the program callsrospy.signal_shutdownto shut down the ROS node.
-
-
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_msgsRun
-
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
WASDkeys act as the left joystick, controlling forward/backward and left/right strafing; each press increases or decreases the value by 10%; - The
IKandJL/QEkeys act as the right joystick, controlling up/down and turning left/right; each press increases or decreases the value by 10%; - The
Rkey is walk (stepping in place);Cis stance (standing in place); - The spacebar resets the left and right joystick inputs to zero.
- The
Running Result
-
Controlling robot movement with the keyboard
