Loading...
Searching...
No Matches
force-curve.hpp
Go to the documentation of this file.
1
11#ifndef _parameteric_curves_force_curve_hpp
12#define _parameteric_curves_force_curve_hpp
13
14#include <boost/archive/text_iarchive.hpp>
15#include <boost/archive/text_oarchive.hpp>
16#include <boost/serialization/split_member.hpp>
17#include <boost/serialization/vector.hpp>
18#include <fstream>
21#include <vector>
22namespace parametriccurves {
23namespace spatial {
24
30template <typename Numeric = double>
32 : public AbstractCurve<Numeric, Eigen::Matrix<Numeric, 6, 1> > {
33 static const std::size_t Dim = 3;
34 typedef Eigen::Matrix<Numeric, 2 * Dim, 1> force_t;
35 typedef Eigen::Matrix<Numeric, 2 * Dim, 1> motion_t;
38 typedef Numeric time_t;
39 typedef Numeric num_t;
41
42 public:
44
46
49 ForceCurve(const spline_lin_t& linPart_, const spline_ang_t& angPart_)
50 : curve_abc_t(linPart_.tmin(), linPart_.tmax()),
51 linPart(linPart_),
52 angPart(angPart_),
53 motionVector(motion_t::Zero()) {}
54
56 ForceCurve(const ForceCurve& other)
57 : curve_abc_t(other.linPart.tmin(), other.linPart.tmax()),
58 linPart(other.linPart),
59 angPart(other.angPart),
60 motionVector(motion_t::Zero()) {}
61
64
65 public:
66 virtual const force_t operator()(const time_t& t) const {
67 force_t s = force_t::Zero();
68 s << linPart(t), angPart(t);
69 return s;
70 }
71
72 virtual const force_t derivate(const time_t&, const std::size_t&) const {
73 // TODO: Implement derivative
74 return force_t::Zero(Dim);
75 }
76
77 virtual const std::size_t& size() const { return linPart.size(); }
78
79 void setMotionVector(const motion_t& motionVector_) {
80 motionVector = motionVector_;
81 return;
82 }
83
84 virtual bool setInitialPoint(const force_t& /*x_init*/) { return false; }
85 virtual bool setInitialPoint(const num_t& /*x_init*/) { return false; }
86
87 protected:
88 /*Attributes*/
92
93 private:
94 // Serialization of the class
96 template <class Archive>
97 void save(Archive& ar, const unsigned int /*version*/) const {
98 ar& linPart;
99 ar& angPart;
100
101 return;
102 }
103
104 template <class Archive>
105 void load(Archive& ar, const unsigned int /*version*/) {
106 ar& linPart;
107 ar& angPart;
108
109 motionVector = motion_t::Zero();
110 this->t_min = linPart.tmin();
111 this->t_max = linPart.tmax();
112
113 assert(this->t_min == angPart.tmin());
114 assert(this->t_max == angPart.tmax());
115 return;
116 }
117
118 BOOST_SERIALIZATION_SPLIT_MEMBER()
119
120 public:
121 bool loadFromFile(const std::string& filename) {
122 std::ifstream ifs(filename.c_str());
123 if (ifs) {
124 boost::archive::text_iarchive ia(ifs);
125 ForceCurve& force_curve = *static_cast<ForceCurve*>(this);
126 ia >> force_curve;
127 } else {
128 const std::string exception_message(filename +
129 " does not seem to be a valid file.");
130 throw std::invalid_argument(exception_message);
131 return false;
132 }
133 return true;
134 }
135
137 bool saveToFile(const std::string& filename) const {
138 std::ofstream ofs(filename.c_str());
139 if (ofs) {
140 boost::archive::text_oarchive oa(ofs);
141 oa << *static_cast<const ForceCurve*>(this);
142 } else {
143 const std::string exception_message(filename +
144 " does not seem to be a valid file.");
145 throw std::invalid_argument(exception_message);
146 return false;
147 }
148 return true;
149 }
150
151 // BOOST_SERIALIZATION_SPLIT_MEMBER()
152};
153} // namespace spatial
154} // namespace parametriccurves
155#endif //_CLASS_EXACTCUBIC
Definition: abstract-curve.hpp:16
Represents a curve of dimension Dim is Safe is false, no verification is made on the evaluation of th...
Definition: abstract-curve.hpp:21
virtual const time_t tmin() const
Definition: abstract-curve.hpp:47
virtual const time_t tmax() const
Definition: abstract-curve.hpp:48
time_t t_max
Definition: abstract-curve.hpp:65
time_t t_min
Definition: abstract-curve.hpp:64
Represents a set of cubic splines defining a continuous function crossing each of the waypoint given ...
Definition: spline.hpp:86
virtual const std::size_t & size() const
Definition: spline.hpp:264
Representation of a spatial vector curve in the form of splines Returns Plucker coordinates in the fo...
Definition: force-curve.hpp:32
virtual const std::size_t & size() const
Definition: force-curve.hpp:77
bool saveToFile(const std::string &filename) const
Saved a Derived object as a text file.
Definition: force-curve.hpp:137
void setMotionVector(const motion_t &motionVector_)
Definition: force-curve.hpp:79
spline_lin_t linPart
Definition: force-curve.hpp:89
virtual const force_t operator()(const time_t &t) const
Evaluation of the cubic spline at time t.
Definition: force-curve.hpp:66
virtual bool setInitialPoint(const num_t &)
Definition: force-curve.hpp:85
Spline< Numeric, Dim, Eigen::Matrix< Numeric, Dim, 1 > > spline_lin_t
Definition: force-curve.hpp:36
spline_ang_t angPart
Definition: force-curve.hpp:90
Spline< Numeric, Dim, Eigen::Matrix< Numeric, Dim, 1 > > spline_ang_t
Definition: force-curve.hpp:37
ForceCurve(const ForceCurve &other)
Copy Constructor.
Definition: force-curve.hpp:56
AbstractCurve< num_t, force_t > curve_abc_t
Definition: force-curve.hpp:40
motion_t motionVector
Definition: force-curve.hpp:91
Eigen::Matrix< Numeric, 2 *Dim, 1 > motion_t
Definition: force-curve.hpp:35
~ForceCurve()
Destructor.
Definition: force-curve.hpp:63
bool loadFromFile(const std::string &filename)
Definition: force-curve.hpp:121
virtual bool setInitialPoint(const force_t &)
Definition: force-curve.hpp:84
Numeric time_t
Definition: force-curve.hpp:38
static const std::size_t Dim
Definition: force-curve.hpp:33
friend class boost::serialization::access
Definition: force-curve.hpp:95
Numeric num_t
Definition: force-curve.hpp:39
Eigen::Matrix< Numeric, 2 *Dim, 1 > force_t
Definition: force-curve.hpp:34
ForceCurve()
Constructor.
Definition: force-curve.hpp:45
virtual const force_t derivate(const time_t &, const std::size_t &) const
Evaluation of the derivative spline at time t.
Definition: force-curve.hpp:72
ForceCurve(const spline_lin_t &linPart_, const spline_ang_t &angPart_)
Constructor.
Definition: force-curve.hpp:49