Ver código fonte

lsm303: Modifying C++ example

Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
Zion Orent 10 anos atrás
pai
commit
9d48301402
1 arquivos alterados com 11 adições e 3 exclusões
  1. 11
    3
      examples/lsm303.cxx

+ 11
- 3
examples/lsm303.cxx Ver arquivo

30
 int
30
 int
31
 main(int argc, char **argv)
31
 main(int argc, char **argv)
32
 {
32
 {
33
+	// Instantiate LSM303 compass on I2C
33
     upm::LSM303 *sensor = new upm::LSM303(0);
34
     upm::LSM303 *sensor = new upm::LSM303(0);
34
 
35
 
36
+    // Get the coordinate data
35
     sensor->getCoordinates();
37
     sensor->getCoordinates();
36
-    int16_t* coor = sensor->getRawCoorData(); // in XZY order
38
+    int16_t* coor = sensor->getRawCoorData(); // in XYZ order. 
39
+    // The sensor returns XZY, but the driver compensates and makes it XYZ
40
+    
41
+    // Print out the X, Y, and Z coordinate data using two different methods
37
     std::cout << "coor: rX " << (int)coor[0]
42
     std::cout << "coor: rX " << (int)coor[0]
38
-              << " - rY " << (int)coor[2]  // note: index is 2
39
-              << " - rZ " << (int)coor[1]  // note: index is 1
43
+              << " - rY " << (int)coor[1]
44
+              << " - rZ " << (int)coor[2]
40
               << std::endl;
45
               << std::endl;
41
     std::cout << "coor: gX " << sensor->getCoorX()
46
     std::cout << "coor: gX " << sensor->getCoorX()
42
               << " - gY " << sensor->getCoorY()
47
               << " - gY " << sensor->getCoorY()
43
               << " - gZ " << sensor->getCoorZ()
48
               << " - gZ " << sensor->getCoorZ()
44
               << std::endl;
49
               << std::endl;
45
 
50
 
51
+    // Get and print out the heading
46
     std::cout << "heading: "
52
     std::cout << "heading: "
47
               << sensor->getHeading()
53
               << sensor->getHeading()
48
               << std::endl;
54
               << std::endl;
49
 
55
 
56
+    // Get the acceleration
50
     sensor->getAcceleration();
57
     sensor->getAcceleration();
51
     int16_t* accel = sensor->getRawAccelData();
58
     int16_t* accel = sensor->getRawAccelData();
59
+    // Print out the X, Y, and Z acceleration data using two different methods
52
     std::cout << "acc: rX " << (int)accel[0]
60
     std::cout << "acc: rX " << (int)accel[0]
53
               << " - rY " << (int)accel[1]
61
               << " - rY " << (int)accel[1]
54
               << " - Z " << (int)accel[2]
62
               << " - Z " << (int)accel[2]