From d1920d9c63706fa80d6c6982a2380a92f33d4edf Mon Sep 17 00:00:00 2001 From: locker98 Date: Wed, 27 Nov 2024 22:44:36 -0500 Subject: [PATCH] updated notes --- docs/General ROS 2/Building ROS2 packages.md | 67 +++++++++++++++++++- docs/General ROS 2/ROS 2 Nodes.md | 3 + docs/TurtleBot 4/SLAM and Navigation.md | 4 +- 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100755 docs/General ROS 2/ROS 2 Nodes.md diff --git a/docs/General ROS 2/Building ROS2 packages.md b/docs/General ROS 2/Building ROS2 packages.md index adcb4db..fdc87ad 100755 --- a/docs/General ROS 2/Building ROS2 packages.md +++ b/docs/General ROS 2/Building ROS2 packages.md @@ -39,8 +39,8 @@ add your code in to the folder with the `__init__.py`. This is usually in the fo #### Programming create a python file for your first node. -`my_first_node.py` -```python + +```python title="my_first_node.py" #!/usr/bin/env python import rclpy from rclpy.node import Node @@ -100,4 +100,65 @@ Go to the workspace folder that was created in the last step and open the `src` ros2 pkg create {package_name} --build-type ament_cmake --dependencies rclcpp ``` -![Image title](img/ros2_nodes.png) + +next create a file in `{package_name}/src`and call it `node_name.cpp` + +```cpp title="node_name.cpp" +#include "rclcpp/rclcpp.hpp" + +class MyNode : public rclcpp::Node +{ +public: +   MyNode() : Node("cpp_test"), counter_(0) +   { +       RCLCPP_INFO(this->get_logger(), "Hello Cpp Node"); + +       timer_ = this->create_wall_timer(std::chrono::milliseconds(500), +                                        std::bind(&MyNode::timerCallback, this)); +   } + +private: +   void timerCallback() +   { +       counter_++; +       RCLCPP_INFO(this->get_logger(), "Hello %d", counter_); +   } + +   rclcpp::TimerBase::SharedPtr timer_; +   int counter_; +}; + +int main(int argc, char **argv) +{ +   rclcpp::init(argc, argv); +   auto node = std::make_shared(); +   rclcpp::spin(node); +   rclcpp::shutdown(); +   return 0; +} +``` + +Next open the program menu on VSCode using `CTRL + SHIFT + P`. Select the `C/C++: Edit Configurations (JSON)`. Make Sure the `c_cpp_properties.json` file has the `"/opt/ros/humble/include/**"` include + +```json hl_lines="9" +{ + "configurations": [ + { + "browse": { + "databaseFilename": "${default}", + "limitSymbolsToIncludedHeaders": false + }, + "includePath": [ + "/opt/ros/humble/include/**", + "/usr/include/**" + ], + "name": "ROS", + "intelliSenseMode": "gcc-x64", + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu11", + "cppStandard": "c++14" + } + ], + "version": 4 +} +``` \ No newline at end of file diff --git a/docs/General ROS 2/ROS 2 Nodes.md b/docs/General ROS 2/ROS 2 Nodes.md new file mode 100755 index 0000000..54c77f8 --- /dev/null +++ b/docs/General ROS 2/ROS 2 Nodes.md @@ -0,0 +1,3 @@ +# Nodes +Nodes are the different ROS topics. in the below picture the nodes are in blue. +![[ros2_nodes.png|900]] \ No newline at end of file diff --git a/docs/TurtleBot 4/SLAM and Navigation.md b/docs/TurtleBot 4/SLAM and Navigation.md index 7fe25b0..8a9a766 100755 --- a/docs/TurtleBot 4/SLAM and Navigation.md +++ b/docs/TurtleBot 4/SLAM and Navigation.md @@ -20,7 +20,7 @@ Once this command is running then you should be able to drive the robot like nor ### Launching the SLAM command Here is the `slam.yaml` config file. You can change the resolution by changing the resolution parameter, by default it is 0.05 but i have had great success when running synchronous SLAM with values as low as 0.01. -```yaml +```yaml title="slam.yaml" slam_toolbox: ros__parameters: @@ -100,7 +100,7 @@ ros2 launch turtlebot4_viz view_robot.launch.py Once you are done creating the map make sure you save it. ```bash - +ros2 run nav2_map_server map_saver_cli -f "map_name" ```