WEBVTT

NOTE
[Locomotion] [IL] Motion Tracking Control: From Motion Retargeting to Imitation Learning Training
Transcript by RoboGeeks: https://robogeeks.org/videos/ohINsroS7Bc

1
00:00:14.800 --> 00:00:22.800
Hello everyone, my name is Robo Xiang. I am an algorithm engineer at Deep Robotics.

2
00:00:22.800 --> 00:00:30.800
Many of you have probably seen robots dancing like humans on video platforms or on stage.

3
00:00:30.800 --> 00:00:37.800
These smooth human-like movements are usually achieved through imitation learning.

4
00:00:37.800 --> 00:00:45.800
In this video, I will introduce the imitation learning training code for the DR02 robot.

5
00:00:45.800 --> 00:00:53.800
The video has two main parts, motion retargeting and imitation learning training.

6
00:00:53.800 --> 00:01:04.800
Both parts are open source, delivering to GitHub repositories, Deep Robotics Retarget and Deep Robotic Mimic.

7
00:01:04.800 --> 00:01:10.800
Before we dive in, let me make a quick disclaimer.

8
00:01:10.800 --> 00:01:14.800
Both repositories are still work in progress.

9
00:01:14.800 --> 00:01:20.800
If you spot anything that could be improved, feel free to let us know.

10
00:01:20.800 --> 00:01:22.800
Let's go start.

11
00:01:22.800 --> 00:01:25.800
First, let's look at motion retargeting.

12
00:01:25.800 --> 00:01:29.800
In this section, I will explain why we need motion retargeting.

13
00:01:29.800 --> 00:01:33.800
Look at some common human motion data formats.

14
00:01:33.800 --> 00:01:38.800
Introduce the GMR algorithm and its implementation.

15
00:01:38.800 --> 00:01:43.800
And finally, show you how to use our retargeting tool.

16
00:01:43.800 --> 00:01:45.800
Motion retargeting is a technique.

17
00:01:45.800 --> 00:01:51.800
It converts human motion data into motion for a humanoid robot.

18
00:01:51.800 --> 00:01:58.800
The robot usually has a different skeleton sculpture and different body proportions.

19
00:01:58.800 --> 00:02:03.800
You might be wondering, why do we need motion retargeting at all?

20
00:02:03.800 --> 00:02:08.800
Can we just collect data that the robot can use structurally?

21
00:02:08.800 --> 00:02:11.800
Let's think about a simple example.

22
00:02:11.800 --> 00:02:17.800
Suppose you bend down and want your fingers to touch the ground.

23
00:02:17.800 --> 00:02:20.800
If we want the robot to imitate this movement,

24
00:02:20.800 --> 00:02:24.800
we can't simply copy the human joint angles.

25
00:02:24.800 --> 00:02:29.800
That's because humans and robots have different body structures.

26
00:02:29.800 --> 00:02:34.800
They have different body proportions, different joint motion ranges,

27
00:02:34.800 --> 00:02:38.800
and different coordinate system directions.

28
00:02:38.800 --> 00:02:44.800
As you can see, these images compare our robot with the human skeleton

29
00:02:44.800 --> 00:02:47.800
from the free-motion data source.

30
00:02:47.800 --> 00:02:55.800
So, copying the joint angles directly will most likely not achieve the same movement.

31
00:02:55.800 --> 00:03:01.800
The robot head might go through the ground or stay in the air.

32
00:03:01.800 --> 00:03:06.800
The robot might even end up in an unnatural posture.

33
00:03:06.800 --> 00:03:12.800
So, the purpose of motion retargeting is to convert human motion into a form

34
00:03:12.800 --> 00:03:16.800
that the robot can actually use.

35
00:03:16.800 --> 00:03:23.800
In general, complete human motion data is a squeeze of skeleton process

36
00:03:23.800 --> 00:03:25.800
that changes over time.

37
00:03:25.800 --> 00:03:30.800
It has two parts, the skeleton and the motion.

38
00:03:30.800 --> 00:03:37.800
The skeleton describes which joints the human body has and how they connect.

39
00:03:37.800 --> 00:03:43.800
The motion describes the pose of the skeleton at each time step.

40
00:03:43.800 --> 00:03:50.800
Playing many frames continuously on one skeleton gives a complete motion.

41
00:03:50.800 --> 00:03:56.800
Common human motion data formats include SMPL and BVH.

42
00:03:56.800 --> 00:03:58.800
Let's look at both.

43
00:03:58.800 --> 00:04:02.800
SMPL is a parametric human body model.

44
00:04:02.800 --> 00:04:07.800
It describes the body with shape parameters, called beta,

45
00:04:07.800 --> 00:04:10.800
and pose parameters, called theta.

46
00:04:10.800 --> 00:04:16.800
The ARMA's dataset contains a large amount of human motion capture data,

47
00:04:16.800 --> 00:04:21.800
converted into the SMPL parameter format.

