updated notes
This commit is contained in:
parent
a3a386ad3d
commit
d1920d9c63
@ -39,8 +39,8 @@ add your code in to the folder with the `__init__.py`. This is usually in the fo
|
|||||||
|
|
||||||
#### Programming
|
#### Programming
|
||||||
create a python file for your first node.
|
create a python file for your first node.
|
||||||
`my_first_node.py`
|
|
||||||
```python
|
```python title="my_first_node.py"
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import rclpy
|
import rclpy
|
||||||
from rclpy.node import Node
|
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
|
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<MyNode>();
|
||||||
|
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
|
||||||
|
}
|
||||||
|
```
|
3
docs/General ROS 2/ROS 2 Nodes.md
Executable file
3
docs/General ROS 2/ROS 2 Nodes.md
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
# Nodes
|
||||||
|
Nodes are the different ROS topics. in the below picture the nodes are in blue.
|
||||||
|
![[ros2_nodes.png|900]]
|
@ -20,7 +20,7 @@ Once this command is running then you should be able to drive the robot like nor
|
|||||||
|
|
||||||
### Launching the SLAM command
|
### 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.
|
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:
|
slam_toolbox:
|
||||||
ros__parameters:
|
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.
|
Once you are done creating the map make sure you save it.
|
||||||
```bash
|
```bash
|
||||||
|
ros2 run nav2_map_server map_saver_cli -f "map_name"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user