Skip to content

Add action interfaces for goal request and goal response #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rcljava_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(${PROJECT_NAME}_java_sources
"src/main/java/org/ros2/rcljava/exceptions/RCLReturn.java"
"src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java"
"src/main/java/org/ros2/rcljava/interfaces/Disposable.java"
"src/main/java/org/ros2/rcljava/interfaces/GoalRequestDefinition.java"
"src/main/java/org/ros2/rcljava/interfaces/GoalResponseDefinition.java"
"src/main/java/org/ros2/rcljava/interfaces/MessageDefinition.java"
"src/main/java/org/ros2/rcljava/interfaces/ServiceDefinition.java"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@

package org.ros2.rcljava.interfaces;

public interface ActionDefinition {}
public interface ActionDefinition {
Class<? extends GoalRequestDefinition> getSendGoalRequestType();
Class<? extends GoalResponseDefinition> getSendGoalResponseType();
Class<? extends MessageDefinition> getGetResultRequestType();
Class<? extends MessageDefinition> getGetResultResponseType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2020 Open Source Robotics Foundation, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ros2.rcljava.interfaces;

import java.util.List;

public interface GoalRequestDefinition<T extends ActionDefinition> extends MessageDefinition {
MessageDefinition getGoal();
List<Byte> getGoalUuid();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2020 Open Source Robotics Foundation, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ros2.rcljava.interfaces;

public interface GoalResponseDefinition<T extends ActionDefinition> extends MessageDefinition {
void accept(boolean accepted);
void setStamp(int sec, int nanosec);
}
40 changes: 40 additions & 0 deletions rosidl_generator_java/resource/action.java.em
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ expand_template(
template_basepath=template_basepath)

action_imports = [
'java.util.List',
'org.ros2.rcljava.common.JNIUtils',
'org.ros2.rcljava.interfaces.ActionDefinition',
'org.ros2.rcljava.interfaces.GoalRequestDefinition',
'org.ros2.rcljava.interfaces.GoalResponseDefinition',
'org.ros2.rcljava.interfaces.MessageDefinition',
'org.slf4j.Logger',
'org.slf4j.LoggerFactory',
]
Expand All @@ -76,6 +80,42 @@ import @(action_import);

public class @(type_name) implements ActionDefinition {

public static class SendGoalRequest extends @(type_name)_SendGoal_Request implements GoalRequestDefinition<@(type_name)> {
public List<Byte> getGoalUuid() {
// Return List since it's hash is based on the values (not the object pointer)
return super.getGoalId().getUuidAsList();
}
}

public static class SendGoalResponse extends @(type_name)_SendGoal_Response implements GoalResponseDefinition<@(type_name)> {
public void accept(boolean accepted) {
super.setAccepted(accepted);
}

public void setStamp(int sec, int nanosec) {
builtin_interfaces.msg.Time msg = new builtin_interfaces.msg.Time();
msg.setSec(sec);
msg.setNanosec(nanosec);
super.setStamp(msg);
}
}

public Class<? extends GoalRequestDefinition> getSendGoalRequestType() {
return SendGoalRequest.class;
}

public Class<? extends GoalResponseDefinition> getSendGoalResponseType() {
return SendGoalResponse.class;
}

public Class<? extends MessageDefinition> getGetResultRequestType() {
return @(type_name)_GetResult_Request.class;
}

public Class<? extends MessageDefinition> getGetResultResponseType() {
return @(type_name)_GetResult_Response.class;
}

private static final Logger logger = LoggerFactory.getLogger(@(type_name).class);

static {
Expand Down
2 changes: 1 addition & 1 deletion rosidl_generator_java/resource/msg.java.em
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import @('.'.join(member.type.namespaced_name()));
@[ end if]@
@[end for]@

public final class @(type_name) implements MessageDefinition {
public class @(type_name) implements MessageDefinition {

private static final Logger logger = LoggerFactory.getLogger(@(type_name).class);

Expand Down