1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
 * @file HeadMotionEngine.h
 *
 * @author <a href="mailto:mellmann@informatik.hu-berlin.de">Heinrich Mellmann</a>
 * @author Oliver Welter
 *
 * Created on 27. Januar 2009, 16:43
 */

#ifndef _HeadMotionEngine_H
#define _HeadMotionEngine_H

#include <Tools/Math/Vector2.h>
#include <Tools/Math/Vector3.h>
#include <vector>

#include <ModuleFramework/Module.h>

// representations
#include <Representations/Infrastructure/FrameInfo.h> // needed for debug plot
#include <Representations/Infrastructure/RobotInfo.h>
#include <Representations/Infrastructure/CameraInfo.h>
#include "Representations/Modeling/InertialModel.h"
#include "Representations/Infrastructure/InertialSensorData.h"
#include "Representations/Modeling/KinematicChain.h"
#include "Representations/Motion/Request/HeadMotionRequest.h"
#include <Representations/Infrastructure/JointData.h>
#include <Representations/Perception/CameraMatrix.h>
#include "Representations/Motion/MotionStatus.h"
#include <Representations/Modeling/CameraMatrixOffset.h>

#include "Tools/DataStructures/RingBufferWithSum.h"
#include "Tools/DataStructures/Spline.h"

// Debug
#include "Tools/Debug/DebugModify.h"
#include <Tools/Debug/DebugRequest.h>
#include <Tools/Debug/DebugPlot.h>
#include <Tools/Debug/DebugDrawings.h>
#include "Tools/Debug/DebugParameterList.h"

BEGIN_DECLARE_MODULE(HeadMotionEngine)
  PROVIDE(DebugModify)
  PROVIDE(DebugRequest)
  PROVIDE(DebugDrawings)
  PROVIDE(DebugParameterList)
  PROVIDE(DebugPlot)

  REQUIRE(RobotInfo)
  REQUIRE(InertialModel)
  REQUIRE(InertialSensorData)
  REQUIRE(KinematicChainSensor)
  REQUIRE(KinematicChainMotor)
  REQUIRE(HeadMotionRequest)
  REQUIRE(SensorJointData)
  REQUIRE(FrameInfo)

  REQUIRE(CameraMatrix)
  REQUIRE(CameraMatrixTop)
  REQUIRE(CameraInfo)
  REQUIRE(CameraInfoTop)
  REQUIRE(CameraMatrixOffset)

  PROVIDE(MotionStatus)
  PROVIDE(MotorJointData)
END_DECLARE_MODULE(HeadMotionEngine)


class HeadMotionEngine: private HeadMotionEngineBase
{
public:
  HeadMotionEngine();
  ~HeadMotionEngine();

  void execute();

private:
  struct Parameters: public ParameterList
  {
    Parameters() : ParameterList("HeadMotionEngine")
    {
      PARAMETER_ANGLE_REGISTER(max_head_velocity_stand) = 120; //  deg/s
      PARAMETER_ANGLE_REGISTER(max_head_velocity_walk_fast) = 90; // deg/s velocity when walking fast
      PARAMETER_ANGLE_REGISTER(max_head_velocity_walk_slow) = 120; // deg/s velocity when walking slow
      PARAMETER_REGISTER(walk_fast_speed_threshold) = 40; // ~mm/s walking speed of the robot. Faster than this is considered fast walking

      PARAMETER_REGISTER(timeThresholdForHeadStuck) = 1000; // ms

      PARAMETER_ANGLE_REGISTER(at_rest_threshold) = 1;
      PARAMETER_ANGLE_REGISTER(at_rest_threshold_walking) = 10;
      PARAMETER_ANGLE_REGISTER(at_target_threshold) = 3;

      PARAMETER_REGISTER(stiffness) = 0.7;

      PARAMETER_REGISTER(use_lookAtWorldPointCool) = true;

      syncWithConfig();
    }

    double max_head_velocity_stand;
    double max_head_velocity_walk_fast;
    double max_head_velocity_walk_slow;
    double walk_fast_speed_threshold;

    int timeThresholdForHeadStuck;

    double at_rest_threshold;
    double at_rest_threshold_walking;
    double at_target_threshold;

    double stiffness;

    bool use_lookAtWorldPointCool;
  } params;

private:

  // HACK: limits.
  // TODO: make them parameters. (as soon as we have a config system that allows loading vectors :)
  // NOTE: V4, V5, V6 have the same limits
  // http://doc.aldebaran.com/2-8/family/nao_technical/joints_naov6.html#naov6-joints-head-joints
  // http://doc.aldebaran.com/2-1/family/robots/joints_robot.html
  std::vector<double> headLimitsHeadYaw  = 
  {
    -2.086017,
    -1.526988,
    -1.089958,
    -0.903033,
    -0.756077,
    -0.486074,
     0.000000,
     0.486074,
     0.756077,
     0.903033,
     1.089958,
     1.526988,
     2.086017
  };

  std::vector<double> headLimitsHeadPitchMin = 
  {
    -0.449073,
    -0.330041,
    -0.430049,
    -0.479965,
    -0.548033,
    -0.671951,
    -0.671951,
    -0.671951,
    -0.548033,
    -0.479965,
    -0.430049,
    -0.330041,
    -0.449073  
  };
  
  std::vector<double> headLimitsHeadPitchMax = 
  {
    0.330041,
    0.200015,
    0.300022,
    0.330041,
    0.370010,
    0.422021,
    0.515047,
    0.422021,
    0.370010,
    0.330041,
    0.300022,
    0.200015,
    0.330041
  };
  
  tk::spline headLimitFunctionMin;
  tk::spline headLimitFunctionMax;

  // internal use
  naoth::JointData theJointData;
  KinematicChain theKinematicChain;

  void updateHeadTargetReached();

  bool trajectoryHeadMove(const std::vector<Vector3d>& points);
  //void gotoPointOnTheGround(const Vector2d& target);

  void lookStraightAhead();
  void lookStraightAheadWithStabilization();
  void lookAtPoint();
  void simpleLookAtPoint();

  void hold();
  void search();
  void randomSearch();

  void moveByAngle(const Vector2d& target);
  void gotoAngle(const Vector2d& target);

  void lookAtWorldPointCool(const Vector3d& target);<--- Function 'lookAtWorldPointCool' argument 1 names different: declaration 'target' definition 'origTarget'.
  void lookAtWorldPoint(const Vector3d& target);<--- Function 'lookAtWorldPoint' argument 1 names different: declaration 'target' definition 'origTarget'.
  void lookAtWorldPointSimple(const Vector3d& target);

  Vector3d g(double yaw, double pitch, const Vector3d& pointInWorld);
  void export_g();

  // for providing head_target_reached and head_got_stuck
  Vector2d motion_target;
  Vector2d last_yaw_pitch_command;
  RingBufferWithSum<Vector2d, 10> absolute_velocity_buffer;
  FrameInfo lastFrameInfoWhenHeadMovedOrOnTarget;
};

#endif  /* _HeadMotionEngine_H */