47 #ifndef FASTRACK_DYNAMICS_KINEMATICS_H 48 #define FASTRACK_DYNAMICS_KINEMATICS_H 52 #include <fastrack_srvs/KinematicPlannerDynamics.h> 59 using control::VectorBoundBox;
63 :
public Dynamics<S, VectorXd, VectorBoundBox,
64 fastrack_srvs::KinematicPlannerDynamics::Response> {
67 :
Dynamics<S, VectorXd, VectorBoundBox,
68 fastrack_srvs::KinematicPlannerDynamics::Response>() {}
70 :
Dynamics<S, VectorXd, VectorBoundBox,
71 fastrack_srvs::KinematicPlannerDynamics::Response>(bound) {}
73 :
Dynamics<S, VectorXd, VectorBoundBox,
74 fastrack_srvs::KinematicPlannerDynamics::Response>(params) {}
75 explicit Kinematics(
const VectorXd& u_lower,
const VectorXd& u_upper)
76 :
Dynamics<S, VectorXd, VectorBoundBox,
77 fastrack_srvs::KinematicPlannerDynamics::Response>(
78 VectorBoundBox(u_lower, u_upper)) {}
82 inline S
Evaluate(
const S& x,
const VectorXd& u)
const;
87 throw std::runtime_error(
"Kinematics: OptimalControl is not implemented.");
91 inline fastrack_srvs::KinematicPlannerDynamics::Response
ToRos()
const;
95 const fastrack_srvs::KinematicPlannerDynamics::Response& res);
108 template <
typename S>
111 const VectorXd c = x.Configuration();
112 if (c.size() != u.size()) {
113 throw std::runtime_error(
"Kinematics: config/control spaces not equal.");
120 template <
typename S>
123 throw std::runtime_error(
"Kinematics was not initialized.");
128 fastrack_srvs::KinematicPlannerDynamics::Response res;
129 for (
size_t ii = 0; ii < lower_bound.size(); ii++) {
130 res.min_speed.push_back(lower_bound(ii));
131 res.max_speed.push_back(upper_bound(ii));
138 template <
typename S>
140 const fastrack_srvs::KinematicPlannerDynamics::Response& res) {
141 if (res.max_speed.size() != res.min_speed.size())
142 throw std::runtime_error(
"Kinematics: invalid service response.");
145 VectorXd lower_bound(res.min_speed.size());
146 VectorXd upper_bound(res.min_speed.size());
147 for (
size_t ii = 0; ii < res.min_speed.size(); ii++) {
148 lower_bound(ii) = res.min_speed[ii];
149 upper_bound(ii) = res.max_speed[ii];
152 this->
control_bound_.reset(
new VectorBoundBox(lower_bound, upper_bound));
157 template <
typename S>
160 throw std::runtime_error(
"Kinematics was not initialized.");
163 const VectorXd c1 = x1.Configuration();
164 const VectorXd c2 = x2.Configuration();
167 double time = -std::numeric_limits<double>::infinity();
168 for (
size_t ii = 0; ii < S::ConfigurationDimension(); ii++) {
169 const double time_this_dim =
170 (c2(ii) >= c1(ii)) ? (c2(ii) - c1(ii)) / this->
control_bound_->Max()(ii)
172 time = std::max(time, time_this_dim);
S Evaluate(const S &x, const VectorXd &u) const
Kinematics(const std::vector< double > ¶ms)
Kinematics(const VectorBoundBox &bound)
double BestPossibleTime(const S &x1, const S &x2) const
fastrack_srvs::KinematicPlannerDynamics::Response ToRos() const
void FromRos(const fastrack_srvs::KinematicPlannerDynamics::Response &res)
std::unique_ptr< VectorBoundBox > control_bound_
Kinematics(const VectorXd &u_lower, const VectorXd &u_upper)
VectorXd OptimalControl(const S &x, const S &value_gradient) const