trajectory_example.cpp
Go to the documentation of this file.
1 
11 #include <frames.hpp>
12 #include <frames_io.hpp>
13 #include <trajectory.hpp>
14 #include <trajectory_segment.hpp>
16 #include <trajectory_composite.hpp>
17 #include <trajectory_composite.hpp>
18 #include <velocityprofile_trap.hpp>
21 #include <utilities/error.h>
22 #include <trajectory_composite.hpp>
23 
24 int main(int argc,char* argv[]) {
25  using namespace KDL;
26  // Create the trajectory:
27  // use try/catch to catch any exceptions thrown.
28  // NOTE: exceptions will become obsolete in a future version.
29  try {
30  // Path_RoundedComposite defines the geometric path along
31  // which the robot will move.
32  //
34  // The routines are now robust against segments that are parallel.
35  // When the routines are parallel, no rounding is needed, and no attempt is made
36  // add constructing a rounding arc.
37  // (It is still not possible when the segments are on top of each other)
38  // Note that you can only rotate in a deterministic way over an angle less then M_PI!
39  // With an angle == M_PI, you cannot predict over which side will be rotated.
40  // With an angle > M_PI, the routine will rotate over 2*M_PI-angle.
41  // If you need to rotate over a larger angle, you need to introduce intermediate points.
42  // So, there is a common use case for using parallel segments.
43  path->Add(Frame(Rotation::RPY(M_PI,0,0), Vector(-1,0,0)));
44  path->Add(Frame(Rotation::RPY(M_PI/2,0,0), Vector(-0.5,0,0)));
45  path->Add(Frame(Rotation::RPY(0,0,0), Vector(0,0,0)));
46  path->Add(Frame(Rotation::RPY(0.7,0.7,0.7), Vector(1,1,1)));
47  path->Add(Frame(Rotation::RPY(0,0.7,0), Vector(1.5,0.3,0)));
48  path->Add(Frame(Rotation::RPY(0.7,0.7,0), Vector(1,1,0)));
49 
50  // always call Finish() at the end, otherwise the last segment will not be added.
51  path->Finish();
52 
53  // Trajectory defines a motion of the robot along a path.
54  // This defines a trapezoidal velocity profile.
55  VelocityProfile* velpref = new VelocityProfile_Trap(0.5,0.1);
56  velpref->SetProfile(0,path->PathLength());
57  Trajectory* traject = new Trajectory_Segment(path, velpref);
58 
59 
61  ctraject->Add(traject);
62  ctraject->Add(new Trajectory_Stationary(1.0,Frame(Rotation::RPY(0.7,0.7,0), Vector(1,1,0))));
63 
64 
65 
66  // use the trajectory
67  double dt=0.1;
68  std::ofstream of("./trajectory.dat");
69  for (double t=0.0; t <= traject->Duration(); t+= dt) {
70  Frame current_pose;
71  current_pose = traject->Pos(t);
72  for (int i=0;i<4;++i)
73  for (int j=0;j<4;++j)
74  of << current_pose(i,j) << "\t";
75  of << "\n";
76  // also velocities and accelerations are available !
77  //traject->Vel(t);
78  //traject->Acc(t);
79  }
80  of.close();
81 
82  // you can get some meta-info on the path:
83  for (int segmentnr=0; segmentnr < path->GetNrOfSegments(); segmentnr++) {
84  double starts,ends;
85  Path::IdentifierType pathtype;
86  if (segmentnr==0) {
87  starts = 0.0;
88  } else {
89  starts = path->GetLengthToEndOfSegment(segmentnr-1);
90  }
91  ends = path->GetLengthToEndOfSegment(segmentnr);
92  pathtype = path->GetSegment(segmentnr)->getIdentifier();
93  std::cout << "segment " << segmentnr << " runs from s="<<starts << " to s=" <<ends;
94  switch(pathtype) {
95  case Path::ID_CIRCLE:
96  std::cout << " circle";
97  break;
98  case Path::ID_LINE:
99  std::cout << " line ";
100  break;
101  default:
102  std::cout << " unknown ";
103  break;
104  }
105  std::cout << std::endl;
106  }
107  std::cout << " trajectory written to the ./trajectory.dat file " << std::endl;
108 
109  delete ctraject;
110  } catch(Error& error) {
111  std::cout <<"I encountered this error : " << error.Description() << std::endl;
112  std::cout << "with the following type " << error.GetType() << std::endl;
113  }
114 
115 }
116 
117 
void Add(const Frame &F_base_point)
virtual void Add(Trajectory *elem)
virtual int GetType() const
Definition: error.h:65
A concrete implementation of a 3 dimensional vector class.
Definition: frames.hpp:160
static Rotation RPY(double roll, double pitch, double yaw)
Definition: frames.cpp:238
virtual Frame Pos(double time) const =0
IdentifierType
Definition: path.hpp:61
virtual const char * Description() const
Definition: error.h:63
virtual IdentifierType getIdentifier() const =0
virtual double Duration() const =0
represents a frame transformation in 3D space (rotation + translation)
Definition: frames.hpp:570
virtual void SetProfile(double pos1, double pos2)=0
int main(int argc, char *argv[])
virtual double GetLengthToEndOfSegment(int i)


orocos_kdl
Author(s):
autogenerated on Sat Jun 15 2019 19:07:36