48
00:04:21.800 --> 00:04:25.800
Let's see what is stored in the data file.

49
00:04:25.800 --> 00:04:29.800
First, the bird shape parameter is beta.

50
00:04:29.800 --> 00:04:31.800
And this is gender.

51
00:04:31.800 --> 00:04:37.800
It is used because SMPLX provides three gender models.

52
00:04:37.800 --> 00:04:41.800
Based on this parameter, we select the correct one.

53
00:04:41.800 --> 00:04:44.800
And this is sampling rate.

54
00:04:44.800 --> 00:04:47.800
Then, we have the full body pose.

55
00:04:47.800 --> 00:04:53.800
The pose data has a shape of 718 by 63,

56
00:04:53.800 --> 00:04:59.800
which means 718 frames and 63 body joints.

57
00:04:59.800 --> 00:05:10.800
We also have position and orientation of the model roots in the vertical coordinate system.

58
00:05:10.800 --> 00:05:15.800
There are some other frames, but we usually do not use them.

59
00:05:15.800 --> 00:05:21.800
If you are interested, you can find more details in the relative documentation.

60
00:05:21.800 --> 00:05:26.800
BVH stands for BioVision Hierarchy.

61
00:05:26.800 --> 00:05:31.800
Compared with SMPL, BVH is more compact.

62
00:05:31.800 --> 00:05:35.800
It mainly contains two types of information,

63
00:05:35.800 --> 00:05:40.800
the skeleton hierarchy and motion data for each frame.

64
00:05:40.800 --> 00:05:43.800
At the beginning of the file,

65
00:05:43.800 --> 00:05:47.800
BVH defines the skeleton hierarchy,

66
00:05:47.800 --> 00:05:53.800
includes parent-children relationships between joints and joint offsets.

67
00:05:53.800 --> 00:06:00.800
Then, it records profound motion information, such as joint rotations.

68
00:06:00.800 --> 00:06:04.800
Our code is modified from the GMR project.

69
00:06:04.800 --> 00:06:07.800
GMR stands for General Motion Retargeting.

70
00:06:07.800 --> 00:06:13.800
It is an open-source, general-purpose motion retargeting framework.

71
00:06:13.800 --> 00:06:17.800
It provides a unified solution for motion retargeting.

72
00:06:17.800 --> 00:06:25.800
The code of the GMR is based on inverse kinematics, or IEK.

73
00:06:25.800 --> 00:06:28.800
The GMR algorithm has three steps.

74
00:06:28.800 --> 00:06:36.800
First, use a configuration file defines the correspondence between human body parts,

75
00:06:36.800 --> 00:06:39.800
human body parts and robot body parts.

76
00:06:39.800 --> 00:06:42.800
Second, for each frame of human motion,

77
00:06:42.800 --> 00:06:49.800
we calculate the positions and orientations of the human body parts.

78
00:06:49.800 --> 00:06:54.800
Finally, we use this value as targets for the robot,

79
00:06:54.800 --> 00:06:59.800
and solve the robot joint angles with inverse kinematics.

80
00:06:59.800 --> 00:07:06.800
Now, let's see how this is implemented in the code.

81
00:07:06.800 --> 00:07:08.800
In this repository,

82
00:07:08.800 --> 00:07:15.800
the access folder contains our robot URDF model and the SMPLX model.

83
00:07:15.800 --> 00:07:22.800
The SMPLX model needs to be downloaded beforehand by yourself.

84
00:07:22.800 --> 00:07:28.800
The general motion retargeting folder contains the main algorithm,

85
00:07:28.800 --> 00:07:36.800
the retargeting configuration file, the core algorithm, and utility and visualization plugins.

86
00:07:36.800 --> 00:07:43.500
The script folder contains explained programs.

87
00:07:43.500 --> 00:07:50.500
It provides examples for retargeting data from different sources,

88
00:07:50.500 --> 00:07:55.500
plus conversion and visualization tools.

89
00:07:55.500 --> 00:08:00.500
In the general motion retargeting folder, focus on three frames.

90
00:08:00.500 --> 00:08:21.500
The IEK configures folder contains the IEK configuration file for the three supported data sources.

91
00:08:21.500 --> 00:08:28.500
In the LTS folder, two programs load BVH and SMPL data.

92
00:08:28.500 --> 00:08:38.500
They read the human motion and calculate the position and orientation of all key joints for each frame.

93
00:08:38.500 --> 00:08:48.500
The Lefenwender folder contains a BVH parsing library, plus some other utility functions.

94
00:08:48.500 --> 00:08:53.500
The configuration file has almost the same structure.

95
00:08:53.500 --> 00:09:01.500
Here, we specify the roots of the robot model and the human skeleton model.

96
00:09:01.500 --> 00:09:07.500
We also define the ground height, weather use, two IEK stages.

97
00:09:07.500 --> 00:09:14.500
This is one of GMR's important features and the scale table for key points.

98
00:09:14.500 --> 00:09:20.500
By applying different scale factors to different body parts,

