A sparse MPC solver for walking motion generation.
walk_parameters.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @author Alexander Sherikov
4  */
5 
6 #include "walk_parameters.h"
7 #include "smpc_solver.h"
8 
9 
10 
11 /**
12  * @brief Initialize parameters to default values.
13  *
14  * @param[in] broker parent broker.
15  */
16 walkParameters::walkParameters(ALPtr<ALBroker> broker) :
17  pref_proxy(broker)
18 {
19 // CoM position feedback
20  /**
21  * @ref AldNaoPaper "0.5 in the publication by Aldebaran-Robotics"
22  */
23  feedback_gain = 0.3;
24  /**
25  * @ref AldNaoPaper "0.003 in the publication by Aldebaran-Robotics"
26  * Note, that even though they derive the value of this parameter in
27  * the paper, we simply tuned it.
28  */
29  feedback_threshold = 0.004;
30 
31 
32 // parameters of the MPC solver
34 
35  mpc_gain_position = 8000.0; // closeness to the reference ZMP points
36  mpc_gain_acceleration = 0.02; // penalty for the acceleration
37  mpc_gain_velocity = 1.0; // penalty for the velocity
38  mpc_gain_jerk = 1.0; // penalty for the jerk
39 
40  mpc_as_tolerance = 1e-7;
42  mpc_as_use_downdate = true;
43 
44  mpc_ip_tolerance_int = 1e-1;
45  mpc_ip_tolerance_ext = 1e+4;
46  mpc_ip_t = 1e-1;
47  mpc_ip_mu = 1.0;
48  mpc_ip_bs_alpha = 0.01;
49  mpc_ip_bs_beta = 0.9;
50  mpc_ip_max_iter = 5;
51  mpc_ip_bs_type = smpc::SMPC_IP_BS_LOGBAR;
52 
53 
54 // parameters of the walking pattern generator
58 
59  ss_time_ms = 400;
60  ds_time_ms = 40;
61  ds_number = 3;
63 
64 
65 // parameters of the steps
66  /**
67  * @ref AldNaoPaper "0.015 in the publication by Aldebaran-Robotics"
68  * 0.02 is used in the built-in module, but is is slightly higher when
69  * executed on the robot.
70  */
71  step_height = 0.02;
72 
73  // The longest step in the built-in module.
74  step_length = 0.04;
75 
76  // Refer to smpc_solver/include/WMG.h for the description of these parameters.
77  bezier_weight_1 = 1.5;
78  bezier_weight_2 = 3.0;
79  bezier_inclination_1 = 0.015;
80  bezier_inclination_2 = 0.01;
81 
82  // assume that z coordinate of a foot after position correction is 0.0
83  set_support_z_to_zero = true;
84 
85 
86 // parameters of the control thread
87  /*
88  * Accordingly to the NAOqi documentation
89  * @verbatim
90  Only DCM has a real-time thread in NAOqi. ::
91  scheduling policy: SCHED_FIFO
92  scheduling priority: 90
93  @endverbatim
94  * Cannot set priority >= 70.
95  */
96  walk_control_thread_priority = 65; // constant
97 
99  dcm_sampling_time_ms = 10; // constant
100 
101  control_sampling_time_ms = 20; // constant
103 
104  loop_time_limit_ms = 15; // less than control_sampling_time_ms
105 
106 
108 
109 
110 // IGM
111  // Acc. to the reference: "32 x Hall effect sensors. 12 bit precision, ie 4096 values per turn"
112  // i.e. 3.14*2/4096 = 0.0015 radian is the lowest detectable change in a joint angle.
113  igm_tol = 0.0015;
114  igm_max_iter = 20;
115  igm_mu = 1.0;
116 
117 
118 
119 // list of parameters, that are stored in config file:
120  param_names.arraySetSize(NUM_PARAMETERS);
121 
122  param_names[FEEDBACK_GAIN] = "feedback_gain";
123  param_names[FEEDBACK_THRESHOLD] = "feedback_threshold";
124 
125  param_names[MPC_SOLVER_TYPE] = "mpc_solver_type";
126 
127  param_names[MPC_GAIN_VELOCITY] = "mpc_gain_velocity";
128  param_names[MPC_GAIN_POSITION] = "mpc_gain_position";
129  param_names[MPC_GAIN_JERK] = "mpc_gain_jerk";
130  param_names[MPC_GAIN_ACCELERATION] = "mpc_gain_acceleration";
131 
132  param_names[MPC_AS_TOLERANCE] = "mpc_as_tolerance";
133  param_names[MPC_AS_MAX_ACTIVATE] = "mpc_as_max_activate";
134  param_names[MPC_AS_USE_DOWNDATE] = "mpc_as_use_downdate";
135 
136  param_names[MPC_IP_TOLERANCE_INT] = "mpc_ip_tolerance_int";
137  param_names[MPC_IP_TOLERANCE_EXT] = "mpc_ip_tolerance_ext";
138  param_names[MPC_IP_T] = "mpc_ip_t";
139  param_names[MPC_IP_MU] = "mpc_ip_mu";
140  param_names[MPC_IP_BS_ALPHA] = "mpc_ip_bs_alpha";
141  param_names[MPC_IP_BS_BETA] = "mpc_ip_bs_beta";
142  param_names[MPC_IP_MAX_ITER] = "mpc_ip_max_iter";
143  param_names[MPC_IP_BS_TYPE] = "mpc_ip_bs_type";
144 
145  param_names[IGM_MU] = "igm_mu";
146 
147  param_names[STEP_HEIGHT] = "step_height";
148  param_names[STEP_LENGTH] = "step_length";
149  param_names[BEZIER_WEIGHT_1] = "bezier_weight_1";
150  param_names[BEZIER_WEIGHT_2] = "bezier_weight_2";
151  param_names[BEZIER_INCLINATION_1] = "bezier_inclination_1";
152  param_names[BEZIER_INCLINATION_2] = "bezier_inclination_2";
153 
154  param_names[LOOP_TIME_LIMIT_MS] = "loop_time_limit_ms";
155  param_names[DCM_TIME_SHIFT_MS] = "dcm_time_shift_ms";
156  param_names[PREVIEW_SAMPLING_TIME_MS] = "preview_sampling_time_ms";
157  param_names[PREVIEW_WINDOW_SIZE] = "preview_window_size";
158 
159  param_names[SS_CONTROL_LOOPS] = "ss_control_loops";
160  param_names[DS_CONTROL_LOOPS] = "ds_control_loops";
161  param_names[DS_NUMBER] = "ds_number";
162  param_names[STEP_PAIRS_NUMBER] = "step_pairs_number";
163 
164  param_names[WALK_PATTERN] = "walk_pattern";
165 }
166 
167 
168 
169 /**
170  * @brief Read parameters from configuration file; if the file does
171  * not exist, write the default values to it.
172  */
174 {
175  ALValue preferences;
176 
177  try
178  {
179  preferences = pref_proxy.readPrefFile ("oru_walk", false);
180  }
181  catch (const ALError &e)
182  {
183  qiLogInfo ("module.oru_walk") << e.what();
184  writeParameters ();
185  return;
186  }
187 
188 
189  if (!preferences.isArray())
190  {
191  return;
192  }
193 
194  for (int i = 0; i < preferences.getSize(); i++)
195  {
196  if (preferences[i][2].isFloat())
197  {
198  if(preferences[i][0] == param_names[FEEDBACK_GAIN]) { feedback_gain = preferences[i][2]; }
199  if(preferences[i][0] == param_names[FEEDBACK_THRESHOLD]) { feedback_threshold = preferences[i][2]; }
200  if(preferences[i][0] == param_names[MPC_GAIN_POSITION]) { mpc_gain_position = preferences[i][2]; }
201  if(preferences[i][0] == param_names[MPC_GAIN_VELOCITY]) { mpc_gain_velocity = preferences[i][2]; }
202  if(preferences[i][0] == param_names[MPC_GAIN_ACCELERATION]) { mpc_gain_acceleration= preferences[i][2]; }
203  if(preferences[i][0] == param_names[MPC_GAIN_JERK]) { mpc_gain_jerk = preferences[i][2]; }
204  if(preferences[i][0] == param_names[MPC_AS_TOLERANCE]) { mpc_as_tolerance = preferences[i][2]; }
205  if(preferences[i][0] == param_names[MPC_IP_TOLERANCE_INT]) { mpc_ip_tolerance_int = preferences[i][2]; }
206  if(preferences[i][0] == param_names[MPC_IP_TOLERANCE_EXT]) { mpc_ip_tolerance_ext = preferences[i][2]; }
207  if(preferences[i][0] == param_names[MPC_IP_T]) { mpc_ip_t = preferences[i][2]; }
208  if(preferences[i][0] == param_names[MPC_IP_MU]) { mpc_ip_mu = preferences[i][2]; }
209  if(preferences[i][0] == param_names[MPC_IP_BS_ALPHA]) { mpc_ip_bs_alpha = preferences[i][2]; }
210  if(preferences[i][0] == param_names[MPC_IP_BS_BETA]) { mpc_ip_bs_beta = preferences[i][2]; }
211  if(preferences[i][0] == param_names[IGM_MU]) { igm_mu = preferences[i][2]; }
212  if(preferences[i][0] == param_names[STEP_HEIGHT]) { step_height = preferences[i][2]; }
213  if(preferences[i][0] == param_names[STEP_LENGTH]) { step_length = preferences[i][2]; }
214  if(preferences[i][0] == param_names[BEZIER_WEIGHT_1]) { bezier_weight_1 = preferences[i][2]; }
215  if(preferences[i][0] == param_names[BEZIER_WEIGHT_2]) { bezier_weight_2 = preferences[i][2]; }
216  if(preferences[i][0] == param_names[BEZIER_INCLINATION_1]) { bezier_inclination_1 = preferences[i][2]; }
217  if(preferences[i][0] == param_names[BEZIER_INCLINATION_2]) { bezier_inclination_2 = preferences[i][2]; }
218  }
219  if (preferences[i][2].isInt())
220  {
221  if(preferences[i][0] == param_names[MPC_SOLVER_TYPE]) { mpc_solver_type = preferences[i][2]; }
222  if(preferences[i][0] == param_names[MPC_IP_MAX_ITER]) { mpc_ip_max_iter = preferences[i][2]; }
223  if(preferences[i][0] == param_names[MPC_IP_BS_TYPE]) { mpc_ip_bs_type = preferences[i][2]; }
224  if(preferences[i][0] == param_names[MPC_AS_MAX_ACTIVATE]) { mpc_as_max_activate = preferences[i][2]; }
225 
226  if(preferences[i][0] == param_names[LOOP_TIME_LIMIT_MS]) { loop_time_limit_ms = preferences[i][2]; }
227  if(preferences[i][0] == param_names[DCM_TIME_SHIFT_MS]) { dcm_time_shift_ms = preferences[i][2]; }
228  if(preferences[i][0] == param_names[PREVIEW_WINDOW_SIZE]) { preview_window_size = preferences[i][2]; }
229  if(preferences[i][0] == param_names[DS_NUMBER]) { ds_number = preferences[i][2]; }
230  if(preferences[i][0] == param_names[STEP_PAIRS_NUMBER]) { step_pairs_number = preferences[i][2]; }
231  if(preferences[i][0] == param_names[WALK_PATTERN]) { walk_pattern = preferences[i][2]; }
232 
233 
234  if(preferences[i][0] == param_names[PREVIEW_SAMPLING_TIME_MS])
235  {
236  preview_sampling_time_ms = preferences[i][2];
238  }
239 
240  if (preferences[i][0] == param_names[SS_CONTROL_LOOPS])
241  {ss_time_ms = control_sampling_time_ms * (int) preferences[i][2];}
242 
243  if(preferences[i][0] == param_names[DS_CONTROL_LOOPS])
244  {ds_time_ms = control_sampling_time_ms * (int) preferences[i][2];}
245  }
246  if (preferences[i][2].isBool())
247  {
248  if(preferences[i][0] == param_names[MPC_AS_USE_DOWNDATE]) { mpc_as_use_downdate = preferences[i][2]; }
249  }
250  }
251 }
252 
253 
254 
255 /**
256  * @brief Write the values of parameters to the config file.
257  */
259 {
260  ALValue preferences;
261 
262  preferences.arraySetSize(NUM_PARAMETERS);
263  for (int i = 0; i < NUM_PARAMETERS; i++)
264  {
265  preferences[i].arraySetSize(3);
266  preferences[i][0] = param_names[i];
267  }
268 
269 
270  // descriptions
271  preferences[FEEDBACK_GAIN][1] = "";
272  preferences[FEEDBACK_THRESHOLD][1] = "";
273 
274  preferences[MPC_SOLVER_TYPE][1] = "";
275 
276  preferences[MPC_GAIN_POSITION][1] = "";
277  preferences[MPC_GAIN_VELOCITY][1] = "";
278  preferences[MPC_GAIN_ACCELERATION][1] = "";
279  preferences[MPC_GAIN_JERK][1] = "";
280 
281  preferences[MPC_AS_TOLERANCE][1] = "";
282  preferences[MPC_AS_MAX_ACTIVATE][1] = "";
283  preferences[MPC_AS_USE_DOWNDATE][1] = "";
284 
285  preferences[MPC_IP_TOLERANCE_INT][1] = "";
286  preferences[MPC_IP_TOLERANCE_EXT][1] = "";
287  preferences[MPC_IP_T][1] = "";
288  preferences[MPC_IP_MU][1] = "";
289  preferences[MPC_IP_BS_ALPHA][1] = "";
290  preferences[MPC_IP_BS_BETA][1] = "";
291  preferences[MPC_IP_MAX_ITER][1] = "";
292  preferences[MPC_IP_BS_TYPE][1] = "";
293 
294  preferences[IGM_MU][1] = "";
295 
296  preferences[STEP_HEIGHT][1] = "";
297  preferences[STEP_LENGTH][1] = "";
298  preferences[BEZIER_WEIGHT_1][1] = "";
299  preferences[BEZIER_WEIGHT_2][1] = "";
300  preferences[BEZIER_INCLINATION_1][1] = "";
301  preferences[BEZIER_INCLINATION_2][1] = "";
302 
303  preferences[LOOP_TIME_LIMIT_MS][1] = "";
304  preferences[DCM_TIME_SHIFT_MS][1] = "";
305  preferences[PREVIEW_SAMPLING_TIME_MS][1] = "";
306  preferences[PREVIEW_WINDOW_SIZE][1] = "";
307 
308  preferences[SS_CONTROL_LOOPS][1] = "";
309  preferences[DS_CONTROL_LOOPS][1] = "";
310  preferences[DS_NUMBER][1] = "";
311  preferences[STEP_PAIRS_NUMBER][1] = "";
312 
313  preferences[WALK_PATTERN][1] = "";
314 
315 
316  // values
317  preferences[FEEDBACK_GAIN][2] = feedback_gain;
318  preferences[FEEDBACK_THRESHOLD][2] = feedback_threshold;
319 
320  preferences[MPC_SOLVER_TYPE][2] = mpc_solver_type;
321 
322  preferences[MPC_GAIN_POSITION][2] = mpc_gain_position;
323  preferences[MPC_GAIN_VELOCITY][2] = mpc_gain_velocity;
325  preferences[MPC_GAIN_JERK][2] = mpc_gain_jerk;
326 
327  preferences[MPC_AS_TOLERANCE][2] = mpc_as_tolerance;
328  preferences[MPC_AS_MAX_ACTIVATE][2] = mpc_as_max_activate;
329  preferences[MPC_AS_USE_DOWNDATE][2] = mpc_as_use_downdate;
330 
331  preferences[MPC_IP_TOLERANCE_INT][2] = mpc_ip_tolerance_int;
332  preferences[MPC_IP_TOLERANCE_EXT][2] = mpc_ip_tolerance_ext;
333  preferences[MPC_IP_T][2] = mpc_ip_t;
334  preferences[MPC_IP_MU][2] = mpc_ip_mu;
335  preferences[MPC_IP_BS_ALPHA][2] = mpc_ip_bs_alpha;
336  preferences[MPC_IP_BS_BETA][2] = mpc_ip_bs_beta;
337  preferences[MPC_IP_MAX_ITER][2] = mpc_ip_max_iter;
338  preferences[MPC_IP_BS_TYPE][2] = mpc_ip_bs_type;
339 
340  preferences[IGM_MU][2] = igm_mu;
341 
342  preferences[STEP_HEIGHT][2] = step_height;
343  preferences[STEP_LENGTH][2] = step_length;
344  preferences[BEZIER_WEIGHT_1][2] = bezier_weight_1;
345  preferences[BEZIER_WEIGHT_2][2] = bezier_weight_2;
346  preferences[BEZIER_INCLINATION_1][2] = bezier_inclination_1;
347  preferences[BEZIER_INCLINATION_2][2] = bezier_inclination_2;
348 
349  preferences[LOOP_TIME_LIMIT_MS][2] = loop_time_limit_ms;
350  preferences[DCM_TIME_SHIFT_MS][2] = dcm_time_shift_ms;
352  preferences[PREVIEW_WINDOW_SIZE][2] = preview_window_size;
353 
356  preferences[DS_NUMBER][2] = ds_number;
357  preferences[STEP_PAIRS_NUMBER][2] = step_pairs_number;
358 
359  preferences[WALK_PATTERN][2] = walk_pattern;
360 
361  try
362  {
363  pref_proxy.writePrefFile("oru_walk", preferences, true);
364  }
365  catch (const ALError &e)
366  {
367  qiLogInfo ("module.oru_walk") << e.what();
368  }
369 }
double mpc_ip_tolerance_ext
double control_sampling_time_sec
double mpc_gain_acceleration
double mpc_gain_position
void readParameters()
Read parameters from configuration file; if the file does not exist, write the default values to it.
int walk_control_thread_priority
double mpc_gain_velocity
void writeParameters()
Write the values of parameters to the config file.
double mpc_ip_tolerance_int
double bezier_inclination_1
ALPreferencesProxy pref_proxy
double preview_sampling_time_sec
double bezier_inclination_2
double feedback_threshold
walkParameters(ALPtr< ALBroker >)
Initialize parameters to default values.