Skip to content

Commit f8b5092

Browse files
committed
All ros args now via launch instead of commandline
Signed-off-by: Arne Nordmann <arne.nordmann@de.bosch.com>
1 parent d8935cc commit f8b5092

8 files changed

Lines changed: 65 additions & 54 deletions

File tree

system_modes/include/system_modes/mode_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace system_modes
4040
class ModeManager : public rclcpp::Node
4141
{
4242
public:
43-
explicit ModeManager(const std::string & model_path);
43+
ModeManager();
4444
ModeManager(const ModeManager &) = delete;
4545

4646
std::shared_ptr<ModeInference> inference();

system_modes/include/system_modes/mode_monitor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace system_modes
3737
class ModeMonitor : public rclcpp::Node
3838
{
3939
public:
40-
ModeMonitor(const std::string & model_path, unsigned int rate, bool verbose, bool clear);
40+
ModeMonitor();
4141
ModeMonitor(const ModeMonitor &) = delete;
4242

4343
std::shared_ptr<ModeInference> inference();

system_modes/launch/mode_manager.launch.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121

2222

2323
def generate_launch_description():
24-
launch.actions.DeclareLaunchArgument('modelfile', description='Path to modelfile')
25-
26-
node = launch_ros.actions.Node(
27-
package='system_modes',
28-
executable='mode_manager',
29-
parameters=[{'modelfile': launch.substitutions.LaunchConfiguration('modelfile')}],
30-
output='screen')
31-
32-
description = launch.LaunchDescription()
33-
description.add_action(node)
34-
35-
return description
24+
return launch.LaunchDescription([
25+
launch.actions.DeclareLaunchArgument(
26+
'modelfile',
27+
description='Path to modelfile'),
28+
launch_ros.actions.Node(
29+
package='system_modes',
30+
executable='mode_manager',
31+
parameters=[{'modelfile': launch.substitutions.LaunchConfiguration('modelfile')}],
32+
output='screen')])

system_modes/launch/mode_monitor.launch.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,34 @@
1515

1616
import launch
1717
import launch.actions
18-
import launch.substitutions
1918

2019
import launch_ros.actions
2120

2221

2322
def generate_launch_description():
24-
launch.actions.DeclareLaunchArgument('modelfile', description='Path to modelfile')
25-
26-
node = launch_ros.actions.Node(
23+
return launch.LaunchDescription([
24+
launch.actions.DeclareLaunchArgument(
25+
'modelfile',
26+
description='Path to modelfile'),
27+
launch.actions.DeclareLaunchArgument(
28+
'debug',
29+
default_value='false',
30+
description='Debug'),
31+
launch.actions.DeclareLaunchArgument(
32+
'verbose',
33+
default_value='false',
34+
description='Print mode parametrization'),
35+
launch.actions.DeclareLaunchArgument(
36+
'rate',
37+
default_value='1000',
38+
description='Monitor refresh rate in ms'),
39+
launch_ros.actions.Node(
2740
package='system_modes',
2841
executable='mode_monitor',
29-
parameters=[{'modelfile': launch.substitutions.LaunchConfiguration('modelfile')}],
30-
output='screen')
31-
32-
description = launch.LaunchDescription()
33-
description.add_action(node)
34-
35-
return description
42+
parameters=[{
43+
'modelfile': launch.substitutions.LaunchConfiguration('modelfile'),
44+
'debug': launch.substitutions.LaunchConfiguration('debug'),
45+
'verbose': launch.substitutions.LaunchConfiguration('verbose'),
46+
'rate': launch.substitutions.LaunchConfiguration('rate')
47+
}],
48+
output='screen')])

system_modes/src/mode_manager_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int main(int argc, char * argv[])
113113
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
114114
rclcpp::init(argc, argv);
115115

116-
manager = std::make_shared<ModeManager>(modelfile);
116+
manager = std::make_shared<ModeManager>();
117117

118118
vector<shared_ptr<rclcpp::Subscription<TransitionEvent>>>
119119
state_sub_;

system_modes/src/mode_monitor_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int main(int argc, char * argv[])
120120
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
121121
rclcpp::init(argc, argv);
122122

123-
monitor = make_shared<ModeMonitor>(modelfile, rate, verbose, !debug);
123+
monitor = make_shared<ModeMonitor>();
124124

125125
vector<shared_ptr<rclcpp::Subscription<TransitionEvent>>>
126126
state_sub_;

system_modes/src/system_modes/mode_manager.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ using namespace std::chrono_literals;
5555
namespace system_modes
5656
{
5757

58-
ModeManager::ModeManager(const string & model_path)
58+
ModeManager::ModeManager()
5959
: Node("__mode_manager"),
6060
mode_inference_(nullptr),
6161
state_change_srv_(), get_state_srv_(), states_srv_(),
@@ -64,16 +64,11 @@ ModeManager::ModeManager(const string & model_path)
6464
state_request_pub_(), mode_request_pub_()
6565
{
6666
declare_parameter("modelfile", rclcpp::ParameterValue(std::string("")));
67+
std::string model_path = get_parameter("modelfile").as_string();
6768
if (model_path.empty()) {
68-
rclcpp::Parameter parameter = get_parameter("modelfile");
69-
std::string alt_model_path = parameter.get_value<rclcpp::ParameterType::PARAMETER_STRING>();
70-
if (alt_model_path.empty()) {
71-
throw std::invalid_argument("Need path to model file.");
72-
}
73-
mode_inference_ = std::make_shared<ModeInference>(alt_model_path);
74-
} else {
75-
mode_inference_ = std::make_shared<ModeInference>(model_path);
69+
throw std::invalid_argument("Need path to model file.");
7670
}
71+
mode_inference_ = std::make_shared<ModeInference>(model_path);
7772

7873
for (auto system : this->mode_inference_->get_systems()) {
7974
this->add_system(system);

system_modes/src/system_modes/mode_monitor.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ using namespace std::literals::string_literals;
5151
namespace system_modes
5252
{
5353

54+
static const bool MONITOR_DEFAULT_VERBOSITY = false;
55+
static const bool MONITOR_DEFAULT_DEBUG = false;
56+
static const unsigned int MONITOR_DEFAULT_RATE_MS = 1000;
57+
5458
static const unsigned int MONITOR_WIDTH_PART = 25;
5559
static const unsigned int MONITOR_WIDTH_STATE = 30;
5660
static const unsigned int MONITOR_WIDTH_MODE = 30;
@@ -70,27 +74,29 @@ static const string MONITOR_TEXT_WARN = "\033[21;"s + to_string(MONITOR_TEXT_WAR
7074
static const string MONITOR_SEPARATOR = MONITOR_TEXT_PLAIN + " | ";
7175
static const string MONITOR_SEPARATOR_BOLD = MONITOR_TEXT_BOLD + " | ";
7276

73-
ModeMonitor::ModeMonitor(
74-
const string & model_path,
75-
unsigned int rate = 1000,
76-
bool verbose = false,
77-
bool clear = true)
77+
ModeMonitor::ModeMonitor()
7878
: Node("__mode_monitor"),
79-
mode_inference_(),
80-
model_path_(model_path),
81-
rate_(rate),
82-
clear_screen_(clear),
83-
verbose_(verbose)
79+
mode_inference_()
8480
{
85-
RCLCPP_DEBUG(get_logger(), "Constructed mode monitor");
86-
87-
declare_parameter("modelfile", rclcpp::ParameterValue(std::string("")));
81+
declare_parameter(
82+
"modelfile",
83+
rclcpp::ParameterValue(std::string("")));
84+
declare_parameter(
85+
"rate",
86+
rclcpp::ParameterValue(static_cast<int>(MONITOR_DEFAULT_RATE_MS)));
87+
declare_parameter(
88+
"debug",
89+
rclcpp::ParameterValue(static_cast<bool>(MONITOR_DEFAULT_DEBUG)));
90+
declare_parameter(
91+
"verbose",
92+
rclcpp::ParameterValue(static_cast<bool>(MONITOR_DEFAULT_VERBOSITY)));
93+
94+
rate_ = get_parameter("rate").as_int();
95+
clear_screen_ = !get_parameter("debug").as_bool();
96+
verbose_ = get_parameter("verbose").as_bool();
97+
model_path_ = get_parameter("modelfile").as_string();
8898
if (model_path_.empty()) {
89-
rclcpp::Parameter parameter = get_parameter("modelfile");
90-
model_path_ = parameter.get_value<rclcpp::ParameterType::PARAMETER_STRING>();
91-
if (model_path_.empty()) {
92-
throw std::invalid_argument("Need path to model file.");
93-
}
99+
throw std::invalid_argument("Need path to model file.");
94100
}
95101
mode_inference_ = std::make_shared<ModeInference>(model_path_);
96102

0 commit comments

Comments
 (0)