99
00:09:20.500 --> 00:09:25.500
we can better align the human motion model with the robot model.

100
00:09:25.500 --> 00:09:33.500
The scale factor is applied to the position of each body part in the local coordinate system,

101
00:09:33.500 --> 00:09:37.500
whose origin is the human root.

102
00:09:37.500 --> 00:09:47.500
After that, the root position is scaled as a whole in the global coordinate system.

103
00:09:47.500 --> 00:09:50.500
Finally, there are two IEK match tables.

104
00:09:50.500 --> 00:09:54.500
Each key represents a joint.

105
00:09:54.500 --> 00:09:59.500
It defines the position and orientation tracking weights,

106
00:09:59.500 --> 00:10:06.500
plus the position and orientation of sets between the human and robot skeletons.

107
00:10:06.500 --> 00:10:13.500
In practice, we mainly adjust the tracking weights based on the task.

108
00:10:13.500 --> 00:10:25.150
When switching to a new dataset, the human scale table is usually the first thing we turn.

109
00:10:25.150 --> 00:10:31.150
The params.py file contains several configuration registers,

110
00:10:31.150 --> 00:10:38.150
the body model path, the IEK configure paths for different data sources,

111
00:10:38.150 --> 00:10:47.150
the robot space name, the robot space name, and the camera distance for visualization.

112
00:10:47.150 --> 00:10:53.150
The core algorithm is implemented in MotionRetarget.py,

113
00:10:53.150 --> 00:10:59.150
which defines the general motion retargeting class.

114
00:10:59.150 --> 00:11:04.150
During initialization, it loads the robot's model

115
00:11:04.150 --> 00:11:11.150
and prints the robot joints, bodies, and motors in the terminal.

116
00:11:11.150 --> 00:11:17.150
Then it loads the IEK configuration and applies the settings.

117
00:11:17.150 --> 00:11:21.150
Finally, it builds up the constraint list.

118
00:11:21.150 --> 00:11:27.150
Besides joint limits, there are two optional constraints.

119
00:11:27.150 --> 00:11:32.150
velocity limits, and collision avoidance.

120
00:11:32.150 --> 00:11:34.150
They are usually disabled by default.

121
00:11:34.150 --> 00:11:39.150
You can enable them in the configuration if you need it.

122
00:11:39.150 --> 00:11:45.590
The core method is the retargeting function.

123
00:11:45.590 --> 00:11:51.590
It defines the complete process for one motion frame.

124
00:11:51.590 --> 00:11:59.590
First, preprocess the input data, including scaling and offset compensation.

125
00:11:59.590 --> 00:12:02.590
Then we perform IEK in two stages.

126
00:12:02.590 --> 00:12:07.590
In the first stage, we usually tracking orientation only.

127
00:12:07.590 --> 00:12:11.590
The maximum number of iterations is 10.

128
00:12:11.590 --> 00:12:20.590
The goal is to quickly find a roughly correct joint configuration with sample constraints.

129
00:12:20.590 --> 00:12:26.590
In the second stage, we track both position and orientation.

130
00:12:26.590 --> 00:12:31.590
The maximum number of iterations is increased to 100,

131
00:12:31.590 --> 00:12:40.590
and the coverage threshold is reduced from 10 to the minor 3 to 10 to the minor 5.

132
00:12:40.590 --> 00:12:45.590
To avoid getting stuck when the target is unreachable.

133
00:12:45.590 --> 00:12:59.590
The server also stops if there is no improvement for five consecutive items and the error is still larger than 0.01.

134
00:12:59.590 --> 00:13:02.590
Why two stages?

135
00:13:02.590 --> 00:13:09.590
Throwing position and orientation together is computationally expensive,

136
00:13:09.590 --> 00:13:14.590
and more likely to get stuck in a local optimum.

137
00:13:14.590 --> 00:13:23.590
By allowing orientation first, we usually improve both convergence speed and solution quality.

138
00:13:23.590 --> 00:13:27.590
Now, let's look at how to use the tool.

139
00:13:27.590 --> 00:13:33.590
We use a BVH file in the NoKai format as an example.

140
00:13:33.590 --> 00:13:44.590
Just run a sample comment and specify the input and output file path, and the retargeting process starts.

141
00:13:44.590 --> 00:13:51.590
After it runs, we first see the motion played on the robot model.

142
00:13:51.590 --> 00:14:00.590
When playback finished, the corresponding robot motion data is generated.

143
00:14:00.590 --> 00:14:09.590
This visualization lets us check two things, whether the input human motion is correct,

144
00:14:09.590 --> 00:14:15.590
and whether the retargeting robot motion looks reasonable.

145
00:14:15.590 --> 00:14:22.590
If the reference motion is complex and the result looks not well,

146
00:14:22.590 --> 00:14:28.590
or you need higher accuracy for the hands or legs,

147
00:14:28.590 --> 00:14:34.590
we can modify the IEK config file for that data format.

