Skip to content

Commit 74b7309

Browse files
Add ros_publish test + external interface.
1 parent 0935ed7 commit 74b7309

9 files changed

+609
-17
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ include(cmake/ros.cmake)
3131
compute_project_args(PROJECT_ARGS LANGUAGES CXX)
3232
project(${PROJECT_NAME} ${PROJECT_ARGS})
3333

34-
if(NOT CMAKE_CXX_STANDARD)
35-
set(CMAKE_CXX_STANDARD 14)
36-
endif()
34+
#if(NOT CMAKE_CXX_STANDARD)
35+
set(CMAKE_CXX_STANDARD 17)
36+
#endif()
3737

3838
cmake_policy(SET CMP0057 NEW)
3939
find_package(ament_cmake REQUIRED)

tests/CMakeLists.txt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ if(BUILD_TESTING)
1111
ament_lint_auto_find_test_dependencies()
1212

1313
# Library for sot_external_interface
14-
add_library(impl_test_sot_external_interface SHARED
15-
impl_test_sot_external_interface)
16-
17-
target_link_libraries(impl_test_sot_external_interface
18-
PUBLIC sot-core::sot-core)
19-
14+
add_library(impl_test_library
15+
SHARED
16+
impl_test_sot_external_interface.cpp
17+
impl_test_sot_mock_device.cpp)
18+
19+
target_include_directories(impl_test_library
20+
PUBLIC include
21+
)
22+
target_link_libraries(impl_test_library
23+
PUBLIC sot-core::sot-core
24+
)
25+
ament_target_dependencies(impl_test_library PUBLIC
26+
dynamic_graph_bridge_msgs
27+
rclcpp
28+
rcl_interfaces
29+
std_srvs
30+
)
2031
# Executable for SotLoaderBasic test
2132
add_executable(test_sot_loader_basic test_sot_loader_basic.cpp)
2233
target_include_directories(
@@ -42,7 +53,7 @@ if(BUILD_TESTING)
4253
DESTINATION lib/${PROJECT_NAME})
4354

4455
# Install library for tests
45-
install(TARGETS impl_test_sot_external_interface DESTINATION lib)
56+
install(TARGETS impl_test_library DESTINATION lib)
4657

4758
install(DIRECTORY launch urdf DESTINATION share/${PROJECT_NAME})
4859

tests/impl_test_sot_external_interface.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
#include "impl_test_sot_external_interface.hh"
22

3-
ImplTestSotExternalInterface::ImplTestSotExternalInterface() {
3+
#include "dynamic_graph_bridge/ros.hpp"
4+
5+
using namespace dynamic_graph_bridge;
6+
7+
ImplTestSotExternalInterface::ImplTestSotExternalInterface()
8+
: device_(new ImplTestSotMockDevice("RobotName")) {
9+
init();
10+
}
11+
12+
ImplTestSotExternalInterface::ImplTestSotExternalInterface(
13+
std::string RobotName)
14+
: device_(new ImplTestSotMockDevice(RobotName)) {
15+
init();
16+
}
17+
18+
ImplTestSotExternalInterface::ImplTestSotExternalInterface(
19+
const char RobotName[])
20+
: device_(new ImplTestSotMockDevice(RobotName)) {
21+
init();
22+
}
23+
24+
ImplTestSotExternalInterface::~ImplTestSotExternalInterface() {}
25+
26+
void ImplTestSotExternalInterface::init() {
427
std::vector<double> ctrl_vector;
528
ctrl_vector.resize(2);
629

@@ -19,9 +42,20 @@ ImplTestSotExternalInterface::ImplTestSotExternalInterface() {
1942
for (std::vector<double>::size_type i = 0; i < 6; i++) ctrl_vector[i] = 0.0;
2043
ctrl_vector[6] = 0.0;
2144
named_base_ff_vec_.setValues(ctrl_vector);
22-
}
2345

24-
ImplTestSotExternalInterface::~ImplTestSotExternalInterface() {}
46+
// rosInit is called here only to initialize ros.
47+
// No spinner is initialized.
48+
py_interpreter_srv_ =
49+
boost::shared_ptr<dynamic_graph_bridge::RosPythonInterpreterServer>(
50+
new dynamic_graph_bridge::RosPythonInterpreterServer());
51+
52+
RosNodePtr py_inter_ptr = get_ros_node("python_interpreter");
53+
// Set the control time step parameter to 0.001
54+
double ts = 0.001;
55+
56+
py_inter_ptr->declare_parameter<double>("/sot_controller/dt", ts);
57+
device_->timeStep(ts);
58+
}
2559

2660
void ImplTestSotExternalInterface::setupSetSensors(
2761
std::map<std::string, dynamicgraph::sot::SensorValues> &) {

tests/impl_test_sot_external_interface.hh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#ifndef _DGB_IMPL_TEST_SOT_EXTERNAL_INTEFACE_HH_
22
#define _DGB_IMPL_TEST_SOT_EXTERNAL_INTEFACE_HH_
33

4+
#include <dynamic_graph_bridge/ros_python_interpreter_server.hpp>
45
#include <iostream>
56
#include <sot/core/abstract-sot-external-interface.hh>
67

8+
#include "impl_test_sot_mock_device.hh"
9+
10+
namespace dynamic_graph_bridge {
711
class ImplTestSotExternalInterface
812
: public dynamicgraph::sot::AbstractSotExternalInterface {
913
public:
1014
ImplTestSotExternalInterface();
15+
ImplTestSotExternalInterface(const char robotName[]);
16+
ImplTestSotExternalInterface(std::string robotName);
1117
virtual ~ImplTestSotExternalInterface();
1218

1319
virtual void setupSetSensors(
@@ -25,12 +31,28 @@ class ImplTestSotExternalInterface
2531

2632
virtual void setNoIntegration(void);
2733

34+
/// Embedded python interpreter accessible via Corba/ros
35+
boost::shared_ptr<dynamic_graph_bridge::RosPythonInterpreterServer>
36+
py_interpreter_srv_;
37+
2838
protected:
2939
// Named ctrl vector
3040
dynamicgraph::sot::ControlValues named_ctrl_vec_;
3141

3242
// Named base free flyer vector
3343
dynamicgraph::sot::ControlValues named_base_ff_vec_;
34-
};
3544

45+
// Update output port with the control computed from the
46+
// dynamic graph.
47+
void updateRobotState(std::vector<double> &anglesIn);
48+
49+
/// Run a python command
50+
void runPython(std::ostream &file, const std::string &command,
51+
dynamicgraph::Interpreter &interpreter);
52+
53+
void init();
54+
55+
ImplTestSotMockDevice *device_;
56+
};
57+
} // namespace dynamic_graph_bridge
3658
#endif

0 commit comments

Comments
 (0)