-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added templates and generation for simulated services
- Loading branch information
1 parent
8fe70f3
commit e0d02d3
Showing
3 changed files
with
131 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* KINOVA (R) KORTEX (TM) | ||
* | ||
* Copyright (c) 2019 Kinova inc. All rights reserved. | ||
* | ||
* This software may be modified and distributed under the | ||
* terms of the BSD 3-Clause license. | ||
* | ||
* Refer to the LICENSE file for details. | ||
* | ||
*/ | ||
|
||
/* | ||
* This file has been auto-generated and should not be modified. | ||
*/ | ||
|
||
{% for include_file_name in include_file_names -%} | ||
#include "{{include_file_name}}" | ||
{% endfor -%} | ||
#include "{{current_header_filename}}" | ||
|
||
{{package.short_name}}SimulationServices::{{package.short_name}}SimulationServices(ros::NodeHandle& node_handle): | ||
I{{package.short_name}}Services(node_handle) | ||
{ | ||
m_pub_Error = m_node_handle.advertise<kortex_driver::KortexError>("kortex_error", 1000); | ||
{%- for method in package.methods -%} | ||
{%- if method.is_notification_rpc %} | ||
m_pub_{{method.name}} = m_node_handle.advertise<kortex_driver::{{method_prepend_rpc_package_name}}{{method.name|replace("Topic", "")}}Notification>("{{method.name_lowercase_with_underscores}}", 1000); | ||
m_is_activated_{{method.name}} = false; | ||
{%- endif -%} | ||
{%- endfor %} | ||
|
||
m_serviceSetDeviceID = m_node_handle.advertiseService("{{package.short_name_lowercase_with_underscores}}/set_device_id", &{{package.short_name}}SimulationServices::SetDeviceID, this); | ||
m_serviceSetApiOptions = m_node_handle.advertiseService("{{package.short_name_lowercase_with_underscores}}/set_api_options", &{{package.short_name}}SimulationServices::SetApiOptions, this); | ||
{% for method in package.methods %} | ||
m_service{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}} = m_node_handle.advertiseService("{{package.short_name_lowercase_with_underscores}}/{%- if method.prepend_on_notification -%}activate_publishing_of_{%- endif -%}{{method.name_lowercase_with_underscores}}", &{{package.short_name}}SimulationServices::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}, this); | ||
{%- endfor %} | ||
} | ||
|
||
bool {{package.short_name}}SimulationServices::SetDeviceID(kortex_driver::SetDeviceID::Request &req, kortex_driver::SetDeviceID::Response &res) | ||
{ | ||
ROS_WARN_ONCE("The SetDeviceID service is not implemented in simulation, and has no effect."); | ||
return true; | ||
} | ||
|
||
bool {{package.short_name}}SimulationServices::SetApiOptions(kortex_driver::SetApiOptions::Request &req, kortex_driver::SetApiOptions::Response &res) | ||
{ | ||
ROS_WARN_ONCE("The SetDeviceID service is not implemented in simulation, and has no effect."); | ||
return true; | ||
} | ||
|
||
{% for method in package.methods %} | ||
bool {{package.short_name}}SimulationServices::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}(kortex_driver::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}::Request &req, kortex_driver::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}::Response &res) | ||
{ | ||
{% if method.is_rpc_deprecated -%} | ||
ROS_WARN("The {{package.short_name_lowercase_with_underscores}}/{%- if method.prepend_on_notification -%}activate_publishing_of_{%- endif -%}{{method.name_lowercase_with_underscores}} service is now deprecated and will be removed in a future release."); | ||
{% endif -%} | ||
|
||
{%- if method.is_notification_rpc %} | ||
m_is_activated_{{method.name}} = true; | ||
{%- endif %} | ||
|
||
if ({{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}Handler) | ||
{ | ||
res = {{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}Handler(req); | ||
} | ||
else | ||
{ | ||
ROS_WARN_ONCE("The simulation handler for {{package.short_name_lowercase_with_underscores}}/{%- if method.prepend_on_notification -%}activate_publishing_of_{%- endif -%}{{method.name_lowercase_with_underscores}} is not implemented, so the service calls will return the default response."); | ||
} | ||
return true; | ||
} | ||
{%- if method.is_notification_rpc %} | ||
void {{package.short_name}}SimulationServices::cb_{{method.name}}({{method.notification_message_cpp_namespace}}::{{method.name|replace("Topic", "")}}Notification notif) | ||
{ | ||
kortex_driver::{{method.name|replace("Topic", "")}}Notification ros_msg; | ||
ToRosData(notif, ros_msg); | ||
m_pub_{{method.name}}.publish(ros_msg); | ||
} | ||
{%- endif %} | ||
{% endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* KINOVA (R) KORTEX (TM) | ||
* | ||
* Copyright (c) 2019 Kinova inc. All rights reserved. | ||
* | ||
* This software may be modified and distributed under the | ||
* terms of the BSD 3-Clause license. | ||
* | ||
* Refer to the LICENSE file for details. | ||
* | ||
*/ | ||
|
||
/* | ||
* This file has been auto-generated and should not be modified. | ||
*/ | ||
|
||
#ifndef _KORTEX_{{package.short_name|upper}}_SIMULATION_SERVICES_H_ | ||
#define _KORTEX_{{package.short_name|upper}}_SIMULATION_SERVICES_H_ | ||
|
||
#include "{{current_interface_header_filename}}" | ||
|
||
using namespace std; | ||
|
||
class {{package.short_name}}SimulationServices : public I{{package.short_name}}Services | ||
{ | ||
public: | ||
{{package.short_name}}SimulationServices(ros::NodeHandle& node_handle); | ||
|
||
virtual bool SetDeviceID(kortex_driver::SetDeviceID::Request &req, kortex_driver::SetDeviceID::Response &res) override; | ||
virtual bool SetApiOptions(kortex_driver::SetApiOptions::Request &req, kortex_driver::SetApiOptions::Response &res) override; | ||
{%- for method in package.methods %} | ||
std::function<kortex_driver::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}::Response&(kortex_driver::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}::Request&)> {{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}Handler = nullptr; | ||
virtual bool {{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}(kortex_driver::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}::Request &req, kortex_driver::{{method.prepend_rpc_package_name}}{{method.prepend_on_notification}}{{method.name}}::Response &res) override; | ||
{%- if method.is_notification_rpc %} | ||
virtual void cb_{{method.name}}({{method.notification_message_cpp_namespace}}::{{method.prepend_rpc_package_name}}{{method.name|replace("Topic", "")}}Notification notif) override; | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
}; | ||
#endif | ||
|