148
00:14:34.590 --> 00:14:42.590
Adjust the constraints weights, try a few times, and the final result improves.

149
00:14:42.590 --> 00:14:51.590
After obtaining the retargeting motion data, we can start the imitation learning process.

150
00:14:51.590 --> 00:14:57.590
Next, I will introduce our code repository in five parts.

151
00:14:57.590 --> 00:15:04.590
Code structure, robot model, training code, training method, and deployment.

152
00:15:04.590 --> 00:15:10.590
The project has two main parts, script and source.

153
00:15:10.590 --> 00:15:15.590
The script folder mainly contains utility programs.

154
00:15:15.590 --> 00:15:25.590
It also contains the RSRL folder, which provides code for training, testing, and mode export.

155
00:15:25.590 --> 00:15:31.590
The imitation learning implementation is mainly in the source folder.

156
00:15:31.590 --> 00:15:40.590
Under source, we define an extension package called whole body tracking.

157
00:15:40.590 --> 00:15:51.590
Inside it, we implement the main training logic for training reference motion with the robot.

158
00:15:51.590 --> 00:15:57.590
The access folder contains the robot model files.

159
00:15:57.590 --> 00:16:03.590
The robots folder defines the robot configuration used in simulation.

160
00:16:03.590 --> 00:16:09.590
The tasks folder is the most important part.

161
00:16:09.590 --> 00:16:18.590
It defines the training environment and how the agent interacts with the robot and environment.

162
00:16:18.590 --> 00:16:30.590
It also contains the reward, observation, and termination configurations, which we will introduce later.

163
00:16:30.590 --> 00:16:41.590
The LTS folder contains basic utilities, such as motion data loading and model exporter.

164
00:16:41.590 --> 00:16:45.590
First, let's look at the robots folder.

165
00:16:45.590 --> 00:16:49.590
Open the dr02pro.py.

166
00:16:49.590 --> 00:16:55.590
Here we define the configuration object for the dr02 robot.

167
00:16:55.590 --> 00:17:01.590
We load the urdf file and configure the physical properties.

168
00:17:01.590 --> 00:17:09.590
One important thing, we do not directly use all the joint parameters in the urdf.

169
00:17:09.590 --> 00:17:17.590
Instead, we configure the joint properties again according to the training requirements.

170
00:17:17.590 --> 00:17:33.590
So, if you want to change torque limits, velocity limits, and position limits, stiffness k, damping d, or other joint parameters, change them here, not in the urdf file.

171
00:17:33.590 --> 00:17:43.590
We use randompd-accurator config to define robots joints, implemented in the actuator.py.

172
00:17:43.590 --> 00:17:55.590
One on top of the joint limit, PD gains, and joint delays provided by the delaypd-accurator.

173
00:17:55.590 --> 00:18:07.590
It also adds several types of randomization for PD parameter, peak torque, joint zero offset, and torque speed curve.

174
00:18:07.590 --> 00:18:25.590
The purpose of randomization is to improve the robustness of the trained policy, so the robot can better handle parameter difference on the real hardware.

175
00:18:25.590 --> 00:18:29.590
We use the classic PPO algorithm.

176
00:18:29.590 --> 00:18:33.590
PPO is very powerful, so we do not need to change much here.

177
00:18:33.590 --> 00:18:37.590
So, I will not go into the algorithm details.

178
00:18:37.590 --> 00:18:41.590
We will only cover the parts we need to modify.

179
00:18:41.590 --> 00:18:44.590
First, max iteration.

180
00:18:44.590 --> 00:18:47.590
We set it to 20,000.

181
00:18:47.590 --> 00:18:54.590
For sample motions, around 10,000 iterations may already give good results.

182
00:18:54.590 --> 00:19:00.590
But we usually set a larger number to make sure training is complete.

183
00:19:00.590 --> 00:19:06.590
The needed iterations mainly depend on motion complexity.

184
00:19:06.590 --> 00:19:10.590
Next, save iterative interval.

185
00:19:10.590 --> 00:19:18.590
We set it to 500, so a checkpoint is saved every 500 iterations.

186
00:19:18.590 --> 00:19:27.590
This keeps models from different training stages and makes it easy to resume if something goes wrong.

187
00:19:27.590 --> 00:19:30.590
Then, empirical normalization.

188
00:19:30.590 --> 00:19:36.590
It controls whether the input observations are normalized.

189
00:19:36.590 --> 00:19:42.590
In PPO training, this is usually enabled, so we set it to true.

190
00:19:42.590 --> 00:19:56.590
Next is the PPO network configuration, including the actor and critic structure, hidden layers, and activation function.

191
00:19:56.590 --> 00:19:58.590
By default, we use allure.

192
00:19:58.590 --> 00:20:02.590
You can also try other activation functions.

193
00:20:02.590 --> 00:20:12.590
However, for this task, different activation functions usually do not make a very significant difference.

