Skip to content

Commit a0f46a4

Browse files
authored
Add action interfaces for goal request and goal response (#52)
* Add interfaces for action goal, result, and feedback Implementing these interfaces in the code generation template makes it easier to pass around these types in a generic way. Note, the 'final' modifier had to be removed from generated message types in order to extend goal, result, and feedback types in action definitions. Signed-off-by: Jacob Perron <[email protected]> * Add new definitions for action goal response and request Signed-off-by: Jacob Perron <[email protected]> * Add getter for UUID to SendGoalRequest Also make inner classes static. Signed-off-by: Jacob Perron <[email protected]> * Add getStamp method to GoalResponseDefinition Signed-off-by: Jacob Perron <[email protected]> * Partially revert "Add interfaces for action goal, result, and feedback" Partially revert commit dd04614. I don't think we need to aliases for the message types, but I'll add them back if they turn out to be useful. * Parameterize goal request and response interfaces on action type Signed-off-by: Jacob Perron <[email protected]> * Fix getGoalUuid implementation It should return a List, since it is hashable. Signed-off-by: Jacob Perron <[email protected]>
1 parent c012ba8 commit a0f46a4

File tree

6 files changed

+93
-2
lines changed

6 files changed

+93
-2
lines changed

rcljava_common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ set(${PROJECT_NAME}_java_sources
3838
"src/main/java/org/ros2/rcljava/exceptions/RCLReturn.java"
3939
"src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java"
4040
"src/main/java/org/ros2/rcljava/interfaces/Disposable.java"
41+
"src/main/java/org/ros2/rcljava/interfaces/GoalRequestDefinition.java"
42+
"src/main/java/org/ros2/rcljava/interfaces/GoalResponseDefinition.java"
4143
"src/main/java/org/ros2/rcljava/interfaces/MessageDefinition.java"
4244
"src/main/java/org/ros2/rcljava/interfaces/ServiceDefinition.java"
4345
)

rcljava_common/src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515

1616
package org.ros2.rcljava.interfaces;
1717

18-
public interface ActionDefinition {}
18+
public interface ActionDefinition {
19+
Class<? extends GoalRequestDefinition> getSendGoalRequestType();
20+
Class<? extends GoalResponseDefinition> getSendGoalResponseType();
21+
Class<? extends MessageDefinition> getGetResultRequestType();
22+
Class<? extends MessageDefinition> getGetResultResponseType();
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Copyright 2020 Open Source Robotics Foundation, Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.ros2.rcljava.interfaces;
17+
18+
import java.util.List;
19+
20+
public interface GoalRequestDefinition<T extends ActionDefinition> extends MessageDefinition {
21+
MessageDefinition getGoal();
22+
List<Byte> getGoalUuid();
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright 2020 Open Source Robotics Foundation, Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.ros2.rcljava.interfaces;
17+
18+
public interface GoalResponseDefinition<T extends ActionDefinition> extends MessageDefinition {
19+
void accept(boolean accepted);
20+
void setStamp(int sec, int nanosec);
21+
}

rosidl_generator_java/resource/action.java.em

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ expand_template(
6363
template_basepath=template_basepath)
6464

6565
action_imports = [
66+
'java.util.List',
6667
'org.ros2.rcljava.common.JNIUtils',
6768
'org.ros2.rcljava.interfaces.ActionDefinition',
69+
'org.ros2.rcljava.interfaces.GoalRequestDefinition',
70+
'org.ros2.rcljava.interfaces.GoalResponseDefinition',
71+
'org.ros2.rcljava.interfaces.MessageDefinition',
6872
'org.slf4j.Logger',
6973
'org.slf4j.LoggerFactory',
7074
]
@@ -76,6 +80,42 @@ import @(action_import);
7680

7781
public class @(type_name) implements ActionDefinition {
7882

83+
public static class SendGoalRequest extends @(type_name)_SendGoal_Request implements GoalRequestDefinition<@(type_name)> {
84+
public List<Byte> getGoalUuid() {
85+
// Return List since it's hash is based on the values (not the object pointer)
86+
return super.getGoalId().getUuidAsList();
87+
}
88+
}
89+
90+
public static class SendGoalResponse extends @(type_name)_SendGoal_Response implements GoalResponseDefinition<@(type_name)> {
91+
public void accept(boolean accepted) {
92+
super.setAccepted(accepted);
93+
}
94+
95+
public void setStamp(int sec, int nanosec) {
96+
builtin_interfaces.msg.Time msg = new builtin_interfaces.msg.Time();
97+
msg.setSec(sec);
98+
msg.setNanosec(nanosec);
99+
super.setStamp(msg);
100+
}
101+
}
102+
103+
public Class<? extends GoalRequestDefinition> getSendGoalRequestType() {
104+
return SendGoalRequest.class;
105+
}
106+
107+
public Class<? extends GoalResponseDefinition> getSendGoalResponseType() {
108+
return SendGoalResponse.class;
109+
}
110+
111+
public Class<? extends MessageDefinition> getGetResultRequestType() {
112+
return @(type_name)_GetResult_Request.class;
113+
}
114+
115+
public Class<? extends MessageDefinition> getGetResultResponseType() {
116+
return @(type_name)_GetResult_Response.class;
117+
}
118+
79119
private static final Logger logger = LoggerFactory.getLogger(@(type_name).class);
80120
81121
static {

rosidl_generator_java/resource/msg.java.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import @('.'.join(member.type.namespaced_name()));
3838
@[ end if]@
3939
@[end for]@
4040

41-
public final class @(type_name) implements MessageDefinition {
41+
public class @(type_name) implements MessageDefinition {
4242

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

0 commit comments

Comments
 (0)