ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to assign the result returned by the bash command to the arg parameter or the param parameter?

asked 2020-01-09 20:52:01 -0500

willzoe gravatar image

When I use rtabmap_ros, I need to specify the database save path.The feasible method is to use the following method to assign values in rtabmap node:

param name = "database_path" type = "string" value = "~ / .ros / rtabmap.db"

But I want to add the current time to the generated database file name.For example, when I execute date + '~ / rtabmap_databases / rtabmap_% Y-% m-% d-% Ih-% Mm-% Ss.db' in bash, the screen prints ~ / rtabmap_databases / rtabmap_2020-01-10 -10h-02m-04s.db. I want to pass this string to the database_path parameter of rtabmap node. Therefore, I use the following methods for parameter assignment:

param name="database_path" command="date +'~/rtabmap_databases/rtabmap_%Y-%m-%d-%Ih-%Mm-%Ss.db'"

but the following error occurs:

[FATAL] (2020-01-10 10:12:27.004) Rtabmap.cpp:298::init() Condition (UFile::getExtension(_databasePath).compare("db") == 0) not met!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-10 09:28:51 -0500

d.fenucci gravatar image

updated 2020-01-10 09:29:12 -0500

I think the problem is that the resulting string from the command date + '~ / rtabmap_databases / rtabmap_% Y-% m-% d-% Ih-% Mm-% Ss.db' has a trailing newline character, thus the check on the last characters of the string (representing the file extension) fails.

Try to replace the command with the following:

<param name="database_path" command="bash -c &quot;date +'~/rtabmap_databases/rtabmap_%Y-%m-%d-%Ih-%Mm-%Ss.db' | tr -d '\n'&quot;"/>

It worked fine on my laptop using ROS melodic.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-01-09 20:52:01 -0500

Seen: 157 times

Last updated: Jan 10 '20