194
00:20:12.590 --> 00:20:20.590
The remaining parameters mostly use the stand PPO configuration.

195
00:20:20.590 --> 00:20:24.590
In most cases, you do not need to change them.

196
00:20:24.590 --> 00:20:29.590
Next, let's look at the task environment configuration.

197
00:20:29.590 --> 00:20:38.590
If you have used our project to train quadrat robots for velocity tracking, the structure here will look familiar.

198
00:20:38.590 --> 00:20:42.590
Both projects use the RSRL framework.

199
00:20:42.590 --> 00:20:54.590
When where needed, I will compare the two, so the difference between imitation learning and other RL tasks will be easier to understand.

200
00:20:54.590 --> 00:20:58.590
First, the environment configuration program.

201
00:20:58.590 --> 00:21:10.590
The environment is composed of several configuration modules.

202
00:21:10.590 --> 00:21:12.590
First, the same.

203
00:21:12.590 --> 00:21:17.590
By default, we use a flat ground environment, which is the plane.

204
00:21:17.590 --> 00:21:21.590
For friction, we use the multiply combination mode.

205
00:21:21.590 --> 00:21:26.590
Both static and dynamic friction coefficients are 1.

206
00:21:26.590 --> 00:21:33.590
So the final contact friction is mainly determined by the robot fleet.

207
00:21:33.590 --> 00:21:37.590
The robot asset is temporarily set to missing.

208
00:21:37.590 --> 00:21:45.590
We want a general environment independent of a specific robot.

209
00:21:45.590 --> 00:21:52.590
The actual robot model is specified in the other configuration.

210
00:21:52.590 --> 00:21:56.590
We also configuration contact sensors.

211
00:21:56.590 --> 00:22:00.590
They are very useful in motion limitation.

212
00:22:00.590 --> 00:22:06.590
They provide contact information between the robot and the environment.

213
00:22:06.590 --> 00:22:14.590
For example, they tell us whether the feet touch the ground and whether the contact is normal.

214
00:22:14.590 --> 00:22:25.590
This helps reward calculation and also tell us whether the robot has loose balance and whether the episode should end.

215
00:22:25.590 --> 00:22:37.590
We also configure contact related parameters such as history length, air time tracking, and contact detection threshold.

216
00:22:37.590 --> 00:22:42.590
This affects reward calculation and terminal later.

217
00:22:42.590 --> 00:22:46.590
Next, the command configuration.

218
00:22:46.590 --> 00:22:53.590
The command in motion tracking differs greatly from that in velocity tracking.

219
00:22:53.590 --> 00:22:59.590
In velocity tracking, the command is relatively vague.

220
00:22:59.590 --> 00:23:06.590
It only tells the robot which direction to go and how fast.

221
00:23:06.590 --> 00:23:14.590
Usually containing the desired x, y velocities and desired yaw rate.

222
00:23:14.590 --> 00:23:20.590
In imitation learning, in contrast, the command is much more specific.

223
00:23:20.590 --> 00:23:31.590
The robot tracks the changes reference motion states to achieve complete motion expression.

224
00:23:31.590 --> 00:23:42.590
These motion states include not only the joint angles at the current moment but also the joint velocities.

225
00:23:42.590 --> 00:23:52.590
In the motion command class, we also use the joint, anchor, and key body positions and orientations from the reference motion.

226
00:23:52.590 --> 00:23:58.590
The reference data contains every body part of the robot.

227
00:23:58.590 --> 00:24:07.590
Our full model has about 40 rigid bodies but we do not use all of them during training.

228
00:24:07.590 --> 00:24:22.590
Instead, we select only 14 key body parts, mainly the shoulders, elbows, wrists, hips, knees, and anchors.

229
00:24:22.590 --> 00:24:32.590
With the position and orientation of these 14 parts, we can basically determine the robot's pose.

230
00:24:32.590 --> 00:24:37.590
Another important algorithm design in imitation learning.

231
00:24:37.590 --> 00:24:49.590
When initializing the robot, we randomly sample the starring frame from the reference motion.

232
00:24:49.590 --> 00:24:57.590
This is an algorithm design called RSI, reference state initialization.

233
00:24:57.590 --> 00:25:02.590
Implemented in the resample command function in the code.

234
00:25:02.590 --> 00:25:07.590
It is very useful for training complex motions.

235
00:25:07.590 --> 00:25:17.840
If every episode starts from the first frame, the robot has to learn the first half of the motion before that.

236
00:25:17.840 --> 00:25:24.840
Before that, before it can even get a chance to learn the second half.

237
00:25:24.840 --> 00:25:28.840
That is very inefficient.

238
00:25:28.840 --> 00:25:42.840
For example, when robot jumps, if the robot has not learned how to land yet but always start from the beginning of the jump,

239
00:25:42.840 --> 00:25:47.840
it may fall frequently at takeoff or forward landing.

240
00:25:47.840 --> 00:26:03.840
In that case, the policy may learn a simple but warm behavior, such as only waving at its arms without actually completing the jump.

