31 struct sched_param walk_control_thread_sched;
34 int retval = pthread_setschedparam(
35 walk_control_thread.native_handle(),
37 &walk_control_thread_sched);
41 ORUW_LOG_MESSAGE(
"Cannot change the priority of the walk control thread: %s\n", strerror(retval));
44 walk_control_thread.detach();
48 halt(
"Failed to spawn the walk control thread.\n", __FUNCTION__);
57 getParentBroker()->getProxy(
"DCM")->getModule()->atPostProcess
60 catch (
const ALError &e)
63 halt(
"Callback registration failed!", __FUNCTION__);
74 vector<float> sensorValues;
77 for (
int i = 0; i < JOINTS_NUM; i++)
79 joint_state.q[i] = sensorValues[i];
87 joint_state.q[R_HIP_YAW_PITCH] = joint_state.q[L_HIP_YAW_PITCH];
117 Transform<double,3> swing_foot_posture;
118 nao.getSwingFootPosture (
nao.state_sensor, swing_foot_posture.data());
135 solver =
new smpc::solver_as (
148 solver =
new smpc::solver_ip (
208 nao.getCoM (
nao.state_sensor,
nao.CoM_position);
210 mpc.init_state.set (
nao.CoM_position[0],
nao.CoM_position[1]);
213 jointState target_joint_state =
nao.state_model;
235 if (wmg.isSupportSwitchNeeded())
238 nao.switchSupportFoot();
242 solver->get_state(CoM, 0);
244 target_joint_state =
nao.state_model;
245 solver->get_state(CoM, 1);
255 halt(
"Time limit is violated!\n", __FUNCTION__);
279 const smpc_parameters &mpc,
280 const smpc::state_com &CoM,
281 const int control_loop_num,
285 nao.setCoM(CoM.x(), CoM.y(), mpc.hCoM);
289 wmg.getFeetPositions (
291 nao.left_foot_posture.data(),
292 nao.right_foot_posture.data());
296 int iter_num =
nao.igm (
304 halt(
"IK does not converge.\n", __FUNCTION__);
306 int failed_joint =
nao.state_model.checkJointBounds();
307 if (failed_joint >= 0)
310 halt(
"Joint bounds are violated.\n", __FUNCTION__);
318 for (
int i = 0; i < LOWER_JOINTS_NUM; i++)
324 catch (
const AL::ALError &e)
327 halt(
"Cannot set joint angles!", __FUNCTION__);
340 nao.getCoM (
nao.state_sensor,
nao.CoM_position);
343 smpc::state_com state_error;
345 init_state.x() -
nao.CoM_position[0],
346 init_state.y() -
nao.CoM_position[1]);
358 state_error.x() = 0.0;
371 state_error.y() = 0.0;
390 smpc_parameters &mpc)
394 if (wmg.formPreviewWindow(mpc) == WMG_HALT)
396 stopWalking(
"Not enough steps to form preview window. Stopping.");
401 solver->set_parameters (mpc.T, mpc.h, mpc.h[0], mpc.angle, mpc.zref_x, mpc.zref_y, mpc.lb, mpc.ub);
402 solver->form_init_fp (mpc.fp_x, mpc.fp_y, mpc.init_state, mpc.X);
404 solver->get_next_state(mpc.init_state);
411 halt(
"Time limit is violated!\n", __FUNCTION__);
429 qiLogInfo (
"module.oru_walk") << message;
445 throw ALERROR(getName(),
function, message);
void setStiffness(const float &)
Set stiffness of joints.
void dcmCallback()
Wake up walk control thread periodically.
double mpc_ip_tolerance_ext
bool solveMPCProblem(WMG &, smpc_parameters &)
Solve the MPC problem.
void walk()
Construct and initialize all necessary classes and register callback function.
double mpc_gain_acceleration
Log time of existance on destruction. Throw an error, if the given upper limit is not satisfied.
void walkControl()
A control loop, that is executed in separate thread.
void readParameters()
Read parameters from configuration file; if the file does not exist, write the default values to it.
bool check()
Checks if the limit is satisfied, logs a message.
int walk_control_thread_priority
void initWalkPattern(WMG &)
Initialize selected walk pattern.
void halt(const char *, const char *)
Log a message, remove stiffness and die.
ALPtr< DCMProxy > dcm_proxy
double ref_joint_angles[LOWER_JOINTS_NUM]
int preview_sampling_time_ms
void correctNextSupportPosition(WMG &)
The position of the next support foot may change from the targeted, this function moves it to the rig...
void stopWalkingRemote()
An interface function that is called remotely to stop the execution.
void solveIKsendCommands(const smpc_parameters &, const smpc::state_com &, const int, WMG &)
Solve inverse kinematics and send commands to the controllers.
int * last_dcm_time_ms_ptr
double mpc_ip_tolerance_int
boost::condition_variable walk_control_condition
bool set_support_z_to_zero
#define ORUW_LOG_JOINTS(sensors, actuators)
void reset()
Reset timer to the current time.
ProcessSignalConnection dcm_callback_connection
double bezier_inclination_1
void readSensors(jointState &)
Update joint angles.
ALPtr< ALMemoryFastAccess > access_sensor_values
#define ORUW_LOG_COM(mpc, nao)
void feedbackError(smpc::state_com &)
Correct state and the model based on the sensor data.
void initSolver()
Initialize solver.
boost::mutex walk_control_mutex
#define ORUW_LOG_SOLVER_INFO
void stopWalking(const char *)
Unregister callback and log a message.
#define ORUW_LOG_STEPS(wmg)
#define ORUW_LOG_MESSAGE(...)
double bezier_inclination_2
int control_sampling_time_ms
#define ORUW_LOG_FEET(nao)
double feedback_threshold