Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug when overwriting footstep #940

Merged
merged 3 commits into from
Jan 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions rtc/AutoBalancer/GaitGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,18 +540,7 @@ namespace rats

bool gait_generator::proc_one_tick ()
{
hrp::Vector3 rzmp;
std::vector<hrp::Vector3> sfzos;
bool refzmp_exist_p = rg.get_current_refzmp(rzmp, sfzos, default_double_support_ratio_before, default_double_support_ratio_after, default_double_support_static_ratio_before, default_double_support_static_ratio_after);
if (!refzmp_exist_p) {
finalize_count++;
rzmp = prev_que_rzmp;
sfzos = prev_que_sfzos;
} else {
prev_que_rzmp = rzmp;
prev_que_sfzos = sfzos;
}
bool solved = preview_controller_ptr->update(refzmp, cog, swing_foot_zmp_offsets, rzmp, sfzos, (refzmp_exist_p || finalize_count < preview_controller_ptr->get_delay()-default_step_time/dt));
solved = false;
/* update refzmp */
if (emergency_flg == EMERGENCY_STOP && lcg.get_footstep_index() > 0) {
leg_type cur_leg = footstep_nodes_list[lcg.get_footstep_index()].front().l_r;
Expand Down Expand Up @@ -589,6 +578,22 @@ namespace rats
overwrite_footstep_nodes_list.clear();
}
}

if ( !solved ) {
hrp::Vector3 rzmp;
std::vector<hrp::Vector3> sfzos;
bool refzmp_exist_p = rg.get_current_refzmp(rzmp, sfzos, default_double_support_ratio_before, default_double_support_ratio_after, default_double_support_static_ratio_before, default_double_support_static_ratio_after);
if (!refzmp_exist_p) {
finalize_count++;
rzmp = prev_que_rzmp;
sfzos = prev_que_sfzos;
} else {
prev_que_rzmp = rzmp;
prev_que_sfzos = sfzos;
}
solved = preview_controller_ptr->update(refzmp, cog, swing_foot_zmp_offsets, rzmp, sfzos, (refzmp_exist_p || finalize_count < preview_controller_ptr->get_delay()-default_step_time/dt));
}

rg.update_refzmp(footstep_nodes_list);
// { // debug
// double cart_zmp[3];
Expand Down Expand Up @@ -877,11 +882,10 @@ namespace rats
}
/* fill preview controller queue by new refzmp */
hrp::Vector3 rzmp;
bool not_solved = true;
while (not_solved) {
while ( !solved ) {
std::vector<hrp::Vector3> sfzos;
bool refzmp_exist_p = rg.get_current_refzmp(rzmp, sfzos, default_double_support_ratio_before, default_double_support_ratio_after, default_double_support_static_ratio_before, default_double_support_static_ratio_after);
not_solved = !preview_controller_ptr->update(refzmp, cog, swing_foot_zmp_offsets, rzmp, sfzos, refzmp_exist_p);
solved = preview_controller_ptr->update(refzmp, cog, swing_foot_zmp_offsets, rzmp, sfzos, refzmp_exist_p);
rg.update_refzmp(footstep_nodes_list);
}
};
Expand Down
1 change: 1 addition & 0 deletions rtc/AutoBalancer/GaitGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ namespace rats
bool use_inside_step_limitation;
std::map<leg_type, std::string> leg_type_map;
coordinates initial_foot_mid_coords;
bool solved;

/* preview controller parameters */
//preview_dynamics_filter<preview_control>* preview_controller_ptr;
Expand Down
43 changes: 42 additions & 1 deletion sample/SampleRobot/samplerobot_auto_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,39 @@ def checkGoPosParam (goalx, goaly, goalth, prev_dst_foot_midcoords):
assert(ret)
return ret

def calcVelListFromPosList(pos_list, dt):
'''Calculate velocity list from position list.
Element of pos_list and vel_list should be list like [0,0,0].
'''
vel_list=[]
ppos=pos_list[0]
for pos in pos_list:
vel_list.append(map(lambda x, y: (x-y)/dt, pos, ppos));
ppos=pos
return vel_list

def checkTooLargeABCCogAcc (acc_thre = 5.0): # [m/s^2]
'''Check ABC too large cog acceleration.
This is used discontinuous cog trajectory.
'''
# Parse COG [m] and tm [s]
cog_list=[]
tm_list=[]
for line in open("/tmp/test-abc-log.abc_cogOut", "r"):
tm_list.append(float(line.split(" ")[0]));
cog_list.append(map(float, line.split(" ")[1:-1]));
cog_list=cog_list[:-1000] # ?? Neglect latter elements
dt = tm_list[1]-tm_list[0] # [s]
# Calculate velocity and acceleration
dcog_list=calcVelListFromPosList(cog_list, dt)
ddcog_list=calcVelListFromPosList(dcog_list, dt)
# Check max
max_cogx_acc = max(map(lambda x : abs(x[0]), ddcog_list))
max_cogy_acc = max(map(lambda x : abs(x[1]), ddcog_list))
ret = (max_cogx_acc < acc_thre) and (max_cogy_acc < acc_thre)
print >> sys.stderr, " Check acc x = ", max_cogx_acc, ", y = ", max_cogy_acc, ", thre = ", acc_thre, "[m/s^2], ret = ", ret
assert(ret)

def demoAutoBalancerFixFeet ():
print >> sys.stderr, "1. AutoBalancer mode by fixing feet"
hcf.startAutoBalancer(["rleg", "lleg"]);
Expand Down Expand Up @@ -219,11 +252,19 @@ def demoGaitGeneratorGoPos():

def demoGaitGeneratorGoVelocity():
print >> sys.stderr, "2. goVelocity and goStop"
print >> sys.stderr, " goVelocity few steps"
hcf.abc_svc.goVelocity(-0.1, -0.05, -20)
time.sleep(1)
hcf.abc_svc.goStop()
checkActualBaseAttitude()
print >> sys.stderr, " goVelocity()=>OK"
print >> sys.stderr, " goVelocity few steps=>OK"
print >> sys.stderr, " Check discontinuity of COG by checking too large COG acc."
hcf.setMaxLogLength(10000)
hcf.clearLog()
hcf.abc_svc.goVelocity(0,0,0) # One step overwrite
hcf.abc_svc.goStop()
hcf.saveLog("/tmp/test-abc-log");
checkTooLargeABCCogAcc()

def demoGaitGeneratorSetFootSteps():
print >> sys.stderr, "3. setFootSteps"
Expand Down