Documentation / v1.0 / Core / Library

From emss Framework - iRobot Create C++ Framework

Jump to: navigation, search

You are here: Documentation / v1.0 / Core / Library


Contents

[edit] Library

The Library package is not considered a Core component, but however is an important part of the emss Core as it provides a substantial amount of functionality. It is a collection of classes which are used by many different components, such as math structures or debugging routines. Some trivial Library classes such as SleeperThread, Util, and TerrainPoint are not discussed in further detail.

[edit] Vector2T

Files:

Library/Math/vector2.h Licensed under GPLv3

Vector2T is an abstraction of a two-dimensional vector. It realizes most of the mathematical operations operable on vectors, such as addition, scalar multiplication, dot products, et cetera. Vector2T is a template class supporting different internal data types such as doubles and floats, and has three defined typedefs of Vector2D (double), Vector2F (float), and Vector2L (long double).

  // Basic vector operations and computations
  Vector2D v1(0.5,0.8);
  Vector2D v2(4.0,2.2);
  Vector2D v3 = v1 + (v2*2);
  double distance = Vector2D::dist(v1,v2);
  double angle = Vector2D::angle(v1,v2);

The original Vector2T class was implemented by our advisor Prof. Dr. Joachim Wirth.

[edit] Trafo2T

Files:

Library/Math/trafo2.h Licensed under GPLv3

Two-dimensional transformation matrices such as rotation matrices can be realized using the Trafo2T template class. Just as the Vector2T class, mathematical operations on transformation matrices have been implemented. There are three defined typedefs of Trafo2D (double), Trafo2F (float), and Trafo2L (long double). Multiple transformations can be appended by using the * operator.

  // Basic rotation and translation
  Trafo2D t1 = Trafo2D::trans(6.0,5.0) * Trafo2D::rot(Rad(45));
  Trafo2D t2 = Trafo2D::trans(1.0,1.0);
  Trafo2D t3 = t2 * t1;

The original Trafo2T class was implemented by our advisor Prof. Dr. Joachim Wirth.

[edit] Spline1T

Files:

Library/Math/spline1.h Licensed under GPLv3

This template class implements different one-dimensional spline approaches. As discussed in section 3.4, splines are smooth and efficient curve interpolations of a finite set of nodes. The different kernels we implemented include SplineKernalBruenner, SplineKernelNRNatural, and SplineKernelStoer. Nodes can be freely added and removed from the spline. When a call to getValue(node,t) is made, Spline1T automatically decides whether or not an internal recalculation of the spline coefficients is needed, maximizing the ease of use to the user. Each kernel has its own implementation of getValue(node,t), getFirstDerivative(node,t), and getSecondDerivative(node,t). Two dimensional curves can easily be realized by using two instances of Spline1T, as mentioned in Section 3.3. There are three defined typedefs of Spline1D (double), Spline1F (float), and Spline1L (long double).

  // Create two splines, one for each dimension and add some nodes
  Spline1D Sx = Spline1D(SplineKernelNRNatural);
  Spline1D Sy = Spline1D(SplineKernelNRNatural);
  Sx.addNode(0.0); Sy.addNode(0.0);
  Sx.addNode(1.4); Sy.addNode(1.1);
  Sx.addNode(3.1); Sy.addNode(2.0);
  Sx.addNode(6.7); Sy.addNode(5.4);
  Sx.addNode(8.0); Sy.addNode(1.1);
  // Draw each spline segment with fixed number of dots
  int DOTS_PER_SEGMENT = 20;
  for (int n = 0; n < Sx.getNodeCount() - n; n++) {
         for (int t = 1; t < DOTS_PER_SEGMENT; t++) {
                 double px = Sx.getValue(n, (double)t / (double)DOTS_PER_SEGMENT);
                 double py = Sy.getValue(n, (double)t / (double)DOTS_PER_SEGMENT);
                 graph.drawPoint(px, py);
         }
  }

[edit] Debug

Files:

Library/Debug.h Licensed under GPLv3

The Debug class offers some debugging assistance, especially during runtime, by encapsulating common console commands. Printing color-formatted sets of values along with an automatic timestamp can be very easily achieved. Additionally, calling setOutput(widget) allows an application to re-route all debugging information to any given text widget.

  // Re-route debugging information to our widget
  Debug::setOutput(consoleWidget);
  // Simple debug messages
  Debug::print(“The shorthand value of PI is %1, while e is %2”, 3.14, 2.72);
  Debug::warning(“This is a warning”);