nao_footstep_clipping.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import almath
4 
5 
6 # Struct with clipping params initialized with clipping values for the NAO robot
7 class Params(object):
8  # Various parameters describing step characteristics.
9  min_step_x = -0.04
10  min_step_y = 0.088
11  max_step_x = 0.08
12  max_step_y = 0.16
13  max_step_theta = 0.5 # 0.5xxx
14  min_step_theta = -max_step_theta
15 
16  # Bounding boxes of NAO's feet.
17  foot_box_r_fl = almath.Pose2D(0.11, 0.038, 0.0)
18  foot_box_r_fr = almath.Pose2D(0.11, -0.050, 0.0)
19  foot_box_r_rr = almath.Pose2D(-0.047, -0.050, 0.0)
20  foot_box_r_rl = almath.Pose2D(-0.047, 0.038, 0.0)
21  foot_box_r = almath.vectorPose2D([foot_box_r_fl, foot_box_r_fr,
22  foot_box_r_rr, foot_box_r_rl])
23 
24  foot_box_l_fl = almath.Pose2D(0.11, 0.050, 0.0)
25  foot_box_l_fr = almath.Pose2D(0.11, -0.038, 0.0)
26  foot_box_l_rr = almath.Pose2D(-0.047, -0.038, 0.0)
27  foot_box_l_rl = almath.Pose2D(-0.047, 0.050, 0.0)
28  foot_box_l = almath.vectorPose2D([foot_box_l_fl, foot_box_l_fr,
29  foot_box_l_rr, foot_box_l_rl])
30 
31 
32 def clip_data(min, max, value):
33  ''' Clip value between two extremes. '''
34  clipped = value
35 
36  if (clipped < min):
37  clipped = min
38  if (clipped > max):
39  clipped = max
40 
41  return clipped
42 
43 
44 def clip_footstep_on_gait_config(foot, is_left_support):
45  ''' Clip the foot move so that it does not exceed the maximum
46  size of steps.
47  foot is an almath.Pose2D (x, y, theta position).
48  is_left_support must be set to True if the move is on the right leg
49  (the robot is supporting itself on the left leg).
50  '''
51 
52  # Clip X.
53  clipped_x = clip_data(Params.min_step_x, Params.max_step_x, foot.x)
54  foot.x = clipped_x
55 
56  # Clip Y.
57  if not is_left_support:
58  clipped_y = clip_data(Params.min_step_y, Params.max_step_y, foot.y)
59  else:
60  clipped_y = clip_data(-Params.max_step_y, -Params.min_step_y, foot.y)
61  foot.y = clipped_y
62 
63  # Clip Theta.
64  clipped_theta = clip_data(Params.min_step_theta, Params.max_step_theta, foot.theta)
65  foot.theta = clipped_theta
66 
67 
69  ''' Clip the foot move inside an ellipse defined by the foot's dimansions.
70  foot is an almath.Pose2D (x, y, theta position).
71  '''
72 
73  # Apply an offset to have Y component of foot move centered on 0.
74  if (foot.y < -Params.min_step_y):
75  foot.y = foot.y + Params.min_step_y
76  elif (foot.y > Params.min_step_y):
77  foot.y = foot.y - Params.min_step_y
78  else:
79  return
80 
81  # Clip the foot move to an ellipse using ALMath method.
82  if foot.x >= 0:
83  almath.clipFootWithEllipse(Params.max_step_x, Params.max_step_y - Params.min_step_y, foot)
84  else:
85  almath.clipFootWithEllipse(Params.min_step_x, Params.max_step_y - Params.min_step_y, foot)
86 
87  # Correct the previous offset on Y component.
88  if foot.y >=0:
89  foot.y = foot.y + Params.min_step_y
90  else:
91  foot.y = foot.y - Params.min_step_y
92 
93 
94 def clip_footstep_to_avoid_collision(foot, is_left_support):
95  ''' Clip the foot move to avoid collision with the other foot.
96  foot is an almath.Pose2D (x, y, theta position).
97  is_left_support must be set to True if the move is on the right leg
98  (the robot is supporting itself on the left leg).
99  '''
100 
101  # Use ALMath method.
102  almath.avoidFootCollision(Params.foot_box_l, Params.foot_box_r, is_left_support, foot)
103 
104 
105 def clip_footstep(foot, is_left_support):
106  ''' Clipping functions to avoid any warnings and undesired effects
107  when sending the footsteps to ALMotion.
108  foot is an almath.Pose2D (x, y, theta position)
109  is_left_support must be set to True if the move is on the right leg
110  (the robot is supporting itself on the left leg).
111  '''
112 
113  # First clip the foot move with gait config.
114  clip_footstep_on_gait_config(foot, is_left_support)
115  # Then clip it on an ellipse.
117  # Then make sure you do not have any collision.
118  clip_footstep_to_avoid_collision(foot, is_left_support)
119 
120 
121 def clip_footstep_tuple(foot, is_left_support):
122  """
123  Wrapper of clip_footstep to handle 'foot' as geometry_msgs.Pose2D.
124  'foot' is a tuple (x, y, theta). A tuple (x_clip, y_clip, theta_clip) is
125  returned.
126  """
127 
128  foot = almath.Pose2D(*foot)
129  clip_footstep(foot, is_left_support)
130  return foot.x, foot.y, foot.theta
def clip_footstep_on_gait_config(foot, is_left_support)
def clip_footstep(foot, is_left_support)
def clip_footstep_to_avoid_collision(foot, is_left_support)
def clip_footstep_tuple(foot, is_left_support)


nao_apps
Author(s):
autogenerated on Mon Jun 10 2019 14:04:55