Ros2 basic test and example
This is a basic example and test for ros2
Preparing
- Create a folder. If default path as
~/jufengwu_ros2_test
, typemkdir ~/jufengwu_ros2_test/src
- Go to that folder. Type
cd . ~/jufengwu_ros2_test/src
- Download this code. Type
git clone https://github.com/JuFengWu/ros2_basic_test_and_example.git
- Make sure you have install Ros2 before. If yuo don't install before, please install by follow this tutorial. Currently, this example is for Ros2 Dashing versoin.
- Type
source /opt/ros/dashing/setup.bash
. - Type
colocn build
.
Dependencies:
Because it have yaml test, please the following packages
libyaml-cpp0.5v5
libyaml-cpp-dev
you can type sudo apt install libyaml-cpp0.5v5 libyaml-cpp-dev
to install those packages.
Run action
- Type
ros2 run action_cpp action_member_functions_server
to create a action server. - Type
ros2 run action_cpp not_composable_client
to create a action client. - Yuo will see the action demon.
Run topic test
- Open the first terminal and type
ros2 run topic_test topic_sub_node
- Open the other terminal and typ
ros2 run topic_test topic_pub_node
- You can see one terminal send message and the other listen message.
Run service test
- Open the first terminal and type
ros2 run service_test client_topic_node
- Open the other terminal and typ
ros2 run service_test service_topic_node
- You can see one terminal send service and the other listen it and send result back.
Run image test
- Go to source code folder. The default is
cd ~/jufengwu_ros2_test/src/ros2_basic_test_and_example
. - Type
ros2 run image_test pub_img
- Open the other terminal and type
ros2 run image_test sub_img
- You can see one terminal send image information and the other listen it and show the image
Run topic test in python
- Open the first terminal and type
ros2 run topic_py listener
- Open the other terminal and type
ros2 run topic_py talker
- You can see one terminal send message and the other listen message by python.
Run component
- Open the first terminal and type
ros2 run rclcpp_components component_container
- Open the second termianl and type
ros2 component load /ComponentManager component_test composition::Talker
, the talker will start to work. - Using the second terminal again and type
ros2 component load /ComponentManager component_test composition::Listener
, the listener will listen what the talker says.
Run life-cycle test
- Open the first terminal and type
ros2 run lifecycle lifecycle_listener
- Open the second terminal and type
ros2 run lifecycle lifecycle_talker
- Open the third terminal and type
ros2 run lifelifecycle_controller
- In the third terminal, you can choose which node state do you want to move.
⚠️ Before choose the node state, please read the ros2 node life cycle design on this page. If you switch the node state without follow the rules, it will show up some errors or warnings.
Run the ros1 ros2 bridge test
- This test will use ros1, please make sure you have insatll ros1 in your computer.
- This test is not only use this project, but also use this package. Please follow the instruction to install the package.
The steps are:
- Build this project.
- Open terminal and type
ros2 run bridge_test test_send
- Open a new terminal to create ros2 ros1_bridge by typing those cmds
. /opt/ros/melodic/setup.bash
. /opt/ros/dashing/setup.bash
export ROS_MASTER_URI=http://localhost:11311
ros2 run ros1_bridge dynamic_bridge __log_disable_rosout:=true
- Download this project and follow this instruction to build and install this project.
- Open the other terminal and type
roslaunch ros2_send_command_test test_bridge.launch
Others
comming soon!