241
00:26:03.840 --> 00:26:15.840
With RSI, the robot can directly learn different phases of the motion, which makes training more efficient.

242
00:26:15.840 --> 00:26:30.840
If a certain segment of motion is particularly difficult for the robot, you can also try increasing the sampling probability of that segment during training.

243
00:26:30.840 --> 00:26:34.840
So that the robot can learn faster.

244
00:26:34.840 --> 00:26:38.380
One more thing to note.

245
00:26:38.380 --> 00:26:47.380
The body order and joint order in the reference data are not the same as in the URDS.

246
00:26:47.380 --> 00:26:56.380
Instead, they follow the order generated after ISAC lab loads the robot.

247
00:26:56.380 --> 00:27:08.380
The general logic is to start from the base link and do a brand first, second, third over the robot structure.

248
00:27:08.380 --> 00:27:22.380
For example, it may first read the left and right hip joints, then the main body, and then the left and right shoulders.

249
00:27:22.380 --> 00:27:40.380
So, when you need to access a specific body or joint in the command during development, it is better to use a name-based index rather than a fixed index.

250
00:27:40.380 --> 00:27:52.380
This avoids data mismatches when the robot structure changes and makes the code easier to understand and maintain.

251
00:27:52.380 --> 00:28:11.380
In addition, we also apply a certain degree of domain randomization to the reference motion data inside the command, which further improves the robustness of the policy.

252
00:28:11.380 --> 00:28:14.380
Next, the action.

253
00:28:14.380 --> 00:28:21.380
In motion tracking, the action is the target joint position output by policy.

254
00:28:21.380 --> 00:28:23.380
They will control the robot.

255
00:28:23.380 --> 00:28:27.380
The action also needs a scale parameter.

256
00:28:27.380 --> 00:28:33.380
This configuration is in the flat environmentconfig.py.

257
00:28:33.380 --> 00:28:41.380
Again, the action order follows the ISAC lab joint order.

258
00:28:41.380 --> 00:28:58.380
So, during deployment, we need a reorder step, converting the simulation joint order into the order required by the real robot control interface.

259
00:28:58.380 --> 00:29:06.380
This ensures each action goes to the correct joint.

260
00:29:06.380 --> 00:29:08.380
Next, the observation.

261
00:29:08.380 --> 00:29:13.380
It has two parts, policy observation and privilege observation.

262
00:29:13.380 --> 00:29:18.380
The policy observation is the input to the actor network.

263
00:29:18.380 --> 00:29:24.380
It represents information we can get during real robot deployment.

264
00:29:24.380 --> 00:29:31.380
The privilege observation is the input to the critic network.

265
00:29:31.380 --> 00:29:37.380
It contains extra information only available during training.

266
00:29:37.380 --> 00:29:40.380
First, the policy observation.

267
00:29:40.380 --> 00:29:53.380
It mainly includes reference motion, base link, gravity, root angular velocity, joint position, joint velocity, and history actions.

268
00:29:53.380 --> 00:29:58.380
The reference motion is very important.

269
00:29:58.380 --> 00:30:09.380
It contains the reference joint position and velocities, which guide the policy toward the target motion.

270
00:30:09.380 --> 00:30:15.380
During training, the policy uses them to know what to do at each moment.

271
00:30:15.380 --> 00:30:26.380
During deployment, we also provide the informed motion so the robot can perform the movement.

272
00:30:26.380 --> 00:30:35.380
The base link gravity is the three-dimensional projection of the gravity direction in the base link frame.

273
00:30:35.380 --> 00:30:41.380
It helps the policy understand the robot's posture.

274
00:30:41.380 --> 00:30:52.380
For example, whether it is tearing or falling, a real robot gets similar information from its IMU.

275
00:30:52.380 --> 00:30:57.380
So this works in both training and deployment.

276
00:30:57.380 --> 00:31:13.380
During training, we also use noise to it, making the input more like real sentence measurement and improving deployment robustness.

277
00:31:13.380 --> 00:31:20.380
The history actions are the actions from previous time steps.

278
00:31:20.380 --> 00:31:29.380
They help the policy understand its recent motion trend and improve smoothness.

279
00:31:29.380 --> 00:31:31.380
Now, the privilege observation.

280
00:31:31.380 --> 00:31:41.380
Besides what we mentioned, it also contains the position and orientation of anchors and other bodies, plus the linear velocity of base link.

281
00:31:41.380 --> 00:31:51.380
These values are hard to get on the real robot, but they help the critic evaluate the current state.

282
00:31:51.380 --> 00:31:59.380
By giving the actor and critic different information, we improve training efficiency.

283
00:31:59.380 --> 00:32:08.380
At the same time, the policy does not depend on information the real robot cannot get during deployment.

284
00:32:08.380 --> 00:32:18.380
If you compare this code with the velocity tracking code, you will see a difference.

