GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/sot/torque_control/joint-trajectory-generator.hh Lines: 0 4 0.0 %
Date: 2023-06-05 17:45:50 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
 * Copyright 2014, Oscar E. Ramos Ponce, LAAS-CNRS
3
 *
4
 */
5
6
#ifndef __sot_torque_control_joint_trajectory_generator_H__
7
#define __sot_torque_control_joint_trajectory_generator_H__
8
9
/* --------------------------------------------------------------------- */
10
/* --- API ------------------------------------------------------------- */
11
/* --------------------------------------------------------------------- */
12
13
#if defined(WIN32)
14
#if defined(joint_position_controller_EXPORTS)
15
#define SOTJOINTTRAJECTORYGENERATOR_EXPORT __declspec(dllexport)
16
#else
17
#define SOTJOINTTRAJECTORYGENERATOR_EXPORT __declspec(dllimport)
18
#endif
19
#else
20
#define SOTJOINTTRAJECTORYGENERATOR_EXPORT
21
#endif
22
23
/* --------------------------------------------------------------------- */
24
/* --- INCLUDE --------------------------------------------------------- */
25
/* --------------------------------------------------------------------- */
26
#include <boost/assign.hpp>
27
#include <map>
28
#include <pinocchio/fwd.hpp>
29
30
/* HELPER */
31
#include <dynamic-graph/signal-helper.h>
32
33
#include <sot/core/matrix-geometry.hh>
34
#include <sot/core/robot-utils.hh>
35
#include <sot/torque_control/utils/trajectory-generators.hh>
36
#include <sot/torque_control/utils/vector-conversions.hh>
37
38
namespace dynamicgraph {
39
namespace sot {
40
namespace torque_control {
41
42
/* --------------------------------------------------------------------- */
43
/* --- CLASS ----------------------------------------------------------- */
44
/* --------------------------------------------------------------------- */
45
46
class SOTJOINTTRAJECTORYGENERATOR_EXPORT JointTrajectoryGenerator
47
    : public ::dynamicgraph::Entity {
48
  typedef JointTrajectoryGenerator EntityClassName;
49
  DYNAMIC_GRAPH_ENTITY_DECL();
50
51
 public:
52
  /* --- CONSTRUCTOR ---- */
53
  JointTrajectoryGenerator(const std::string& name);
54
55
  void init(const double& dt, const std::string& robotRef);
56
57
  /* --- SIGNALS --- */
58
  DECLARE_SIGNAL_IN(base6d_encoders, dynamicgraph::Vector);
59
  DECLARE_SIGNAL_OUT(q, dynamicgraph::Vector);
60
  DECLARE_SIGNAL_OUT(dq, dynamicgraph::Vector);
61
  DECLARE_SIGNAL_OUT(ddq, dynamicgraph::Vector);
62
  DECLARE_SIGNAL(fRightFoot, OUT, dynamicgraph::Vector);
63
  DECLARE_SIGNAL(fLeftFoot, OUT, dynamicgraph::Vector);
64
  DECLARE_SIGNAL(fRightHand, OUT, dynamicgraph::Vector);
65
  DECLARE_SIGNAL(fLeftHand, OUT, dynamicgraph::Vector);
66
67
 protected:
68
  DECLARE_SIGNAL_OUT_FUNCTION(fRightFoot, dynamicgraph::Vector);
69
  DECLARE_SIGNAL_OUT_FUNCTION(fLeftFoot, dynamicgraph::Vector);
70
  DECLARE_SIGNAL_OUT_FUNCTION(fRightHand, dynamicgraph::Vector);
71
  DECLARE_SIGNAL_OUT_FUNCTION(fLeftHand, dynamicgraph::Vector);
72
73
 public:
74
  /* --- COMMANDS --- */
75
76
  void playTrajectoryFile(const std::string& fileName);
77
78
  /** Print the current angle of the specified joint. */
79
  void getJoint(const std::string& jointName);
80
81
  /** Returns whether all given trajectories have ended **/
82
  bool isTrajectoryEnded();
83
84
  /** Move a joint to a position with a minimum-jerk trajectory.
85
   * @param jointName The short name of the joint.
86
   * @param qFinal The desired final position of the joint [rad].
87
   * @param time The time to go from the current position to qFinal [sec].
88
   */
89
  void moveJoint(const std::string& jointName, const double& qFinal,
90
                 const double& time);
91
  void moveForce(const std::string& forceName, const int& axis,
92
                 const double& fFinal, const double& time);
93
94
  /** Start an infinite sinusoidal trajectory.
95
   * @param jointName The short name of the joint.
96
   * @param qFinal The position of the joint corresponding to the max amplitude
97
   * of the sinusoid [rad].
98
   * @param time The time to go from the current position to qFinal [sec].
99
   */
100
  void startSinusoid(const std::string& jointName, const double& qFinal,
101
                     const double& time);
102
103
  /** Start an infinite triangle trajectory.
104
   * @param jointName The short name of the joint.
105
   * @param qFinal The position of the joint corresponding to the max amplitude
106
   * of the trajectory [rad].
107
   * @param time The time to go from the current position to qFinal [sec].
108
   */
109
  void startTriangle(const std::string& jointName, const double& qFinal,
110
                     const double& time, const double& Tacc);
111
112
  /** Start an infinite trajectory with piece-wise constant acceleration.
113
   * @param jointName The short name of the joint.
114
   * @param qFinal The position of the joint corresponding to the max amplitude
115
   * of the trajectory [rad].
116
   * @param time The time to go from the current position to qFinal [sec].
117
   * @param Tacc The time during witch acceleration is keept constant [sec].
118
   */
119
  void startConstAcc(const std::string& jointName, const double& qFinal,
120
                     const double& time);
121
122
  /** Start an infinite sinusoidal trajectory for the specified force signal.
123
   * @param forceName The short name of the force signal (rh, lh, rf, lf).
124
   * @param fFinal The 6d force corresponding to the max amplitude of the
125
   * sinusoid [N/Nm].
126
   * @param time The time to go from 0 to fFinal [sec].
127
   */
128
  //        void startForceSinusoid(const std::string& forceName, const
129
  //        dynamicgraph::Vector& fFinal, const double& time);
130
  void startForceSinusoid(const std::string& forceName, const int& axis,
131
                          const double& fFinal, const double& time);
132
133
  /** Start a linear-chirp trajectory, that is a sinusoidal trajectory with
134
   * frequency being a linear function of time.
135
   * @param jointName The short name of the joint.
136
   * @param qFinal The position of the joint corresponding to the max amplitude
137
   * of the sinusoid [rad].
138
   * @param f0 The initial (min) frequency of the sinusoid [Hz]
139
   * @param f1 The final (max) frequency of the sinusoid [Hz]
140
   * @param time The time to get from f0 to f1 [sec]
141
   */
142
  void startLinearChirp(const std::string& jointName, const double& qFinal,
143
                        const double& f0, const double& f1, const double& time);
144
145
  void startForceLinearChirp(const std::string& forceName, const int& axis,
146
                             const double& fFinal, const double& f0,
147
                             const double& f1, const double& time);
148
149
  /** Stop the motion of the specified joint. If jointName is "all"
150
   * it stops the motion of all joints.
151
   * @param jointName A string identifying the joint to stop.
152
   * */
153
  void stop(const std::string& jointName);
154
155
  /** Stop the trajectory of the specified force. If forceName is "all"
156
   * it stops all forces.
157
   * @param forceName A string identifying the force to stop.
158
   * */
159
  void stopForce(const std::string& forceName);
160
161
  /* --- ENTITY INHERITANCE --- */
162
  virtual void display(std::ostream& os) const;
163
164
  void sendMsg(const std::string& msg, MsgType t = MSG_TYPE_INFO,
165
               const char* = "", int = 0) {
166
    logger_.stream(t) << ("[JointTrajectoryGenerator-" + name + "] " + msg)
167
                      << '\n';
168
  }
169
170
 protected:
171
  enum JTG_Status {
172
    JTG_STOP,
173
    JTG_SINUSOID,
174
    JTG_MIN_JERK,
175
    JTG_LIN_CHIRP,
176
    JTG_TRIANGLE,
177
    JTG_CONST_ACC,
178
    JTG_TEXT_FILE
179
  };
180
181
  bool
182
      m_initSucceeded;  /// true if the entity has been successfully initialized
183
  bool m_firstIter;     /// true if it is the first iteration, false otherwise
184
  double m_dt;          /// control loop time period
185
186
  RobotUtilShrPtr m_robot_util;
187
188
  std::vector<int> m_iterForceSignals;
189
190
  std::vector<JTG_Status> m_status;  /// status of the joints
191
  std::vector<AbstractTrajectoryGenerator*> m_currentTrajGen;
192
  std::vector<NoTrajectoryGenerator*> m_noTrajGen;
193
  std::vector<MinimumJerkTrajectoryGenerator*> m_minJerkTrajGen;
194
  std::vector<SinusoidTrajectoryGenerator*> m_sinTrajGen;
195
  std::vector<LinearChirpTrajectoryGenerator*> m_linChirpTrajGen;
196
  std::vector<TriangleTrajectoryGenerator*> m_triangleTrajGen;
197
  std::vector<ConstantAccelerationTrajectoryGenerator*> m_constAccTrajGen;
198
  TextFileTrajectoryGenerator* m_textFileTrajGen;
199
200
  std::vector<JTG_Status> m_status_force;  /// status of the forces
201
  std::vector<AbstractTrajectoryGenerator*> m_currentTrajGen_force;
202
  std::vector<NoTrajectoryGenerator*> m_noTrajGen_force;
203
  std::vector<SinusoidTrajectoryGenerator*> m_sinTrajGen_force;
204
  std::vector<MinimumJerkTrajectoryGenerator*> m_minJerkTrajGen_force;
205
  std::vector<LinearChirpTrajectoryGenerator*> m_linChirpTrajGen_force;
206
207
  bool generateReferenceForceSignal(const std::string& forceName, int fid,
208
                                    dynamicgraph::Vector& s, int iter);
209
210
  bool convertJointNameToJointId(const std::string& name, unsigned int& id);
211
  bool convertForceNameToForceId(const std::string& name, unsigned int& id);
212
  bool isJointInRange(unsigned int id, double q);
213
  bool isForceInRange(unsigned int id, const Eigen::VectorXd& f);
214
  bool isForceInRange(unsigned int id, int axis, double f);
215
216
};  // class JointTrajectoryGenerator
217
218
}  // namespace torque_control
219
}  // namespace sot
220
}  // namespace dynamicgraph
221
222
#endif  // #ifndef __sot_torque_control_joint_position_controller_H__