|
| 1 | +/* |
| 2 | + * Description: Test Supervisor device API |
| 3 | + * This file contains tests of reset simulation method |
| 4 | + */ |
| 5 | + |
| 6 | +#include <webots/robot.h> |
| 7 | +#include <webots/supervisor.h> |
| 8 | + |
| 9 | +#include "../../../lib/ts_assertion.h" |
| 10 | +#include "../../../lib/ts_utils.h" |
| 11 | + |
| 12 | +#define TIME_STEP 32 |
| 13 | + |
| 14 | +int main(int argc, char **argv) { |
| 15 | + ts_setup(argv[1]); |
| 16 | + |
| 17 | + const double initial_translation[3] = {0, 0, 1}; |
| 18 | + const double new_translation[3] = {1, 0, 0}; |
| 19 | + WbFieldRef translation_field = wb_supervisor_node_get_field(wb_supervisor_node_get_from_def("SOLID"), "translation"); |
| 20 | + if (strcmp(argv[1], "supervisor_reset_simulation_fields_resetter") == 0) { |
| 21 | + wb_robot_step(TIME_STEP); |
| 22 | + wb_robot_step(TIME_STEP); |
| 23 | + |
| 24 | + // <Other controller verifies SOLID's inital position> |
| 25 | + |
| 26 | + wb_robot_step(TIME_STEP); |
| 27 | + wb_supervisor_simulation_reset(); |
| 28 | + wb_robot_step(TIME_STEP); // We have to wait another step or else the reset will overwrite the new value |
| 29 | + wb_supervisor_field_set_sf_vec3f(translation_field, new_translation); |
| 30 | + } else { |
| 31 | + wb_robot_step(TIME_STEP); |
| 32 | + wb_robot_step(TIME_STEP); |
| 33 | + const double *first_translation = wb_supervisor_field_get_sf_vec3f(translation_field); |
| 34 | + ts_assert_vec3_equal( |
| 35 | + first_translation[0], first_translation[1], first_translation[2], initial_translation[0], initial_translation[1], |
| 36 | + initial_translation[2], "SOLID's initial position should be [%f, %f, %f] not [%f, %f, %f]", initial_translation[0], |
| 37 | + initial_translation[1], initial_translation[2], first_translation[0], first_translation[1], first_translation[2]); |
| 38 | + wb_robot_step(TIME_STEP); |
| 39 | + |
| 40 | + // <Other controller resets the simulation> |
| 41 | + |
| 42 | + wb_robot_step(TIME_STEP); |
| 43 | + |
| 44 | + // <Other controller updates SOLID's position> |
| 45 | + |
| 46 | + wb_robot_step(TIME_STEP); |
| 47 | + const double *second_translation = wb_supervisor_field_get_sf_vec3f(translation_field); |
| 48 | + ts_assert_vec3_equal( |
| 49 | + second_translation[0], second_translation[1], second_translation[2], new_translation[0], new_translation[1], |
| 50 | + new_translation[2], "SOLID's position should be [%f, %f, %f] not [%f, %f, %f] after reset", new_translation[0], |
| 51 | + new_translation[1], new_translation[2], second_translation[0], second_translation[1], second_translation[2]); |
| 52 | + } |
| 53 | + |
| 54 | + ts_send_success(); |
| 55 | + return EXIT_SUCCESS; |
| 56 | +} |
0 commit comments