285
00:32:18.380 --> 00:32:23.380
For velocity tracking, the robot needs to keep walking or running.

286
00:32:23.380 --> 00:32:33.380
So, the observation usually contains gain phase, foot height, air time, and contact state.

287
00:32:33.380 --> 00:32:37.380
This helps the robot understand its walking state.

288
00:32:37.380 --> 00:32:44.380
For imitation learning, the privileged observation in sand contains bird-dee pose.

289
00:32:44.380 --> 00:32:51.380
This gives more accurate information for learning a new motion.

290
00:32:51.380 --> 00:32:54.380
And then, the event configuration.

291
00:32:54.380 --> 00:32:59.380
Events are mainly used for domain randomization during training.

292
00:32:59.380 --> 00:33:09.380
In the real world, the robots are affected by cables, assembles, errors, and different between components.

293
00:33:09.380 --> 00:33:15.380
So, the physical parameters of each robot may differ slightly.

294
00:33:15.380 --> 00:33:31.380
If we train with only one fixed set of parameters, the policy may become too specialized to simulation, causing a large performance gap on the real world.

295
00:33:31.380 --> 00:33:43.380
So, we often use domain randomization in reinforcement learning to make the robots more robust to different physical conditions.

296
00:33:43.380 --> 00:33:47.380
Here, we configure five types of events.

297
00:33:47.380 --> 00:33:52.380
The first four is the startup model.

298
00:33:52.380 --> 00:33:57.380
Means they are applying when each episode starts.

299
00:33:57.380 --> 00:34:14.380
We randomly change the friction coefficient, restitution coefficient, default joint positions, robot mass, and sand of mass positions within range.

300
00:34:14.380 --> 00:34:21.380
These are physical parameters that can significantly affect real-world motion.

301
00:34:21.380 --> 00:34:27.010
The large event uses the interval mode.

302
00:34:27.010 --> 00:34:45.010
The robot receives random external push during the episode, simulating disturbance such as collisions or unexpected bumps.

303
00:34:45.010 --> 00:34:50.010
Together with the observation noise.

304
00:34:50.010 --> 00:35:00.010
This randomization makes training close to the real robot and improves the robustness of the final policy.

305
00:35:00.010 --> 00:35:02.010
Next, rewards.

306
00:35:02.010 --> 00:35:08.010
In reinforcement learning, the reward quality finds the behavior we want.

307
00:35:08.010 --> 00:35:17.010
If it is well decided, the robot's behavior moves close to the target as training progresses.

308
00:35:17.010 --> 00:35:26.010
For imitation learning, rewards fall into two categories, tracking rewards and constraint rewards.

309
00:35:26.010 --> 00:35:30.010
Tracking rewards relate to motion tracking.

310
00:35:30.010 --> 00:35:45.010
They include tracking the center of mass or anchor position and orientation, tracking key body position and orientation, and their linear and angular velocity.

311
00:35:45.010 --> 00:35:52.010
The goal is to follow the reference motion as closely as possible.

312
00:35:52.010 --> 00:36:02.010
If all important body parts track the reference well throughout the motion, we consider the motion learned.

313
00:36:02.010 --> 00:36:11.010
But in practice, overall tracking reward alone may not always work well.

314
00:36:11.010 --> 00:36:21.010
If we only measure overall body tracking error, the vertical wall error of the feet may be small.

315
00:36:21.010 --> 00:36:26.010
So the policy may not pay enough attention to lifting the feet.

316
00:36:26.010 --> 00:36:34.010
The motion may look mostly right, but the feet never right lift the ground and simply slide.

317
00:36:34.010 --> 00:36:39.010
So for important motion features, we add extra rewards.

318
00:36:39.010 --> 00:36:49.010
For example, a foot-high tracking reward makes the policy pay more attention to foot-high and improve leg motion.

319
00:36:49.010 --> 00:36:55.010
Besides tracking rewards, we have constraint rewards.

320
00:36:55.010 --> 00:37:10.010
They usually have negative weight and penalize unwanted behaviors, such as exceeding joint position limit, exceeding torque limit, or self-collision.

321
00:37:10.010 --> 00:37:20.010
These constraints let the policy complete the target motion while satisfying the robot physical limit.

322
00:37:20.010 --> 00:37:31.010
In general, if the reference motion is simple or have good quality, imitation learning needs fewer rewards than velocity tracking.

323
00:37:31.010 --> 00:37:36.010
A good reference already provides strong guidance.

324
00:37:36.010 --> 00:37:49.010
If the motion is difficult or the reference is not very good, we may add more specific reward function to guide or constrain certain parts.

325
00:37:49.010 --> 00:37:52.010
Next, termination.

326
00:37:52.010 --> 00:37:56.010
Termination defines when an episode ends during training.

327
00:37:56.010 --> 00:38:06.010
In general, when the current state can no longer provide useful training data, we end the episode early.

328
00:38:06.010 --> 00:38:12.010
The first case is when the episode time limit is reached.

