This is a ROS Package for the beginner tutorials with creating a basic publisher and subscriber in C++. Reference: link
Must have the following installed:
- Ubuntu 18.04
- ROS Melodic
- C++, roscpp
- Standard library
- rqt_console
- xterm (runs the subscriber in another terminal)
sudo apt-get install ros-melodic-rqt ros-melodic-rqt-common-plugins
sudo apt install xterm
Create catkin workspace. Go to terminal and follow these commands:
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
Then source the setup.bash file with this command:
source devel/setup.bash
Now please clone the beginner_tutorials package by doing the following:
cd src/
git clone https://github.com/dngo13/beginner_tutorials.git
cd ..
catkin_make
source devel/setup.bash
Go to the src directory for the catkin workspace. And then follow these steps
cd ~/catkin_ws/src/
git clone https://github.com/dngo13/beginner_tutorials.git
cd ..
catkin_make
source devel/setup.bash
Now that the package is built, we can run the program.
In this terminal, run roscore
.
Open a new terminal, source it with:
source devel/setup.bash
And then run:
rosrun beginner_tutorials talker
Now, open a new terminal again, source it with:
source devel/setup.bash
And then run:
rosrun beginner_tutorials listener
You should see output in both terminals similar to ENPM808X ROS count: # and I heard: [ENPM808X ROS count: #]
Open a new terminal, source it with:
source devel/setup.bash
And then run:
roslaunch beginner_tutorials pub_sub_launch.launch
Alternatively, to change the frequency:
roslaunch beginner_tutorials pub_sub_launch.launch frequency:=##
Where ## is a number of your choice. Note that a 0 or a negative number will throw a fatal error and terminate the program. A frequency greater than 25 will give a warning.
To call the service first check if it is seen below:
rosservice list
You should see something like:
/ChangeStringOutput
/listener_node/get_loggers
/listener_node/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level
/rqt_gui_py_node_11776/get_loggers
/rqt_gui_py_node_11776/set_logger_level
/rqt_gui_py_node_11824/get_loggers
/rqt_gui_py_node_11824/set_logger_level
/talker_node/get_loggers
/talker_node/set_logger_level
Then, run the command below to change the text, with anything between the quotes as your desired output.
rosservice call /ChangeStringOutput "New Message"
To view tf frames, ensure the talker is running by making sure the launch file is running:
1st terminal: roscore
2nd terminal:
roslaunch beginner_tutorials pub_sub_launch.launch
3rd terminal:
rosrun rqt_tf_tree rqt_tf_tree
Also the pdf file for the frames (frames.pdf) is pregenerated and inside the /results directory.
To run the test, ensure you are in the catkin workspace first and run the below.
cd ~/catkin_ws/
catkin_make run_tests
Ctrl-c to end the script. You should see an output similar to:
[Testcase: testbeginner_tutorials_test] ... ok
[ROSTEST]-----------------------------------------------------------------------
[beginner_tutorials.rosunit-beginner_tutorials_test/testTalkerExists][passed]
SUMMARY
* RESULT: SUCCESS
* TESTS: 1
* ERRORS: 0
* FAILURES: 0
rostest log file is in /home/diane/.ros/log/rostest-diane-laptop-linux-19937.log
There is a rosbag file already recorded in the /results directory. To view it, do the following commands in a terminal.
cd ~/catkin_ws/
source devel/setup.bash
cd src/beginner_tutorials/results
rosbag info rosbag_record.bag
The output should be similar to this:
path: rosbag_record.bag
version: 2.0
duration: 15.0s
start: Nov 14 2021 17:47:16.61 (1636930036.61)
end: Nov 14 2021 17:47:31.57 (1636930051.57)
size: 184.1 KB
messages: 876
compression: none [1/1 chunks]
types: rosgraph_msgs/Log [acffd30cd6b6de30f120938c17c593fb]
std_msgs/String [992ce8a1687cec8c8bd883ec73ca41d1]
tf2_msgs/TFMessage [94810edda583a504dfda3829e70d7eec]
topics: /chatter 147 msgs : std_msgs/String
/rosout 293 msgs : rosgraph_msgs/Log (3 connections)
/rosout_agg 289 msgs : rosgraph_msgs/Log
/tf 147 msgs : tf2_msgs/TFMessage
If you want to record a new bag file then launch the launch file with the following argument like below:
roslaunch beginner_tutorials pub_sub_launch.launch record_bag:=True
To disable bag recording, just ignore the record_bag param as the default value is set to false in the launch file.
Open a terminal and start roscore
.
Then in a new terminal:
cd ~/catkin_ws/
source devel/setup.bash
rosbag play src/beginner_tutorials/results/rosbag_record.bag
In a third terminal:
rosrun beginner_tutorials listener