Skip to content

Commit 33d4493

Browse files
committed
rtt_ros_msgs/rtt_ros_deployment: added service eval (rtt_ros_msgs/Eval) to the rosdeployment service
This service evaluates arbitrary commands in the scripting service of the deployer.
1 parent a82d84f commit 33d4493

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

rtt_ros_msgs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ find_package(catkin REQUIRED COMPONENTS message_generation std_msgs)
3737
## Generate services in the 'srv' folder
3838
add_service_files(
3939
FILES
40+
Eval.srv
4041
RunScript.srv
4142
GetPeerList.srv
4243
)

rtt_ros_msgs/srv/Eval.srv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
string code
2+
---
3+
bool success

rtt_rosdeployment/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include_directories(${catkin_INCLUDE_DIRS})
88
orocos_use_package(ocl-deployment)
99

1010
orocos_plugin(rtt_rosdeployment src/rtt_rosdeployment_service.cpp)
11-
target_link_libraries(rtt_rosdeployment ${catkin_LIBRARIES})
11+
target_link_libraries(rtt_rosdeployment ${catkin_LIBRARIES} ${OROCOS-RTT_RTT-SCRIPTING_LIBRARY})
1212

1313
orocos_generate_package(
1414
DEPENDS rtt_ros_msgs

rtt_rosdeployment/package.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
<export>
2626
<rtt_ros>
2727
<plugin_depend>rtt_rosnode</plugin_depend>
28-
<plugin_depend>rtt_ros_msgs</plugin_depend>
28+
<!--
29+
rtt_ros_msgs is not an RTT plugin
30+
<plugin_depend>rtt_ros_msgs</plugin_depend>
31+
-->
2932
</rtt_ros>
3033
</export>
3134
</package>

rtt_rosdeployment/src/rtt_rosdeployment_service.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <rtt/plugin/Plugin.hpp>
44
#include <rtt/plugin/ServicePlugin.hpp>
55
#include <rtt/internal/GlobalService.hpp>
6+
#include <rtt/scripting/Scripting.hpp>
67

8+
#include <rtt_ros_msgs/Eval.h>
79
#include <rtt_ros_msgs/RunScript.h>
810
#include <rtt_ros_msgs/GetPeerList.h>
911

@@ -24,16 +26,23 @@ class ROSDeploymentService : public RTT::Service
2426

2527
ros::NodeHandle nh_;
2628

29+
ros::ServiceServer eval_service_;
2730
ros::ServiceServer run_script_service_;
2831
ros::ServiceServer get_peer_list_service_;
2932

33+
bool eval_cb(
34+
rtt_ros_msgs::Eval::Request& request,
35+
rtt_ros_msgs::Eval::Response& response);
36+
3037
bool run_script_cb(
3138
rtt_ros_msgs::RunScript::Request& request,
3239
rtt_ros_msgs::RunScript::Response& response);
3340

3441
bool get_peer_list_cb(
3542
rtt_ros_msgs::GetPeerList::Request& request,
3643
rtt_ros_msgs::GetPeerList::Response& response);
44+
45+
RTT::OperationCaller<bool(std::string const&)> eval_;
3746
};
3847

3948

@@ -44,13 +53,25 @@ ROSDeploymentService::ROSDeploymentService(OCL::DeploymentComponent* deployer) :
4453
{
4554
if(deployer_) {
4655
// Create services
56+
eval_service_ = nh_.advertiseService("eval",&ROSDeploymentService::eval_cb,this);
4757
run_script_service_ = nh_.advertiseService("run_script",&ROSDeploymentService::run_script_cb,this);
4858
get_peer_list_service_ = nh_.advertiseService("get_peer_list",&ROSDeploymentService::get_peer_list_cb,this);
59+
60+
eval_ = deployer_->getProvider<RTT::Scripting>("scripting")->eval;
4961
} else {
5062
RTT::log(RTT::Error) << "Attempted to load the rosdeployment service on a TaskContext which is not an OCL::DeploymentComponent. No ROS services will be advertised." << RTT::endlog();
5163
}
5264
}
5365

66+
bool ROSDeploymentService::eval_cb(
67+
rtt_ros_msgs::Eval::Request& request,
68+
rtt_ros_msgs::Eval::Response& response)
69+
{
70+
if (!eval_.ready()) return false;
71+
response.success = eval_(request.code);
72+
return true;
73+
}
74+
5475
bool ROSDeploymentService::run_script_cb(
5576
rtt_ros_msgs::RunScript::Request& request,
5677
rtt_ros_msgs::RunScript::Response& response)

0 commit comments

Comments
 (0)