Skip to content

Commit 34da057

Browse files
authored
Merge latest dev into master (#49)
Mode manager is now publishing transitions that are inferred by the mode inference, i.e. state and mode transitions of systems, mode transitions of nodes. * Stricter constness in mode inference * ModeEvent now includes start mode (of transition) * Adds inference of transitions to mode inference * Tests for transition inference * Mode manager publishs inferred transitions * Version push to 0.4.0 #42 Signed-off-by: Arne Nordmann <arne.nordmann@de.bosch.com>
1 parent 9189558 commit 34da057

File tree

11 files changed

+301
-86
lines changed

11 files changed

+301
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode

system_modes/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog for package system_modes
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
0.4.0 (2020-09-30)
6+
-----------
7+
* mode event now including start and goal mode
8+
* publish inferred state and mode transitions
9+
* https://github.com/micro-ROS/system_modes/issues/42
10+
511
0.3.0 (2020-07-23)
612
-----------
713
* removed boost dependencies (was: program options)

system_modes/include/system_modes/mode_inference.hpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,38 @@ class ModeInference
5353
virtual void update_param(const std::string &, rclcpp::Parameter &);
5454
virtual void update_target(const std::string &, StateAndMode);
5555

56-
virtual StateAndMode get(const std::string & part);
56+
virtual StateAndMode get(const std::string & part) const;
5757
virtual StateAndMode get_or_infer(const std::string & part);
5858

5959
virtual StateAndMode infer(const std::string & part);
60-
virtual StateAndMode infer_system(const std::string & part);
6160
virtual StateAndMode infer_node(const std::string & part);
61+
virtual StateAndMode infer_system(const std::string & part);
62+
63+
/**
64+
* Infers latest transitions of systems
65+
*
66+
* Returns map of last inferred transitions of systems into new states or
67+
* new modes. State transitions of nodes don't have to be inferred, as
68+
* nodes publish their state transitions. For nodes, we only need to infer
69+
* mode transitions.
70+
*/
71+
virtual Deviation infer_transitions();
6272

63-
virtual StateAndMode get_target(const std::string & part);
64-
virtual ModeConstPtr get_mode(const std::string & part, const std::string & mode);
65-
virtual std::vector<std::string> get_available_modes(const std::string & part);
73+
virtual StateAndMode get_target(const std::string & part) const;
74+
virtual ModeConstPtr get_mode(const std::string & part, const std::string & mode) const;
75+
virtual std::vector<std::string> get_available_modes(const std::string & part) const;
6676

6777
virtual ~ModeInference() = default;
6878

6979
protected:
70-
virtual bool matching_parameters(const rclcpp::Parameter &, const rclcpp::Parameter &);
80+
virtual bool matching_parameters(const rclcpp::Parameter &, const rclcpp::Parameter &) const;
7181
virtual void read_modes_from_model(const std::string & model_path);
7282
virtual void add_param_to_mode(ModeBasePtr, const rclcpp::Parameter &);
7383

7484
private:
75-
StatesMap nodes_, nodes_target_;
76-
StatesMap systems_, systems_target_;
85+
StatesMap nodes_, nodes_target_, nodes_cache_;
86+
StatesMap systems_, systems_target_, systems_cache_;
87+
7788
std::map<std::string, ModeMap> modes_;
7889
ParametersMap parameters_;
7990

@@ -83,6 +94,8 @@ class ModeInference
8394
param_mutex_;
8495
mutable std::shared_timed_mutex
8596
nodes_target_mutex_, systems_target_mutex_;
97+
mutable std::shared_timed_mutex
98+
nodes_cache_mutex_, systems_cache_mutex_;
8699
};
87100

88101
} // namespace system_modes

system_modes/include/system_modes/mode_manager.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class ModeManager : public rclcpp::Node
9090
const std::string &,
9191
const std::string &);
9292

93+
virtual void publish_transitions();
94+
9395
private:
9496
std::shared_ptr<ModeInference> mode_inference_;
9597

@@ -117,16 +119,23 @@ class ModeManager : public rclcpp::Node
117119
std::map<std::string, rclcpp::AsyncParametersClient::SharedPtr>
118120
param_change_clients_;
119121

120-
// Lifecycle transition request
122+
// Lifecycle transition publisher
123+
std::map<std::string, rclcpp::Publisher<lifecycle_msgs::msg::TransitionEvent>::SharedPtr>
124+
transition_pub_;
121125
std::map<std::string, rclcpp::Publisher<lifecycle_msgs::msg::TransitionEvent>::SharedPtr>
122126
state_request_pub_;
123127

124-
// Mode transition request publisher
128+
// Mode transition publisher
129+
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
130+
mode_transition_pub_;
125131
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
126132
mode_request_pub_;
127133

128134
// Remember states and modes of the systems
129135
std::map<std::string, StateAndMode> current_modes_;
136+
137+
// Timer to check for and publish recent transitions
138+
rclcpp::TimerBase::SharedPtr transition_timer_;
130139
};
131140

132141
} // namespace system_modes

system_modes/msg/ModeEvent.msg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
# The time point at which this event occurred.
12
uint64 timestamp
3+
4+
# The starting mode from which this event transitioned.
5+
Mode start_mode
6+
7+
# The end mode of this transition event.
28
Mode goal_mode

system_modes/package.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>system_modes</name>
5-
<version>0.3.0</version>
6-
<description>Model-based distributed configuration handling.</description>
5+
<version>0.4.0</version>
6+
<description>
7+
The system modes concept assumes that a robotics system is built
8+
from components with a lifecycle. It adds a notion of (sub-)systems,
9+
hiararchically grouping these nodes, as well as a notion of modes
10+
that determine the configuration of these nodes and (sub-)systems in
11+
terms of their parameter values.
12+
</description>
713
<maintainer email="arne.nordmann@bosch.com">Arne Nordmann</maintainer>
814
<license>Apache License 2.0</license>
915

0 commit comments

Comments
 (0)