iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test-GaussianPDF.C
Go to the documentation of this file.
1 /*! @file
2  @author Unknown
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
35 
36 NRT_CREATE_STATE_FIELD_GROUP(Position2D,(x)(y));
37 NRT_CREATE_STATE_FIELD_GROUP(Velocity2D,(x)(y));
38 
40 
41 NRT_CREATE_STATE_FIELD_GROUP(Acceleration2D,(x)(y));
42 
43 int main()
44 {
46 
47  // Write to the mean elements
48  vehicle.mean<Position2D::x>() = 1;
49  vehicle.mean<Position2D::y>() = 2;
50  vehicle.mean<Velocity2D>() = Eigen::Vector2d(3, 4);
51  vehicle.mean<Velocity2D>() << 3, 4;
52 
53  // Read from the mean elements
54  double pos_x_mean = vehicle.mean<Position2D::x>();
55  double pos_y_mean = vehicle.mean<Position2D::y>();
56  Eigen::Vector2d vel_mean = vehicle.mean<Velocity2D>();
57  std::cout << "Mean Position x: " << pos_x_mean << std::endl;
58  std::cout << "Mean Position y: " << pos_y_mean << std::endl;
59  std::cout << "Mean Velocity: " << std::endl << vel_mean << std::endl;
60 
61  // Grab the entire mean vector
62  Eigen::Vector4d mean = vehicle.mean<>();
63  std::cout << "Mean: " << std::endl << mean << std::endl;
64 
65  // Write to some covariance elements
66  vehicle.covariance<Position2D::x, Position2D::y>() = 1;
67  vehicle.covariance<Position2D::x>() = 2;
68  vehicle.covariance<Velocity2D>() << 3, 4,
69  4, 6;
70 
71  // Read from some covariance elements
72  double pos_xy_cov = vehicle.covariance<Position2D::x, Position2D::y>();
73  double pos_xx_cov = vehicle.covariance<Position2D::x>();
74  Eigen::Matrix2d vel_cov = vehicle.covariance<Velocity2D>();
75  std::cout << "Covariance Position xy: " << pos_xy_cov << std::endl;
76  std::cout << "Covariance Position xx: " << pos_xx_cov << std::endl;
77  std::cout << "Covariance Velocity: " << std::endl << vel_cov << std::endl;
78 
79  vehicle.covariance<Position2D::x, Velocity2D::y>() = 3;
80  Eigen::Matrix2d posVelCovariance = vehicle.covariance<Position2D, Velocity2D>();
81  std::cout << "---" << std::endl;
82  std::cout << posVelCovariance << std::endl;
83 
84  std::cout << "---" << std::endl;
85  std::cout << vehicle.covariance<>() << std::endl;
86 
87 
88  // The following will cause nicely-worded compile time errors
89  // vehicle.mean<Acceleration2D>();
90  // vehicle.mean<Acceleration2D::x>();
91 
92  return 0;
93 }