329
00:38:12.010 --> 00:38:15.010
Each episode has a maximum duration.

330
00:38:15.010 --> 00:38:25.010
When the simulation steps can't reach this limit, the episode ends regardless of the robot's current state.

331
00:38:25.010 --> 00:38:34.010
The second case is when the robot state has deviated too far from the target.

332
00:38:34.010 --> 00:38:42.010
For example, the robot's center of mass may move too far from the reference position.

333
00:38:42.010 --> 00:38:46.010
Its posture may also become abnormal.

334
00:38:46.010 --> 00:38:51.010
Or the feet may move too far away from their reference position.

335
00:38:51.010 --> 00:39:00.010
This indicates that the robot may lose balance or is about to fall.

336
00:39:00.010 --> 00:39:08.010
Since data from such states is usually not useful, we terminate the episode early.

337
00:39:08.010 --> 00:39:16.010
Termination for imitation learning is usually stricter than for velocity training.

338
00:39:16.010 --> 00:39:21.010
Early termination acts as extra supervision.

339
00:39:21.010 --> 00:39:34.010
It keeps the training data concentrated in valid motion widgets and prevents the policy from drifting too far from the reference.

340
00:39:34.010 --> 00:39:47.010
Once important point, once early termination triggers, all remaining rewards in the episode are set to zero.

341
00:39:47.010 --> 00:39:51.010
In some cases, we also use curriculum learning.

342
00:39:51.010 --> 00:40:01.010
For complex motion, it lets the robot move gradually from an easier version of the task to complete motion.

343
00:40:01.010 --> 00:40:09.010
For example, we first reduce the difficulty and let the robot learn the basic motion patterns.

344
00:40:09.010 --> 00:40:16.010
Then, we gradually increase the requirements until the robot platform the complex motion.

345
00:40:16.010 --> 00:40:20.010
This is very useful for difficult movements.

346
00:40:20.010 --> 00:40:29.010
But for most motions, if the reward is well decided and the reference has good quality,

347
00:40:29.010 --> 00:40:33.010
we can usually train a good policy directly.

348
00:40:33.010 --> 00:40:38.010
So, curriculum is not required for every task.

349
00:40:38.010 --> 00:40:43.010
After retargeting, we can get a .pkl file.

350
00:40:43.010 --> 00:40:52.010
Its meaning contains the two robots drawing and anchor motion data and is not enough for imitation learning.

351
00:40:52.010 --> 00:41:04.010
During training, we also need the relative position and orientation of each body with respect to the anchor.

352
00:41:04.010 --> 00:41:13.010
So, we compute them with World Kinematics or FK and save them into the data file in ADVICE.

353
00:41:13.010 --> 00:41:23.010
This avoids repeated FK computation during training and improves efficiency.

354
00:41:23.010 --> 00:41:29.010
After pre-processing, we can start training.

355
00:41:29.010 --> 00:41:33.010
We provide a training program with automatic recovery.

356
00:41:33.010 --> 00:41:43.010
If training runs long and is interrupted by norm values or other errors, this program will start automatically.

357
00:41:43.010 --> 00:41:49.010
This is very useful for humanoid training, which often takes a long time.

358
00:41:49.010 --> 00:41:59.150
During training, we can adjust settings by modifying the configuration parameters.

359
00:41:59.150 --> 00:42:08.150
We can also use TensorBoard to view reward and episode length, which makes monitoring easier.

360
00:42:08.150 --> 00:42:12.150
Finally, let's talk about policy export and deployment.

361
00:42:12.150 --> 00:42:22.150
After training, we use export onnix fast.py to export the policy as an onnix model.

362
00:42:22.150 --> 00:42:34.150
If you are using our deep robotics SDK 2 for deployment, place the training motion data in the state machine's motion data folder,

363
00:42:34.150 --> 00:42:39.150
and the policy file in the policy folder.

364
00:42:39.150 --> 00:42:51.150
We also need to modify the path configuration in MimicPolicyRunner.hpp under the RunPolicy folder.

365
00:42:51.150 --> 00:42:58.150
This ensures the program loads the motion data and policy correctly.

366
00:42:58.150 --> 00:43:07.150
After this step, we can run the trained imitation policy on simulation or on real robot.

367
00:43:07.150 --> 00:43:25.130
That is all for this video.

368
00:43:25.130 --> 00:43:37.130
We introduce the complete imitation learning pipeline of the DR-02 robot in two parts, motion retargeting and imitation learning training.

369
00:43:37.130 --> 00:43:44.130
Of course, with limited video time, it is impossible to cover every detail.

370
00:43:44.130 --> 00:43:51.130
Both projects are open source, and the GitHub links are in the video description.

371
00:43:51.130 --> 00:44:03.130
You are welcome to ask questions and discuss on GitHub, and you are welcome to download the code and explore more interesting humanoid robot applications.

372
00:44:03.130 --> 00:44:05.130
Thank you for your watching.
