Yufan Zhong / Mbed 2 deprecated GOLD_MINER

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Winch-test.h Source File

Winch-test.h

00001 #ifndef WINCH_TEST_H
00002 #define WINCH_TEST_H
00003 
00004 /**
00005  * \brief Check that Winch object goes to correct position when moved
00006  * 
00007  * \returns true if all the tests passed
00008  */
00009 bool Winch_test_movement()
00010 {
00011     // Initialise Winch object with a winch width of 12 and height of 6
00012     Winch winch;
00013     winch.init(6,12);
00014 
00015     // Set the position to 42,9
00016     Vector2D initial_pos = {42, 9};
00017     winch.set_pos(initial_pos);
00018 
00019     // Read the position
00020     Vector2D read_pos_1 = winch.get_pos();
00021     printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
00022 
00023     // Set the direction to E and mag to 0.2
00024     Direction d = E;
00025     float mag = 0.2;
00026 
00027     // Update the position
00028     winch.update(d,mag);
00029 
00030     // Read the position
00031     Vector2D read_pos_2 = winch.get_pos();
00032     printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
00033     
00034     // Now check that both the positions are as expected
00035     bool success_flag = true;
00036     
00037     // Fail the test if the initial position is wrong
00038     if (read_pos_1.x != 42 || read_pos_1.y != 9) {
00039         success_flag = false;
00040     }
00041     
00042     // Fail the test if the final position is wrong
00043     if (read_pos_2.x != 43 || read_pos_2.y != 9) {
00044         success_flag = false;
00045     }
00046 
00047     return success_flag;
00048 }
00049 #endif