52 using namespace gtsam;
63 list<TimedOdometry> odometryList;
66 if (!is)
throw runtime_error(
"Plaza1_DR.txt file not found");
69 double t, distance_traveled, delta_heading;
70 is >> t >> distance_traveled >> delta_heading;
71 odometryList.push_back(
82 vector<RangeTriple> triples;
85 if (!is)
throw runtime_error(
"Plaza1_TD.txt file not found");
88 double t, sender, receiver,
range;
89 is >> t >> sender >> receiver >>
range;
97 int main(
int argc,
char** argv) {
102 size_t K = triples.size();
105 size_t start = 220,
end=3000;
120 rangeNoise = robust ? tukey : gaussian;
127 M_PI - 2.02108900000000);
129 newFactors.
addPrior(0, pose0, priorNoise);
131 ofstream os2(
"rangeResultLM.txt");
132 ofstream os3(
"rangeResultSR.txt");
146 size_t ids[] = { 1, 6, 0, 5 };
147 typedef std::shared_ptr<SmartRangeFactor> SmartPtr;
148 map<size_t, SmartPtr> smartFactors;
150 for(
size_t jj: ids) {
160 size_t countK = 0, totalCount=0;
168 std::tie(t, odometry) = timedOdometry;
169 printf(
"step %d, time = %g\n",(
int)i,t);
177 lastPose = predictedPose;
178 initial.
insert(i, predictedPose);
179 landmarkEstimates.
insert(i, predictedPose);
182 while (k < K && t >= std::get<0>(triples[k])) {
183 size_t j = std::get<1>(triples[k]);
184 double range = std::get<2>(triples[k]);
186 if (smart && totalCount < minK) {
188 smartFactors[
j]->addRange(i, range);
189 printf(
"adding range %g for %d",range,(
int)j);
190 }
catch (
const invalid_argument&
e) {
191 printf(
"warning: omitting duplicate range %g for %d: %s", range,
201 if (k <= 200 ||
std::abs(error[0]) < 5)
211 if (k >= minK && countK >= incK) {
213 isam.
update(newFactors, initial);
215 gttic_(calculateEstimate);
217 gttoc_(calculateEstimate);
222 landmarkEstimates =
Values();
228 if (smart && !hasLandmarks) {
229 cout <<
"initialize from smart landmarks" << endl;
230 for(
size_t jj: ids) {
238 os2 <<
key <<
"\t" <<
point.x() <<
"\t" <<
point.y() <<
"\t1" << endl;
240 for(
size_t jj: ids) {
242 os3 << jj <<
"\t" << landmark.x() <<
"\t" << landmark.y() <<
"\t1" 258 ofstream
os(
"rangeResult.txt");
260 os <<
key <<
"\t" <<
pose.
x() <<
"\t" <<
pose.
y() <<
"\t" <<
pose.theta() << endl;
const gtsam::Symbol key('X', 0)
A smart factor for range-only SLAM that does initialization and marginalization.
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
const ValueType at(Key j) const
std::pair< double, Pose2 > TimedOdometry
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
std::map< Key, ValueType > extract(const std::function< bool(Key)> &filterFcn=&_truePredicate< Key >) const
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
virtual ISAM2Result update(const NonlinearFactorGraph &newFactors=NonlinearFactorGraph(), const Values &newTheta=Values(), const FactorIndices &removeFactorIndices=FactorIndices(), const std::optional< FastMap< Key, int > > &constrainedKeys={}, const std::optional< FastList< Key > > &noRelinKeys={}, const std::optional< FastList< Key > > &extraReelimKeys={}, bool force_relinearize=false)
static shared_ptr Create(const RobustModel::shared_ptr &robust, const NoiseModel::shared_ptr noise)
static Point3 landmark(0, 0, 5)
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
list< TimedOdometry > readOdometry()
std::shared_ptr< Base > shared_ptr
Incremental update functionality (ISAM2) for BayesTree, with fluid relinearization.
vector< RangeTriple > readTriples()
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
NonlinearISAM isam(relinearizeInterval)
Key symbol(unsigned char c, std::uint64_t j)
Class compose(const Class &g) const
std::tuple< double, size_t, double > RangeTriple
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
std::vector< float > Values
ofstream os("timeSchurFactors.csv")
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
Double_ range(const Point2_ &p, const Point2_ &q)
int main(int argc, char **argv)
static EIGEN_DEPRECATED const end_t end
void insert(Key j, const Value &val)
pair< double, Pose2 > TimedOdometry
Pose2 odometry(2.0, 0.0, 0.0)
utility functions for loading datasets
Values calculateEstimate() const
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
All noise models live in the noiseModel namespace.