Skip to content

Commit 4b5292b

Browse files
martingrswltr
andcommitted
Allow sending VehicleCommAdapterMessages via the Operations Desk
Co-authored-by: Stefan Walter <stefan.walter@iml.fraunhofer.de> Merged-by: Stefan Walter <stefan.walter@iml.fraunhofer.de>
1 parent 25a8cee commit 4b5292b

File tree

21 files changed

+1387
-2
lines changed

21 files changed

+1387
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-FileCopyrightText: The openTCS Authors
2+
// SPDX-License-Identifier: MIT
3+
package org.opentcs.components.plantoverview;
4+
5+
import jakarta.annotation.Nonnull;
6+
import java.util.Map;
7+
import java.util.Set;
8+
import org.opentcs.drivers.vehicle.VehicleCommAdapterMessage;
9+
10+
/**
11+
* Objects implementing this interface provide a set of suggested types for
12+
* {@link VehicleCommAdapterMessage}s and keys and values for their parameters.
13+
*/
14+
public interface VehicleCommAdapterMessageSuggestions {
15+
16+
/**
17+
* Returns suggested types for {@link VehicleCommAdapterMessage}s.
18+
*
19+
* @return Suggested types for {@link VehicleCommAdapterMessage}s.
20+
*/
21+
@Nonnull
22+
Set<String> getTypeSuggestions();
23+
24+
/**
25+
* Returns a map of parameter suggestions that are specified for the given
26+
* {@link VehicleCommAdapterMessage} type.
27+
* <p>
28+
* The map contains parameter keys mapped to suggestions for the corresponding parameter's values.
29+
* </p>
30+
*
31+
* @param type The {@link VehicleCommAdapterMessage} type for which parameter suggestions are
32+
* requested.
33+
* @return A map of parameter suggestions.
34+
*/
35+
@Nonnull
36+
Map<String, Set<String>> getParameterSuggestionsFor(
37+
@Nonnull
38+
String type
39+
);
40+
}

opentcs-api-injection/src/main/java/org/opentcs/customizations/plantoverview/PlantOverviewInjectionModule.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.opentcs.components.plantoverview.PlantModelImporter;
1010
import org.opentcs.components.plantoverview.PluggablePanelFactory;
1111
import org.opentcs.components.plantoverview.PropertySuggestions;
12+
import org.opentcs.components.plantoverview.VehicleCommAdapterMessageSuggestions;
1213
import org.opentcs.customizations.ConfigurableInjectionModule;
1314

