NimbRo ROS Soccer Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RobotModel.h
1 // Encapsulates the model of a robot for gait purposes.
2 // File: RobotModel.h
3 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
4 
5 // Ensure header is only included once
6 #ifndef CAP_ROBOTMODEL_H
7 #define CAP_ROBOTMODEL_H
8 
9 // Includes
10 #include <QGLViewer/frame.h>
11 #include <cap_gait/contrib/Action.h>
12 #include <cap_gait/cap_gait_config.h>
13 
14 // Margait contrib namespace
15 namespace margait_contrib
16 {
17 
18 // Namespaces
19 using namespace qglviewer;
20 
21 // RobotModel class
22 class RobotModel
23 {
24 public:
25  // Constructor
26  explicit RobotModel(cap_gait::CapConfig* capConfig);
27 
28  // Configuration variables
29  const cap_gait::CapConfig* getConfig() const { return config; }
30 
31  // Reset function
32  void reset(bool resetModel = true);
33 
34  // Robot odometry
35  void resetOdom(); // Resets the CoM odometry to a zero position in the world frame
36  void setOdom(double comX, double comY, double fYaw); // Set the CoM odometry to a particular position and fused yaw in the world frame
37 
38  // Update the robot model with new pose and fused angle data
39  void update(const Pose& pose, double fusedX, double fusedY);
40 
41  // Sets the support leg sign of the model and updates the required associated frames
42  void setSupportLeg(int supportLegSign);
43 
44  // Robot model CoM vector (vector from footstep frame to CoM in footstep frame coordinates)
45  Vec suppComVector() const; // Returns the vector pointing from the support footstep frame to the CoM in support footstep frame coordinates
46  Vec freeComVector() const; // Returns the vector pointing from the free footstep frame to the CoM in free footstep frame coordinates
47  Vec leftComVector() const; // Returns the vector pointing from the left footstep frame to the CoM in left footstep frame coordinates
48  Vec rightComVector() const; // Returns the vector pointing from the right footstep frame to the CoM in right footstep frame coordinates
49 
50  // Robot model step vector (vector from footstep frame to other footstep frame in footstep frame coordinates)
51  Vec suppStepVector() const; // Returns the vector pointing from the support footstep frame to the free footstep frame in support footstep frame coordinates
52  Vec freeStepVector() const; // Returns the vector pointing from the free footstep frame to the support footstep frame in free footstep frame coordinates
53  Vec leftStepVector() const; // Returns the vector pointing from the left footstep frame to the right footstep frame in left footstep frame coordinates
54  Vec rightStepVector() const; // Returns the vector pointing from the right footstep frame to the left footstep frame in right footstep frame coordinates
55 
56  // Robot model swing vector (vector from CoM to other footstep frame in footstep frame coordinates)
57  Vec suppSwingVector() const; // Returns the vector pointing from the CoM to the free footstep frame in support foot coordinates
58  Vec freeSwingVector() const; // Returns the vector pointing from the CoM to the support footstep frame in free foot coordinates
59  Vec leftSwingVector() const; // Returns the vector pointing from the CoM to the right footstep frame in left foot coordinates
60  Vec rightSwingVector() const; // Returns the vector pointing from the CoM to the left footstep frame in right foot coordinates
61 
62  // Robot model step yaw (difference in fused yaw from footstep frame to other footstep frame in the global coordinate frame)
63  double suppStepYaw() const; // Returns the difference in fused yaw from the support footstep frame to the free footstep frame in the global coordinate frame
64  double freeStepYaw() const; // Returns the difference in fused yaw from the free footstep frame to the support footstep frame in the global coordinate frame
65  double leftStepYaw() const; // Returns the difference in fused yaw from the left footstep frame to the right footstep frame in the global coordinate frame
66  double rightStepYaw() const; // Returns the difference in fused yaw from the right footstep frame to the left footstep frame in the global coordinate frame
67 
68  // Static conversion functions
69  static double fusedYaw(const Quaternion& q); // Returns the fused yaw of a quaternion orientation in the range (-pi,pi]
70  static Quaternion quatFromFusedPR(double fusedX, double fusedY); // Converts a pure fused pitch/roll rotation to a quaternion
71 
72 protected:
73  // Initialisation of kinematic model
74  void initKinematicModel(); // Initialises the entire kinematic chain
75  void initKinematicHierarchy(); // Initialises the reference frame hierarchy of the kinematic chain
76  void initKinematicTranslations(); // Initialises the translations of the kinematic chain
77  void initKinematicRotations(); // Initialises the rotations of the kinematic chain
78 
79  // Update functions
80  void updateLeftRightFootstep(); // Updates the left/right footstep frames based on the left/right foot floor point frames
81  void updateSuppFreeFootstep(); // Updates the support and free footstep frames as being the left or right footstep frames, based on the current support leg sign
82 
83  // Set robot pose functions
84  void setPose(const Pose& pose) { this->pose = pose; applyPose(); } // Set the kinematic pose of the modelled robot and apply it
85  void applyPose(); // Applies the currently set joint angles to the kinematic model
86  void alignModel(double fusedX, double fusedY); // Set the fused pitch/roll orientation of the model (fused yaw is part of the odometry)
87 
88  // Helper functions
89  double getStepYaw(const Frame& fromFootstep, const Frame& toFootstep) const;
90 
91  // Configuration variables
92  cap_gait::CapConfig* config;
93  void robotSpecCallback() { initKinematicTranslations(); }
94 
95  // Robot pose (encapsulates the currently set joint angles, applied to the kinematic frames by the applyPose() function)
96  Pose pose;
97 
98 public:
99  // Root frame
100  Frame base; // Global frame placed at the centre between the two hip joints (the nominal "base" reference point of the robot)
101 
102  // Footstep frames
103  Frame leftFootstep; // Global frame placed at the left foot floor point, with only the yaw component of the rotation of the left foot (left footstep frame)
104  Frame rightFootstep; // Global frame placed at the right foot floor point, with only the yaw component of the rotation of the right foot (right footstep frame)
105  Frame suppFootstep; // Frame placed at either the left or right footstep frame depending on the current support leg (support footstep frame)
106  Frame freeFootstep; // Frame placed at either the left or right footstep frame depending on the current free leg (free footstep frame)
107 
108  // Trunk frames
109  Frame com; // Frame placed at the CoM of the robot
110  Frame trunkLink; // Frame placed at the trunk link of the robot as per the tf (i.e. as defined by the URDF model)
111 
112  // Head frames
113  Frame neck; // Frame placed at the neck joint, aligned with the head
114  Frame head; // Frame placed at the centre of the head, aligned with the head
115 
116  // Left arm frames
117  Frame lShoulder; // Frame placed at the left shoulder joint, aligned with the upper arm
118  Frame lElbow; // Frame placed at the left elbow joint, aligned with the lower arm
119  Frame lHand; // Frame placed at the left hand, aligned with the lower arm
120 
121  // Right arm frames
122  Frame rShoulder; // Frame placed at the right shoulder joint, aligned with the upper arm
123  Frame rElbow; // Frame placed at the right elbow joint, aligned with the lower arm
124  Frame rHand; // Frame placed at the right hand, aligned with the lower arm
125 
126  // Left leg frames
127  Frame lHip; // Frame placed at the left hip joint, aligned with the upper leg
128  Frame lKnee; // Frame placed at the left knee joint, aligned with the lower leg
129  Frame lAnkle; // Frame placed at the left ankle joint, aligned with the foot
130  Frame lFootFloorPoint; // Frame placed at the point on the bottom of the left foot that is assumed to be in contact with the ground when left is the support foot, aligned with the foot
131 
132  // Right leg frames
133  Frame rHip; // Frame placed at the right hip joint, aligned with the upper leg
134  Frame rKnee; // Frame placed at the right knee joint, aligned with the lower leg
135  Frame rAnkle; // Frame placed at the right ankle joint, aligned with the foot
136  Frame rFootFloorPoint; // Frame placed at the point on the bottom of the right foot that is assumed to be in contact with the ground when right is the support foot, aligned with the foot
137 
138  // TODO: A current shortcoming of the robot model is that x-offsets from the hip midpoint to the shoulder line/arm axis/head axis aren't considered.
139 
140  // Support leg information
141  enum
142  {
143  LEFT_LEG = -1,
144  RIGHT_LEG = 1
145  };
146  int supportLegSign; // Sign of the current support leg (1 = Right leg, -1 = Left leg)
147  bool supportExchange; // Flag whether a support exchange happened during a call to update()
148  bool supportExchangeLock; // Flag whether a support exchange is currently disallowed (used to enforce a hysteresis)
149 };
150 
151 }
152 
153 #endif
154 // EOF
Configuration struct for the capture step gait.
Definition: cap_gait_config.h:21