How I Learned to Stop Worrying and Love the Terminal

zGiven that most of you will access ROS through the terminal (the -X next to ssh indicates that you can try to run GUI tools, but the speed is excessively slow), here are some terminal commands and tools that will make working in the terminal a lot easier.

tmux 

Tmux is a terminal multiplexer, which means that you can run multiple terminal shells in one window. Type tmux  into the terminal, and it should take you a nearly identical terminal window.

Commands are

  • Ctrl-b + % – Split the terminal vertically into two panes
  • Ctrl-b + " – Split the terminal horizontally into two panes
  • Ctrl-b (with continued press) + arrow_key – Resize the pane
  • Ctrl-b + arrow_key – Change pane selection
  • Ctrl-b + x – terminal the current selected pane
  • Ctrl-b + [ – Read mode (ESC and move cursor to escape)

vim (or nano)

Vim is a text editor that requires the users to use key commands. You could either type vimtutor for practice (which will take about 10 minutes), or google for basic vim commands. You only really use ~10 commands, so I think it’s worth learning vim.
I highly recommend you go through vimtutor multiple times.
Currently, there is a file explorer pane in vim (called netrw) – you can switch between panes using Ctrl-W + Arrow_keys  and terminate each pane using Esc and typing :wq (for editor) and :q (file explorer).
Terminal commands

To redirect the terminal output to a file (so you can read the error output)

some_command >file.log 2>&1 

Run a command in the background:

some_command & 

Move out of current folder

cd ..

How to run a command every terminal launch

Modify ~/.bashrc (e.g. vim ~/.bashrc) and put commands at the bottom.

~/.bashrc is essentially a shell (bash) command that runs when you first open the terminal, which means that you can put setup commands in ~/.bashrc so that you would not have to type them over and over again.

In ~/.bashrc, you can put ~/catkin_ws/devel/setup.bash (which is within ROS workspace) as one of the setup files to execute at launch. Whatsetup.bash does is that it sets up the path variables for ROS, allowing commands like roscd to find where the directory with packages is.

For those who are not so familiar with the terminal language, a “shell” is the terminal – a way for the user to interact with the operating system (Linux, in this case).

ROS commands

roscd <package_name> <folder_name>

rosed <pacakge_name> <file_name> – Opens file for editing

Commands like roscd (ros + cd) and rosed (ros + ed), they are essentially shortcuts for cd and ed to edit ROS package files quickly.

 

Leave a Reply

Your email address will not be published. Required fields are marked *