Skip to content

Commit ad7a984

Browse files
authored
Fix/navsat transform (#652)
* Add test for simple interface check on navsat_transform
1 parent b4eb606 commit ad7a984

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ if(BUILD_TESTING)
260260
ament_add_gtest(test_navsat_conversions test/test_navsat_conversions.cpp)
261261
target_link_libraries(test_navsat_conversions ${library_name})
262262

263+
#### NAVSAT TRANSFORM TESTS ####
264+
ament_add_gtest_executable(test_navsat_transform test/test_navsat_transform.cpp)
265+
target_link_libraries(test_navsat_transform ${library_name})
266+
rosidl_target_interfaces(test_navsat_transform
267+
${PROJECT_NAME} "rosidl_typesupport_cpp")
268+
ament_add_test(test_navsat_transform
269+
GENERATE_RESULT_FOR_RETURN_CODE_ZERO
270+
TIMEOUT 100
271+
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test/test_navsat_transform.launch.py"
272+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
273+
)
274+
263275
ament_add_gtest_executable(test_ros_robot_localization_listener
264276
test/test_ros_robot_localization_listener.cpp)
265277
target_link_libraries(test_ros_robot_localization_listener ${library_name})
@@ -295,6 +307,7 @@ if(BUILD_TESTING)
295307
#test_ekf_localization_node_bag3
296308
test_robot_localization_estimator
297309
test_navsat_conversions
310+
test_navsat_transform
298311
test_ros_robot_localization_listener
299312
test_ros_robot_localization_listener_publisher
300313
#test_ukf_localization_node_bag1

src/navsat_transform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ NavSatTransform::NavSatTransform(const rclcpp::NodeOptions & options)
116116
"Please use 'broadcast_cartesian_transform' instead.");
117117
} else {
118118
broadcast_cartesian_transform_ =
119-
this->declare_parameter("broadcast_utm_transform", broadcast_cartesian_transform_);
119+
this->declare_parameter("broadcast_cartesian_transform", broadcast_cartesian_transform_);
120120
}
121121

122122
broadcast_cartesian_transform_as_parent_frame_ =

test/test_navsat_transform.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2021, Charles River Analytics, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above
12+
* copyright notice, this list of conditions and the following
13+
* disclaimer in the documentation and/or other materials provided
14+
* with the distribution.
15+
* 3. Neither the name of the copyright holder nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
34+
#include <gtest/gtest.h>
35+
36+
#include <robot_localization/navsat_conversions.hpp>
37+
#include <chrono>
38+
#include <memory>
39+
#include <string>
40+
41+
#include "robot_localization/srv/set_datum.hpp"
42+
#include "robot_localization/srv/from_ll.hpp"
43+
#include "rclcpp/rclcpp.hpp"
44+
45+
46+
using namespace std::chrono_literals;
47+
48+
TEST(NavSatTransformUTMJumpTest, UtmTest)
49+
{
50+
auto node_ = rclcpp::Node::make_shared("test_navsat_transform");
51+
auto setDatumClient = node_->create_client<robot_localization::srv::SetDatum>("/datum");
52+
53+
EXPECT_TRUE(setDatumClient->wait_for_service(5s));
54+
55+
// Initialise the navsat_transform node to a UTM zone
56+
auto setDatumRequest = std::make_shared<robot_localization::srv::SetDatum::Request>();
57+
setDatumRequest->geo_pose.position.latitude = 1;
58+
setDatumRequest->geo_pose.position.longitude = 4;
59+
setDatumRequest->geo_pose.orientation.w = 1;
60+
61+
auto setDatumResponse = setDatumClient->async_send_request(setDatumRequest);
62+
auto ret = rclcpp::spin_until_future_complete(node_, setDatumResponse, 5s);
63+
EXPECT_EQ(ret, rclcpp::FutureReturnCode::SUCCESS);
64+
}
65+
66+
int main(int argc, char ** argv)
67+
{
68+
rclcpp::init(argc, argv);
69+
::testing::InitGoogleTest(&argc, argv);
70+
int ret = RUN_ALL_TESTS();
71+
rclcpp::shutdown();
72+
73+
return ret;
74+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
import launch
3+
from launch import LaunchDescription
4+
import launch_ros.actions
5+
import yaml
6+
import sys
7+
from launch.substitutions import EnvironmentVariable
8+
import launch.actions
9+
from launch.actions import DeclareLaunchArgument
10+
from launch_testing.legacy import LaunchTestService
11+
from launch.actions import ExecuteProcess
12+
from launch import LaunchService
13+
from ament_index_python.packages import get_package_prefix
14+
15+
def generate_launch_description():
16+
#*****test_navsat_transform.test*****
17+
navsat_transform = launch_ros.actions.Node(
18+
package='robot_localization',
19+
executable='navsat_transform_node',
20+
name='test_navsat_transform',
21+
output='screen',
22+
)
23+
24+
return LaunchDescription([
25+
navsat_transform,
26+
])
27+
28+
29+
def main(argv=sys.argv[1:]):
30+
ld = generate_launch_description()
31+
32+
test1_action = ExecuteProcess(
33+
cmd=[get_package_prefix('robot_localization') + '/lib/robot_localization/test_navsat_transform'],
34+
output='screen',
35+
)
36+
37+
lts = LaunchTestService()
38+
lts.add_test_action(ld, test1_action)
39+
ls = LaunchService(argv=argv)
40+
ls.include_launch_description(ld)
41+
return lts.run(ls)
42+
43+
if __name__ == '__main__':
44+
sys.exit(main())

0 commit comments

Comments
 (0)