1415
/**
@@ -63,6 +64,17 @@ protected Multibinder<OrderTypeSuggestions> orderTypeSuggestionsBinder() {
6364
return Multibinder.newSetBinder(binder(), OrderTypeSuggestions.class);
6465
}
6566

67+
/**
68+
* Returns a multibinder that can be used to register classes that provide suggestions for
69+
* vehicle comm adapter messages.
70+
*
71+
* @return The multibinder.
72+
*/
73+
protected Multibinder<VehicleCommAdapterMessageSuggestions>
74+
vehicleCommAdapterMessageSuggestionsBinder() {
75+
return Multibinder.newSetBinder(binder(), VehicleCommAdapterMessageSuggestions.class);
76+
}
77+
6678
/**
6779
* Returns a multibinder that can be used to register {@link ObjectHistoryEntryFormatter}s.
6880
*

opentcs-documentation/src/docs/release-notes/changelog.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This change log lists the most relevant changes for past releases in reverse chr
2323
** Consider `orderpool.sweepAge` when cleaning up order sequences, too.
2424
** Add support for mapping coordinates from the plant model's coordinate system to the coordinate system of a vehicle and vice versa (when sending/receiving them to/from a vehicle).
2525
For more information, please refer to the user's guide.
26+
** Add support for sending `VehicleCommAdapterMessage`s via the Operations Desk.
2627
* Bugs fixed:
2728
** Properly check a new plant model for duplicate element names before accepting it.
2829
** Don't allow transport orders to be created with a peripheral reservation token set to the empty string.

opentcs-operationsdesk/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ application.mainClass = ext.mainClass
1414
ext.collectableDistDir = new File(buildDir, 'install')
1515

1616
dependencies {
17+
api project(':opentcs-commadapter-loopback')
1718
api project(':opentcs-common')
1819
api project(':opentcs-impl-configuration-gestalt')
1920
api project(':opentcs-plantoverview-common')
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// SPDX-FileCopyrightText: The openTCS Authors
2+
// SPDX-License-Identifier: MIT
3+
package org.opentcs.operationsdesk;
4+
5+
import static java.util.Objects.requireNonNull;
6+
7+
import java.util.HashMap;
8+
import java.util.HashSet;
9+
import java.util.Map;
10+
import java.util.Set;
11+
import java.util.stream.Collectors;
12+
import java.util.stream.Stream;
13+
import javax.annotation.Nonnull;
14+
import org.opentcs.components.plantoverview.VehicleCommAdapterMessageSuggestions;
15+
import org.opentcs.data.model.Vehicle;
16+
import org.opentcs.drivers.vehicle.VehicleCommAdapterMessage;
17+
import org.opentcs.virtualvehicle.LoopbackCommAdapterMessages;
18+
19+
/**
20+
* The default suggestions for {@link VehicleCommAdapterMessage}s.
21+
*/
22+
public class DefaultVehicleCommAdapterMessageSuggestions
23+
implements
24+
VehicleCommAdapterMessageSuggestions {
25+
26+
private final Set<String> typeSuggestions = new HashSet<>();
27+
private final Map<String, Map<String, Set<String>>> parameterSuggestions = new HashMap<>();
28+
29+
/**
30+
* Creates a new instance.
31+
*/
32+
public DefaultVehicleCommAdapterMessageSuggestions() {
33+
addTypeSuggestion(
34+
LoopbackCommAdapterMessages.INIT_POSITION,
35+
new ParameterSuggestion(LoopbackCommAdapterMessages.INIT_POSITION_PARAM_POSITION)
36+
);
37+
addTypeSuggestion(LoopbackCommAdapterMessages.CURRENT_MOVEMENT_COMMAND_FAILED);
38+
addTypeSuggestion(
39+
LoopbackCommAdapterMessages.PUBLISH_EVENT,
40+
new ParameterSuggestion(LoopbackCommAdapterMessages.PUBLISH_EVENT_PARAM_APPENDIX)
41+
);
42+
addTypeSuggestion(
43+
LoopbackCommAdapterMessages.SET_ENERGY_LEVEL,
44+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_ENERGY_LEVEL_PARAM_LEVEL)
45+
);
46+
addTypeSuggestion(
47+
LoopbackCommAdapterMessages.SET_LOADED,
48+
new ParameterSuggestion(
49+
LoopbackCommAdapterMessages.SET_LOADED_PARAM_LOADED,
50+
Set.of("true", "false")
51+
)
52+
);
53+
addTypeSuggestion(
54+
LoopbackCommAdapterMessages.SET_ORIENTATION_ANGLE,
55+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_ORIENTATION_ANGLE_PARAM_ANGLE)
56+
);
57+
addTypeSuggestion(
58+
LoopbackCommAdapterMessages.SET_POSITION,
59+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_POSITION_PARAM_POSITION)
60+
);
61+
addTypeSuggestion(LoopbackCommAdapterMessages.RESET_POSITION);
62+
addTypeSuggestion(
63+
LoopbackCommAdapterMessages.SET_PRECISE_POSITION,
64+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_PRECISE_POSITION_PARAM_X),
65+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_PRECISE_POSITION_PARAM_Y),
66+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_PRECISE_POSITION_PARAM_Z)
67+
);
68+
addTypeSuggestion(LoopbackCommAdapterMessages.RESET_PRECISE_POSITION);
69+
addTypeSuggestion(
70+
LoopbackCommAdapterMessages.SET_STATE,
71+
new ParameterSuggestion(
72+
LoopbackCommAdapterMessages.SET_STATE_PARAM_STATE,
73+
Set.of(
74+
Vehicle.State.UNKNOWN.name(),
75+
Vehicle.State.UNAVAILABLE.name(),
76+
Vehicle.State.ERROR.name(),
77+
Vehicle.State.IDLE.name(),
78+
Vehicle.State.EXECUTING.name(),
79+
Vehicle.State.CHARGING.name()
80+
)
81+
)
82+
);
83+
addTypeSuggestion(
84+
LoopbackCommAdapterMessages.SET_PAUSED,
85+
new ParameterSuggestion(
86+
LoopbackCommAdapterMessages.SET_PAUSED_PARAM_PAUSED,
87+
Set.of("true", "false")
88+
)
89+
);
90+
addTypeSuggestion(
91+
LoopbackCommAdapterMessages.SET_PROPERTY,
92+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_PROPERTY_PARAM_KEY),
93+
new ParameterSuggestion(LoopbackCommAdapterMessages.SET_PROPERTY_PARAM_VALUE)
94+
);
95+
addTypeSuggestion(
96+
LoopbackCommAdapterMessages.RESET_PROPERTY,
97+
new ParameterSuggestion(LoopbackCommAdapterMessages.RESET_PROPERTY_PARAM_KEY)
98+
);
99+
addTypeSuggestion(
100+
LoopbackCommAdapterMessages.SET_SINGLE_STEP_MODE_ENABLED,
101+
new ParameterSuggestion(
102+
LoopbackCommAdapterMessages.SET_SINGLE_STEP_MODE_ENABLED_PARAM_ENABLED,
103+
Set.of("true", "false")
104+
)
105+
);
106+
addTypeSuggestion(
107+
LoopbackCommAdapterMessages.TRIGGER_SINGLE_STEP
108+
);
109+
}
110+
111+
@Override
112+
@Nonnull
113+
public Set<String> getTypeSuggestions() {
114+
return Set.copyOf(typeSuggestions);
115+
}
116+
117+
@Override
118+
@Nonnull
119+
public Map<String, Set<String>> getParameterSuggestionsFor(
120+
@Nonnull
121+
String type
122+
) {
123+
return parameterSuggestions.getOrDefault(requireNonNull(type, "type"), Map.of());
124+
}
125+
126+
private void addTypeSuggestion(
127+
String typeSuggestion,
128+
ParameterSuggestion... parameterSuggestions
129+
) {
130+
typeSuggestions.add(typeSuggestion);
131+
this.parameterSuggestions.put(
132+
typeSuggestion,
133+
Stream.of(parameterSuggestions)
134+
.collect(
135+
Collectors.toMap(
136+
ParameterSuggestion::key,
137+
ParameterSuggestion::values
138+
)
139+
)
140+
);
141+
}
142+
143+
/**
144+
* A suggestion for a single parameter consisting of the parameter's key and suggestions for its
145+
* value.
146+
*
147+
* @param key The parameter's key.
148+
* @param values A set of suggested values
149+
*/
150+
private record ParameterSuggestion(String key, Set<String> values) {
151+
152+
/**
153+
* Creates a new instance.
154+
*
155+
* @param key The parameter's key.
156+
*/
157+
ParameterSuggestion(String key) {
158+
this(key, Set.of());
159+
}
160+
}
161+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-FileCopyrightText: The openTCS Authors
2+
// SPDX-License-Identifier: MIT
3+
package org.opentcs.operationsdesk;
4+
5+
import jakarta.inject.Singleton;
6+
import org.opentcs.customizations.plantoverview.PlantOverviewInjectionModule;
7+
import org.opentcs.drivers.vehicle.VehicleCommAdapterMessage;
8+
import org.opentcs.operationsdesk.vehicles.MergedVehicleCommAdapterMessageSuggestions;
9+
10+
/**
11+
* This module configures the multibinder used to suggest {@link VehicleCommAdapterMessage}
12+
* parameters.
13+
*/
14+
public class VehicleCommAdapterMessageSuggestionsModule
15+
extends
16+
PlantOverviewInjectionModule {
17+
18+
/**
19+
* Creates a new instance.
20+
*/
21+
public VehicleCommAdapterMessageSuggestionsModule() {
22+
}
23+
24+
@Override
25+
protected void configure() {
26+
vehicleCommAdapterMessageSuggestionsBinder().addBinding()
27+
.to(DefaultVehicleCommAdapterMessageSuggestions.class)
28+
.in(Singleton.class);
29+
30+
bind(MergedVehicleCommAdapterMessageSuggestions.class).in(Singleton.class);
31+
}
32+
}

