Skip to content

Commit e4f8f81

Browse files
committed
Merge branch 'dev' into feature/win-and-macos-build
Signed-off-by: Arne Nordmann <arne.nordmann@de.bosch.com>
2 parents 888b5a8 + 0ada932 commit e4f8f81

16 files changed

Lines changed: 377 additions & 118 deletions

.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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
Changelog for package system_modes
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5-
0.2.3 (2020-02-13)
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+
11+
0.3.0 (2020-07-23)
12+
-----------
13+
* removed boost dependencies (was: program options)
14+
* changed mode service specifications (less redundancy)
15+
* https://github.com/micro-ROS/system_modes/issues/24
16+
17+
0.2.3 (2020-07-23)
618
-----------
719
* improved StateAndMode struct
820
* testing

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: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,32 @@ class ModeManager : public rclcpp::Node
6565

6666
// Mode service callbacks
6767
virtual void on_change_mode(
68-
const std::shared_ptr<rmw_request_id_t>,
68+
const std::string &,
6969
const std::shared_ptr<system_modes::srv::ChangeMode::Request>,
7070
std::shared_ptr<system_modes::srv::ChangeMode::Response>);
7171
virtual void on_get_mode(
72-
const std::shared_ptr<rmw_request_id_t>,
73-
const std::shared_ptr<system_modes::srv::GetMode::Request>,
72+
const std::string &,
7473
std::shared_ptr<system_modes::srv::GetMode::Response>);
7574
virtual void on_get_available_modes(
76-
const std::shared_ptr<rmw_request_id_t>,
77-
const std::shared_ptr<system_modes::srv::GetAvailableModes::Request>,
75+
const std::string &,
7876
std::shared_ptr<system_modes::srv::GetAvailableModes::Response>);
7977

8078
virtual bool change_state(
81-
const std::string & node,
79+
const std::string &,
8280
unsigned int,
8381
bool transitive = true);
84-
virtual bool change_mode(const std::string & node, const std::string & mode);
82+
virtual bool change_mode(
83+
const std::string &,
84+
const std::string &);
8585

86-
virtual void change_part_state(const std::string & node, unsigned int);
87-
virtual void change_part_mode(const std::string & node, const std::string & mode);
86+
virtual void change_part_state(
87+
const std::string &,
88+
unsigned int);
89+
virtual void change_part_mode(
90+
const std::string &,
91+
const std::string &);
92+
93+
virtual void publish_transitions();
8894

8995
private:
9096
std::shared_ptr<ModeInference> mode_inference_;
@@ -113,16 +119,23 @@ class ModeManager : public rclcpp::Node
113119
std::map<std::string, rclcpp::AsyncParametersClient::SharedPtr>
114120
param_change_clients_;
115121

116-
// Lifecycle transition request
122+
// Lifecycle transition publisher
123+
std::map<std::string, rclcpp::Publisher<lifecycle_msgs::msg::TransitionEvent>::SharedPtr>
124+
transition_pub_;
117125
std::map<std::string, rclcpp::Publisher<lifecycle_msgs::msg::TransitionEvent>::SharedPtr>
118126
state_request_pub_;
119127

120-
// Mode transition request publisher
128+
// Mode transition publisher
129+
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
130+
mode_transition_pub_;
121131
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
122132
mode_request_pub_;
123133

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

128141
} // 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: 10 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.2.3</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

@@ -15,6 +21,8 @@
1521
<depend>builtin_interfaces</depend>
1622
<depend>rosidl_default_generators</depend>
1723

24+
<exec_depend>launch_ros</exec_depend>
25+
1826
<test_depend>ament_cmake_gtest</test_depend>
1927
<test_depend>ament_cmake_gmock</test_depend>
2028
<test_depend>ament_cmake_pep257</test_depend>

system_modes/src/mode_monitor_node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void mode_change_callback(
6969
const string & node_name)
7070
{
7171
monitor->inference()->update_state(node_name, State::PRIMARY_STATE_ACTIVE);
72-
monitor->inference()->update_mode(node_name, msg->goal_mode.label.c_str());
72+
monitor->inference()->update_mode(node_name, msg->goal_mode.label);
7373
}
7474

7575
void transition_request_callback(
@@ -93,7 +93,7 @@ void mode_request_callback(
9393
{
9494
monitor->inference()->update_target(
9595
node_name,
96-
StateAndMode(State::PRIMARY_STATE_ACTIVE, msg->goal_mode.label.c_str()));
96+
StateAndMode(State::PRIMARY_STATE_ACTIVE, msg->goal_mode.label));
9797
}
9898

9999
void

0 commit comments

Comments
 (0)