ROS Essential
To create a PKG
cd src
ros2 pkg create --build-type ament_python your_package_name
ros2 pkg create --build-type ament_python --node-name navigate_to_target turtlebot_navigator
#This will create a new package called turtlebot3_navigator with a Python node named navigate_to_target.
#to include srv
ros2 pkg create --build-type ament_python --license Apache-2.0 service_bot --dependencies rclpy bot
Source the setup file:
source ~/ros_ws/install/setup.bash
Delete the Entire Build and Install Directories:
cd ~/ros_ws
rm -rf build install log
Building Package
cd ~/ros_ws
colcon clean --packages-select alphabet_publisher_pkg #clean any deleted pkg file
colcon build --packages-select alphabet_publisher_pkg #normal build
colcon build --packages-select action_py --symlink-install #if you use this, No need to build each and everytime. Just the source file .bashrc
Monitoring ROS Topic
ros2 topic echo /topic_name
Clean the WS
cd ~/ros_ws
rm -rf build install log
colcon build --packages-skip-build-finished --symlink-install
colcon clean --packages-select lidar_bot
Files Access
chmod +x service_server.py
Creating Action Service
ros2 pkg create my_robot
mkdir srv action msg
#CMakeLists.txt
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"action/CountUntil.action"
)
ament_export_dependencies(rosidl_default_runtime)
#package.xml
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
Node Template
#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
class MyCustomNode(Node): # MODIFY NAME
def __init__(self):
super().__init__("node_name") # MODIFY NAME
def main(args=None):
rclpy.init(args=args)
node = MyCustomNode() # MODIFY NAME
try:
rclpy.spin(node)
except KeyboardInterrupt:
pass
finally:
node.destroy_node()
rclpy.shutdown()
if __name__ == "__main__":
main()
My friend, feel free to use my code:)
Launching Task #3: turtlebot_navigator
#from 1 to 4
#1
ros2 launch alphabet_publisher_pkg start_publisher.launch.py
#2
ros2 launch alphabet_publisher_pkg conditional_launch.py
ros2 topic echo /topic_name
#3
ros2 interface show robot_interface/msg/PositionFeedback
#4
ros2 launch turtlebot3_gazebo turtlebot3_house.launch.py
ros2 run turtlebot_navigator navigate_to_target
ros2 run turtlebot_navigator odom_subscriber
Launching Task #5: Lidar
#1
ros2 run action_py obstacle_avoidance_server
ros2 run action_py obstacle_avoidance_client
Launching Task #4: Server Request
#1
ros2 run my_package turn_server
ros2 run my_package turn_client "Turn Right"