0
$\begingroup$

Rosanswers logo

Hi,

I was following along the ROS tutorials since the beginning and I am having troubles on the ros_readbagfile command, because I am not able to running it:

I install the dependencies like asked in the beginning of the ros_readbagfile.py file:

sudo apt install python3-rosbag

And did the following steps how suggested in the tutorials:

# Download the file
  wget https://raw.githubusercontent.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/master/useful_scripts/ros_readbagfile.py
# Make it executable
  chmod +x ros_readbagfile.py
# Ensure you have the ~/bin directory for personal binaries
  mkdir -p ~/bin
# Move this executable script into that directory as `ros_readbagfile`, so that it will
# be available as that command
  mv ros_readbagfile.py ~/bin/ros_readbagfile
# Re-source your ~/.bashrc file to ensure ~/bin is in your PATH, so you can use this
# new `ros_readbagfile` command you just installed
  . ~/.bashrc

But it is still not working and it appears "ros_readbagfile: command not found" when I run:

time ros_readbagfile demo.bag /obs1/gps/fix /diagnostics_agg | tee topics.yaml

Can someone help me how to figure it out why is not working? Thank you


Originally posted by goncaloski on ROS Answers with karma: 11 on 2021-02-11

Post score: 1


Original comments

Comment by jarvisschultz on 2021-02-11:
I'd start by looking at your PATH environment variable and making sure that ~/bin/ is actually included. Can you run echo $PATH?

Comment by Super on 2021-02-16:
I had the same problem. If I run "~/bin$ echo $PATH" then i got:

/opt/ros/noetic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

In the other hand, if I place myself on my bin folder and run "pwd" i got:

/home/username/bin

Actually I thing I do not understand quite good the problem, or why we have to ~/.bashrc if we already have created our bin folder.

Thanks in advance.

Comment by jarvisschultz on 2021-02-16:
@Super please do not post answers that are actually answers. This is a Q&A site not a discussion forum. I've moved your answer to a question comment.

Comment by jarvisschultz on 2021-02-16:
@Super looking at the PATH variable you've posted, it's clear that the ~/bin directory is not on your path. Without that directory being on your PATH, it will be impossible to execute the script. Likely the author of the instructions from OP's question was counting on the fact that if the ~/bin directory exists, then on many Ubuntu/Debian systems it will automatically be added to the PATH. However, this would only happen upon re-running your ~/.profile or ~/.bashrc (depending on those files' contents). This is why the instructions have you re-run the bashrc with . ~/.bashrc. Read more here: https://askubuntu.com/questions/402353/how-to-add-home-username-bin-to-path

Comment by eRCaGuy on 2021-08-27:
Did you figure it out? I wrote ros_readbagfile and that tutorial.

Comment by Ruturaj on 2022-06-29:
I am facing the same problem, followed all steps in the tutorial , any solution to this? @eRCaGuy (Using Arch Linux, but am newbie to Linux.)

Comment by eRCaGuy on 2022-07-04:
@Ruturaj, does this fix it for you? See my new answer: https://answers.ros.org/question/371583/ros_readbagfile-command-not-found/?answer=403354#post-id-403354

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Maybe this is the first time you are creating the "~/bin" dir so try logging out of your user account and log in back, see if the command work now. If not, then try replacing the command:

mv ros_readbagfile.py ~/bin/ros_readbagfile

by:

ln -si "${PWD}/ros_readbagfile.py" ~/bin/ros_readbagfile

The command shoud work now after logging out and logging back in


Originally posted by mentxlist with karma: 21 on 2021-10-26

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

I am the author of this ROS wiki article: Reading messages from a bag file

I'm also the author of the ros_readbag.py Python script, which is part of my eRCaGuy_dotfiles repo.

To "install" the ros_readbagfile.py script, all we need to do is make it executable, name it ros_readbagfile, move it into the ~/bin folder, and ensure that folder is in your PATH variable, which is a variable containing a list of folders your terminal will look in for executables whenever you type an executable name.

How to add the ~/bin directory to your PATH variable so that executables within it can be found

On Linux Ubuntu, the ~/bin dir gets automatically added to your PATH variable if that dir exists! This happens because Ubuntu's default ~/.profile file, which gets sourced whenever your Bash terminal starts up, contains these lines of code:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

So, if you have followed my installation instructions and they don't work, you are probably missing the above lines in your ~/.profile file. So, create that file if it doesn't exist, then copy and paste that above code chunk into it. Then follow my instructions again.

You may need to re-source that file with this weird-looking command: . ~/.profile, OR re-source your bashrc file: . ~/.bashrc, OR log out and log back in. Now, view your PATH variable with echo "$PATH" and look to see that your ~/bin dir is there. It will look like this, for instance, assuming your username is gabriel: :/home/gabriel/bin:.

That's it!

Does that work for you? Leave a comment below.

Alternative fixes:

Option 1: call the script by its full path instead

time ~/bin/ros_readbagfile demo.bag /obs1/gps/fix /diagnostics_agg | tee topics.yaml

Option 2: manually run this in your terminal first:

PATH="$HOME/bin:$PATH"

Option 3: add this to your ~/.profile file, OR to your ~/.bashrc file

Option A:

PATH="$HOME/bin:$PATH"

OR, even better: Option B:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

Then re-source: . ~/.bashrc or log out and log back in.

See also

  1. My answer on source (.) vs export (and also some file lock [flock] stuff at the end)

Originally posted by eRCaGuy with karma: 171 on 2022-07-04

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.