Basic Usage
Testing with the Example Code
Getting the Code
- Clone the code: git clone https://gitee.com/leju-robot/kuavo_opensource
Confirming the Robot Version in the Environment Variables
-
Our Kuavo physical robots come in multiple models, and the program has already been adapted to the different versions. You only need to set the robot version in the environment variables.
-
To confirm the robot version, enter
echo $ROBOT_VERSIONin the terminal. It outputs an integer of the version number times 10, e.g. Kuavo 2.3 corresponds to 23, Kuavo 3.2 to 32, and so on. -
If the robot version is not set, or the version number does not match your robot, set it following the steps below.
1. Choose the corresponding configuration file according to the terminal type you use. For example, for a bash terminal, edit `~/.bashrc`; 2. Add `export ROBOT_VERSION=23` (Kuavo 2.3 corresponds to 23, Kuavo 3.2 to 32, and so on) to the end of the file, then save and exit. 3. Reopen the terminal or run `source ~/.bashrc`, then recompile the code for the change to take effect.
Configuration Files
- The Kuavo-related configuration files are located in the
$HOME/.config/lejuconfig/config/config/kuavo_v*directory, where*is the robot version number. - The Kuavo-related model files are located in the
$HOME/.config/lejuconfig/models/directory. - When the program starts, if the configuration files or model files do not exist, they are automatically copied from the corresponding directories under src.
- If you need to modify the configuration files, please modify the configuration files in the
$HOME/.config/lejuconfig/config/kuavo_v*directory. - When the program starts, it prints the following configuration file information. If your modification does not take effect, check whether the configuration file actually loaded by the program is the same as the one you modified:
[ConfigReader] CURRENT_SOURCE_DIR: /home/carlos/ohh_katkin_ws/src/kuavo
[ConfigReader] CONFIG_ROOT_PATH: /home/lab/.config/lejuconfig
[ConfigReader] CONFIG_PATH: /home/lab/.config/lejuconfig/config/kuavo_v4.0/kuavo.jsonHead Joint Configuration
When the robot has head joints (sometimes the head may be absent or its cable may be disconnected), if you need to obtain the head joint position information, you need to modify the configuration files in the $HOME/.config/lejuconfig/config/kuavo_v* directory (v3.4, v4.0...) and add the following content:
- Modify MOTORS_TYPE to declare the type of the head motors, e.g.
ruiwo, - Modify min_joint_position_limits and max_joint_position_limits to declare the position limits of the head joints.

