James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Committer:
jamesheavey
Date:
Wed May 08 18:44:16 2019 +0000
Revision:
124:d635e3154bf3
testing done

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 124:d635e3154bf3 1 #ifndef LASER_TEST_H
jamesheavey 124:d635e3154bf3 2 #define LASER_TEST_H
jamesheavey 124:d635e3154bf3 3
jamesheavey 124:d635e3154bf3 4 /**
jamesheavey 124:d635e3154bf3 5 * \brief Check that Laser object goes to correct position when moved
jamesheavey 124:d635e3154bf3 6 *
jamesheavey 124:d635e3154bf3 7 * \returns true if all the tests passed
jamesheavey 124:d635e3154bf3 8 */
jamesheavey 124:d635e3154bf3 9 bool Laser_test_movement()
jamesheavey 124:d635e3154bf3 10 {
jamesheavey 124:d635e3154bf3 11 // Initialise Laser object at -10,0 with velocity of y as -2
jamesheavey 124:d635e3154bf3 12 Laser _laser;
jamesheavey 124:d635e3154bf3 13 _laser.init();
jamesheavey 124:d635e3154bf3 14
jamesheavey 124:d635e3154bf3 15 int read_pos1x = _laser.get_x();
jamesheavey 124:d635e3154bf3 16 int read_pos1y = _laser.get_y();
jamesheavey 124:d635e3154bf3 17
jamesheavey 124:d635e3154bf3 18 // Read the position
jamesheavey 124:d635e3154bf3 19 printf("%f, %f\n", read_pos1x, read_pos1y);
jamesheavey 124:d635e3154bf3 20
jamesheavey 124:d635e3154bf3 21 // Set the x position to 10, 0
jamesheavey 124:d635e3154bf3 22 _laser.set_posx(10);
jamesheavey 124:d635e3154bf3 23
jamesheavey 124:d635e3154bf3 24 // Update the position
jamesheavey 124:d635e3154bf3 25 _laser.update();
jamesheavey 124:d635e3154bf3 26
jamesheavey 124:d635e3154bf3 27 int read_pos2x = _laser.get_x();
jamesheavey 124:d635e3154bf3 28 int read_pos2y = _laser.get_y();
jamesheavey 124:d635e3154bf3 29
jamesheavey 124:d635e3154bf3 30 // Read the position
jamesheavey 124:d635e3154bf3 31 printf("%f, %f\n", read_pos2x, read_pos2y);
jamesheavey 124:d635e3154bf3 32
jamesheavey 124:d635e3154bf3 33 // Now check that both the positions are as expected
jamesheavey 124:d635e3154bf3 34 bool success_flag = true;
jamesheavey 124:d635e3154bf3 35
jamesheavey 124:d635e3154bf3 36 // Fail the test if the initial position is wrong
jamesheavey 124:d635e3154bf3 37 if (read_pos1x != 0 || read_pos1y != 0) {
jamesheavey 124:d635e3154bf3 38 success_flag = false;
jamesheavey 124:d635e3154bf3 39 }
jamesheavey 124:d635e3154bf3 40 if (read_pos2x != 10 || read_pos2y != 0) {
jamesheavey 124:d635e3154bf3 41 success_flag = false;
jamesheavey 124:d635e3154bf3 42 }
jamesheavey 124:d635e3154bf3 43
jamesheavey 124:d635e3154bf3 44
jamesheavey 124:d635e3154bf3 45
jamesheavey 124:d635e3154bf3 46 return success_flag;
jamesheavey 124:d635e3154bf3 47 }
jamesheavey 124:d635e3154bf3 48 #endif