We know that when running a program, you must enter the command "source ./devel/setup.bash" in each new terminal, otherwise the program cannot be run, which is very troublesome. In fact, we only need to add the corresponding statement in .bashrc. The solution is as follows:
method one:
Type in terminal
sudo gedit ~/.bashrc
The .bashrc file will appear
We just add the statement on the last line:
source /home/***/your_ws/devel/setup.bash
The *** part is your computer name, your_ws is your own workspace name.
After saving, you can directly run the code in this workspace when you open any terminal in the future. Of course, if you create a new workspace, you have to follow this method to add the devel of the new workspace to the .bashrc file.
Note: After adding, you usually have to reopen a terminal and then run the code with rosrun. If you still run the code in the original terminal, rosrun will report an error (I don’t know why)
Method Two:
Add statements directly in the terminal
echo "source /home/***/your_ws/devel/setup.bash">>~/.bashrc
The *** part is your computer name, your_ws is your own workspace name.
Then reopen a terminal, rosrun code