If you do not need head joint information, skip this step.
Disabling Joints
- Disabled joint motor: append
_disabletoMOTOR_TYPEin the configuration file to disable the joint - Missing joint motor: append
_nonetoMOTOR_TYPEin the configuration file to disable the joint
{
"MOTORS_TYPE":[
"PA100_18_none", "PA100_none", "PA100_none", "PA100_none", "CK_none", "CK_none",
"PA100_18_none", "PA100_none", "PA100_none", "PA100_none", "CK_none", "CK_none",
"PA100_disable", "ruiwo_disable", "ruiwo_disable", "ruiwo", "ruiwo", "ruiwo", "ruiwo",
"PA100_disable", "ruiwo_disable", "ruiwo_disable", "ruiwo", "ruiwo", "ruiwo", "ruiwo"],
}Driver types that support disabled joints: EC_Master, ruiwo
Driver types that support missing joints: EC_Master
Dependencies
The development libraries that kuavo currently depends on are listed below. The following dependencies need to be installed before compiling:
libmodbus-dev:amd64
libmodbus5:amd64
libusb-1.0-0-dev
sudo apt install libmodbus-dev:amd64 libmodbus5:amd64 libusb-1.0-0-devCompiling the Code
Build option description:
USE_PYTHON_RUIWO_SDK
- ON: use the Python version of the SDK for ruiwo_controller
- OFF: default value; use the C++ version of the SDK for ruiwo_controller
ONLY_USE_HALF_UP_BODY
- ON: control only the upper body
- OFF: default value; enable all body joints as normal
Usage example: catkin_make -DONLY_USE_HALF_UP_BODY=ON -DUSE_PYTHON_RUIWO_SDK=OFF
- cd kuavo_opensource (if you used git clone https://gitee.com/leju-robot/kuavo_opensource new_dir, then you should cd into new_dir here)
- mkdir build to create the directory required by cmake
- cmake .. to generate the Makefiles used for compilation with cmake (Note: you need to delete the contents of the original build directory before compiling, to avoid stale cache preventing the changes from taking effect)
- make -j$(nproc) uses the number of CPUs on the current system as the maximum number of parallel threads for make
- If the compilation fails, use git status to check whether the code or the related third-party libraries have been modified
- If the compilation succeeds, an executable file will be produced at ./src/biped_v2/kuavoController
Running the Program
Compiling the repository code produces several executable files:
- ./src/biped_v2/kuavoController: the control program, which can be run directly to control the robot's motion
- ./src/biped_v2/bin2csv: the log conversion program, which converts the recorded logs to csv format so they can be opened in tools such as plotjuggler
- ./src/biped_v2/drake_play_back: the playback program, which can replay previous logs
Parameter Description
The kuavoController program contains many parameters; you can use --help to view their usage. Common ones include:
- --real: run on the real robot; on the physical robot it needs to be run with root privileges
- --cali: calibration mode (only used on the physical robot); in calibration mode all of the robot's motors return to zero, which is used to check whether the zero positions are correct
- --setzero: triggers zero-position calibration of the robot's ruiwo motors; only used on the physical robot and when running in
ROSmode (must be used together with the--caliparameter) - --log: enables lcm logging, off by default. When enabled, all state variables at every moment (accurate to 0.1 ms) are recorded into an
lcm_log.binfile, which can be converted to csv format with bin2csv
The bin2csv program accepts the path of the binary log file to be converted and the name of the output csv file.
- If no arguments are specified, the log file saved by the most recent run of
kuavoControllerto/tmp/lcm_log.binis used by default. - All logs of each run are saved in the
/var/lcm_log/directory, named by timestamp.
Running in Simulation
The simulation environment is based on drake. Refer to the following steps. If you want to run Drake with docker, refer to docs/kuaovo_docker_env.md
-
Run drake-visualizer to start the drake frontend environment
-
Run the robot program:
sudo ./src/biped_v2/kuavoController
Key Bindings:
:speech_balloon: : Note that the keys are pressed in the terminal where kuavoController is executed, and after each key press you must press Enter again for it to take effect.
- Only in the standing state can you switch to action modes such as walking, jumping, and squatting
- Press r to enter the walking state
- Press j to enter the jumping state
- Press p to enter the squatting state
- Press h and k to open and close the grippers (requires the physical robot to support this)
- Press number keys 1,2,3...7 to execute the n-th action in the corresponding configuration file (
$HOME/.config/lejuconfig/config/<ROBOT_VERSION>/pose_hand_arm.csv) - Press number keys 8 and 9 to execute the corresponding combined actions in the configuration file (
$HOME/.config/lejuconfig/config/<ROBOT_VERSION>/pose.csv)
- In the walking state
- By default, entering the walking state is in velocity control mode, and the robot steps in place
- Press w,a,s,d to move the robot forward, backward, left, and right
- Press q,e to rotate the robot left and right
- While moving, press the space bar to bring the robot's velocity to zero
- Press c to exit the walking state and return to the standing state
- In the jumping state
- Upon entering the jumping state, the robot first squats down slowly; jumping can only start after it has squatted to a standstill
- Press the space bar or j to jump
- The robot jumps and lands automatically; once the robot is standing firm, you can press the space bar or j again to jump
- Press c or q to exit the jumping state and return to the standing state
- In other states
- Press c or q to exit the current state and return to the standing state
Running on the Physical Robot
Calibrating the Robot's Motor Positions
Since the motors' single encoders are currently mounted on the high-speed end of the motors and cannot yet remember the absolute joint positions, every time the motors are powered off and restarted, the motor positions must first be calibrated so that they fall within the same revolution as the previously recorded zero position. After that, the robot can be used normally.
- Lift the robot off the ground, bend all joints to the starting position, and power on the robot's NUC and motors
- Run sudo ./src/biped_v2/kuavoController --real --cali and wait for the EtherCat communication self-check. If the self-check passes, the robot's motors will move to the starting position. If the starting position is observed to be incorrect, simply turn off the main motor switch, adjust the position of each motor, power on again, keep the NUC on, and run sudo ./src/biped_v2/kuavoController --real --cali once more.
- Repeat the loop above until the robot moves from its initial position to the normal position after the calibration program starts.
- After calibration is complete, the robot's motors will remember the calibrated position. The user can run the control program repeatedly before the motors are powered off, without calibrating again.
- If it is really impossible to straighten the robot's initial position by adjusting the power-on position, you can, when necessary, adjust the robot's state to the correct position by adjusting the robot's zero points (note that the robot's zero points have already been adjusted at the factory; unless the motors have been disassembled and reassembled, there is normally no need to recalibrate the zero positions — you only need to make sure that the position recorded by the encoder at power-on is within the same revolution as the recorded zero point).
- The zero point file is located at
~/.config/lejuconfig/offset.csv - Before powering on, bend the robot so that all body joints are straight, then power on and run the calibration program above. While running, the program prints the initial position of each motor; write these positions into
~/.config/lejuconfig/offset.csv. - The zero positions can also be fine-tuned manually according to the actual walking or standing behavior.
- The zero point file is located at
Using the Example Program
- Run sudo ./src/biped_v2/kuavoController --real
The operating procedure is as follows:
2.1 Hoist the robot off the ground; after the robot is fully extended vertically, its soles should be more than 2CM above the ground
2.2 Enter the command above and press Enter. The robot will then control all motors to move to the ready state. The robot's legs will retract.
2.3 Lower the robot so that, with its legs retracted, its soles are about 2CM above the ground.
2.4 One person, wearing gloves, holds the robot's torso while the other person presses the o key, and the robot will enter the standing state. While standing, the robot tends to tip backward, so the person holding it should apply slight force to help the robot keep its balance. Once the robot is balanced, let go.
2.5 After the robot is standing, press the r key, and the robot will enter the velocity-based gait mode. After entering the gait, the velocity in every direction defaults to 0; use a (left), d (right), w (forward), d (backward) to change the velocities on the x,y axes and control the robot to move forward, backward, left, and right. When the robot moves, the hoist holding the robot must move in sync and must not tug at the robot.
2.6 To exit the gait mode, press the c key. The robot will reset its movement velocity, exit the gait mode, and return to standing. (Note! Do not exit the program directly with Ctrl+C at this point; otherwise all of the robot's joints will suddenly be released from control, generating large inertia that may snap the hoist's steel cable and cause the robot to fall and be damaged.)
2.7 To finish debugging, press the p key, and the robot will retract its legs. Lower the robot with the hoist until its soles are about 2 CM above the ground after retraction. Press Ctrl+C to exit the program.
Source Code Description
.
├── CMakeLists.txt
└── src
├── main.cc 入口程序
├── StandRobot.cc 整体的框架,里面包含了状态估计,运动控制的调用
├── StandRobot.h
├── StandStateEstimation.cpp 状态故常模块
├── StandStateEstimation.h
├── StandTrajectory.cc 运动控制模块
├── StandTrajectory.h
├── StateMachineError.cc 机器人状态机的实现:处理错误的状态
├── StateMachineError.h
├── StateMachineStand.cc 机器人状态机的实现:处理站立的状态
└── StateMachineStand.h
Note: There is a basic explanation in StandTrajectory::StandTrajectory. In this standing example program, the user can try modifying the Yaw and Pitch angles of the robot's torso to observe the robot's behavior, and can modify the height above the ground to adjust the robot's standing height. Please note that parameter changes should first be tried in the simulation environment, and when running, the robot's safety rope should be hung on the support frame. This is because if the modified values are too large, the inverse kinematics may fail and the program may crash, causing the robot to fall to the ground.
Arm Servo Zero-Point Calibration Program (if you have reinstalled the system, or the arm's zero points are damaged, you can recalibrate using the following method)
This is used to calibrate the working range of the servos and record the current zero points. If the program is run with the --record parameter, the latest information will be written into the zero-point configuration file ~/.config/lejuconfig/servos_positions.ini.
Without the --record parameter, it will only print the current servo positions and the read maximum and minimum values at 1000 ms intervals.
Running the Wrist Servo Calibration Program
Switch to the root directory of the repository, for example kuavo_opensource. Then run the following command
sudo ./bin/start_tools.sh ./bin/dynamixel_calibrate_servos --record-
Turn each servo left and right to its limit positions, and hold at the limit positions for 2 seconds.
-
Turn each servo to its zero-point position and hold for 2 seconds.
-
Press q and then Enter, and wait for the calibration program to exit. After the calibration program exits, the zero point and valid motion range of each servo will be recorded in
~/.config/lejuconfig/servos_positions.ini. -
Add the udev rules for the servo devices and set latency_timer automatically. This only needs to be added after reinstalling the system; robots from the factory already have it added.
sudo cp 99-usb-servo.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger