- 3.0.2 rigid body dynamics module.
SimpleArmTrajectoryGenerator.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include "../state/JointState.h"
9 #include "../state/JointAcceleration.h"
10 
12 
13 namespace ct {
14 namespace rbd {
15 
22 template <size_t NJOINTS, typename SCALAR = double>
24 {
25 public:
29 
30 
31  SimpleArmTrajectoryGenerator(const Velocity& kAbsMaxJointVelocities, const Acceleration& kAbsMaxJointAccelerations)
32  : abs_max_joint_velocities_(kAbsMaxJointVelocities), abs_max_joint_accelerations_(kAbsMaxJointAccelerations)
33  {
34  // Initialize joint angle generators
35  for (size_t i = 0; i < NJOINTS; i++)
36  {
37  joint_traj_generators_.push_back(SingleDOFTrajectoryGenerator());
38  }
39  }
40 
46  const Position& end,
47  const SCALAR sampling_time = SCALAR(0.02),
48  bool verbose = false)
49  {
50  // Step 1 set bounds and determine the joint that takes the most time to execute and the
51  // according time
52  std::vector<SCALAR> planned_joint_times(NJOINTS);
53 
54  SCALAR x_new, v_new;
55 
56  for (size_t i = 0; i < NJOINTS; i++)
57  {
58  planned_joint_times[i] = joint_traj_generators_[i].setup(
59  start(i), end(i), abs_max_joint_velocities_(i), abs_max_joint_accelerations_(i));
60  }
61 
62  SCALAR time_horizon = *std::max_element(planned_joint_times.begin(), planned_joint_times.end());
63  size_t num_traj_points = round(time_horizon / sampling_time) + 1;
64 
65  if (verbose)
66  {
67  std::cout << "SimpleArmTrajectoryGenerator: Time horizon of new Trajectory: " << time_horizon << " sec."
68  << std::endl;
69  std::cout << "SimpleArmTrajectoryGenerator: Number of Sampling Points: " << num_traj_points
70  << std::endl;
71  }
72 
74 
75  for (size_t n = 0; n < num_traj_points; n++)
76  {
78  double time = n * sampling_time;
79 
80  for (size_t i = 0; i < NJOINTS; i++)
81  {
82  joint_traj_generators_[i].queryTrajectory(time, x_new, v_new);
83  new_state(i) = x_new;
84  new_state(i + NJOINTS) = v_new;
85  }
86 
87  new_traj.push_back(new_state, time, true);
88  }
89 
90 
91  return new_traj;
92  }
93 
94 private:
95  std::vector<tpl::SingleDOFTrajectoryGenerator<SCALAR>> joint_traj_generators_;
96  Velocity abs_max_joint_velocities_;
97  Acceleration abs_max_joint_accelerations_;
98 };
99 
100 } // rbd
101 } // ct
typename ct::rbd::JointState< NJOINTS, SCALAR >::Velocity Velocity
Definition: SimpleArmTrajectoryGenerator.h:27
joint state and joint velocity
Definition: JointState.h:21
typename ct::rbd::JointState< NJOINTS, SCALAR >::Position Position
Definition: SimpleArmTrajectoryGenerator.h:26
Definition: SimpleArmTrajectoryGenerator.h:23
CppAD::AD< CppAD::cg::CG< double > > SCALAR
bool verbose
Definition: rbdJITtests.h:15
constexpr size_t n
for i
Eigen::Matrix< SCALAR, NJOINTS, 1 > Acceleration
Definition: JointAcceleration.h:27
core::StateTrajectory< 2 *NJOINTS > generateTrajectory(const Position &start, const Position &end, const SCALAR sampling_time=SCALAR(0.02), bool verbose=false)
Definition: SimpleArmTrajectoryGenerator.h:45
void push_back(const T &data, const SCALAR &time, const bool timeIsAbsolute)
typename ct::rbd::JointAcceleration< NJOINTS, SCALAR >::Acceleration Acceleration
Definition: SimpleArmTrajectoryGenerator.h:28
tpl::SingleDOFTrajectoryGenerator< double > SingleDOFTrajectoryGenerator
Definition: SingleDOFTrajectoryGenerator.h:206
SimpleArmTrajectoryGenerator(const Velocity &kAbsMaxJointVelocities, const Acceleration &kAbsMaxJointAccelerations)
Definition: SimpleArmTrajectoryGenerator.h:31