opentcs-operationsdesk/src/guiceConfig/resources/META-INF/services/org.opentcs.customizations.plantoverview.PlantOverviewInjectionModule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
org.opentcs.operationsdesk.DefaultImportersExportersModule
55
org.opentcs.operationsdesk.PropertySuggestionsModule
66
org.opentcs.operationsdesk.transport.OrderTypeSuggestionsModule
7+
org.opentcs.operationsdesk.VehicleCommAdapterMessageSuggestionsModule

opentcs-operationsdesk/src/main/java/org/opentcs/operationsdesk/application/action/ViewActionMap.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.opentcs.operationsdesk.application.action.actions.FindVehicleAction;
2121
import org.opentcs.operationsdesk.application.action.actions.PauseAllVehiclesAction;
2222
import org.opentcs.operationsdesk.application.action.actions.ResumeAllVehiclesAction;
23+
import org.opentcs.operationsdesk.application.action.actions.SendVehicleCommAdapterMessageAction;
2324
import org.opentcs.operationsdesk.application.action.app.AboutAction;
2425
import org.opentcs.operationsdesk.application.action.view.AddDrawingViewAction;
2526
import org.opentcs.operationsdesk.application.action.view.AddPeripheralJobViewAction;
@@ -50,6 +51,7 @@ public class ViewActionMap
5051
* @param actionFactory The action factory
5152
* @param createTransportOrderAction The action to create transport orders
5253
* @param findVehicleAction The action to find vehicles
54+
* @param sendVehicleCommAdapterMessageAction The action to send vehicle comm adapter messages.
5355
* @param pauseAllVehiclesAction The action to pause all vehicles
5456
* @param resumeAllVehiclesAction The action to resume all vehicles
5557
* @param aboutAction The action to show the about window
@@ -67,6 +69,7 @@ public ViewActionMap(
6769
ActionFactory actionFactory,
6870
CreateTransportOrderAction createTransportOrderAction,
6971
FindVehicleAction findVehicleAction,
72+
SendVehicleCommAdapterMessageAction sendVehicleCommAdapterMessageAction,
7073
PauseAllVehiclesAction pauseAllVehiclesAction,
7174
ResumeAllVehiclesAction resumeAllVehiclesAction,
7275
AboutAction aboutAction,
@@ -107,6 +110,7 @@ public ViewActionMap(
107110
// Menu item Actions -> Create ...
108111
put(CreateTransportOrderAction.ID, createTransportOrderAction);
109112
put(CreatePeripheralJobAction.ID, createPeripheralJobAction);
113+
put(SendVehicleCommAdapterMessageAction.ID, sendVehicleCommAdapterMessageAction);
110114

111115
// --- Menu View ---
112116
// Menu View -> Add drawing view

0 commit comments

Comments
 (0)