added code templet
This commit is contained in:
parent
44e42acfd7
commit
a3a386ad3d
17
code-snippets/ros2 node templete/.vscode/c_cpp_properties.json
vendored
Normal file
17
code-snippets/ros2 node templete/.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/opt/ros/foxy/include"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "clang-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
69
code-snippets/ros2 node templete/.vscode/settings.json
vendored
Normal file
69
code-snippets/ros2 node templete/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"csignal": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"strstream": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"complex": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"future": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"shared_mutex": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cfenv": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp"
|
||||
}
|
||||
}
|
25
code-snippets/ros2 node templete/my_cpp_pkg/CMakeLists.txt
Normal file
25
code-snippets/ros2 node templete/my_cpp_pkg/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(my_cpp_pkg)
|
||||
|
||||
# Default to C++14
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(-Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
||||
# find dependencies
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
|
||||
add_executable(cpp_node src/my_first_node.cpp)
|
||||
ament_target_dependencies(cpp_node rclcpp)
|
||||
|
||||
install(TARGETS
|
||||
cpp_node
|
||||
DESTINATION lib/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
ament_package()
|
20
code-snippets/ros2 node templete/my_cpp_pkg/package.xml
Normal file
20
code-snippets/ros2 node templete/my_cpp_pkg/package.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>my_cpp_pkg</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="ed@todo.todo">ed</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
@ -0,0 +1,32 @@
|
||||
#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::seconds(1),
|
||||
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;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
class MyCustomNode : public rclcpp::Node // MODIFY NAME
|
||||
{
|
||||
public:
|
||||
MyCustomNode() : Node("node_name") // MODIFY NAME
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
rclcpp::init(argc, argv);
|
||||
auto node = std::make_shared<MyCustomNode>(); // MODIFY NAME
|
||||
rclcpp::spin(node);
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
27
code-snippets/ros2 node templete/my_py_pkg/my_py_pkg/my_first_node.py
Executable file
27
code-snippets/ros2 node templete/my_py_pkg/my_py_pkg/my_first_node.py
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
|
||||
|
||||
class MyNode(Node):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("py_test")
|
||||
self.counter_ = 0
|
||||
self.get_logger().info("Hello ROS2")
|
||||
self.create_timer(0.5, self.timer_callback)
|
||||
|
||||
def timer_callback(self):
|
||||
self.counter_ += 1
|
||||
self.get_logger().info("Hello " + str(self.counter_))
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
node = MyNode()
|
||||
rclpy.spin(node)
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,19 @@
|
||||
#!/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
|
||||
rclpy.spin(node)
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
20
code-snippets/ros2 node templete/my_py_pkg/package.xml
Normal file
20
code-snippets/ros2 node templete/my_py_pkg/package.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>my_py_pkg</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="ed@todo.todo">ed</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<depend>rclpy</depend>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
4
code-snippets/ros2 node templete/my_py_pkg/setup.cfg
Normal file
4
code-snippets/ros2 node templete/my_py_pkg/setup.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
[develop]
|
||||
script-dir=$base/lib/my_py_pkg
|
||||
[install]
|
||||
install-scripts=$base/lib/my_py_pkg
|
26
code-snippets/ros2 node templete/my_py_pkg/setup.py
Normal file
26
code-snippets/ros2 node templete/my_py_pkg/setup.py
Normal file
@ -0,0 +1,26 @@
|
||||
from setuptools import setup
|
||||
|
||||
package_name = 'my_py_pkg'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='0.0.0',
|
||||
packages=[package_name],
|
||||
data_files=[
|
||||
('share/ament_index/resource_index/packages',
|
||||
['resource/' + package_name]),
|
||||
('share/' + package_name, ['package.xml']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='ed',
|
||||
maintainer_email='ed@todo.todo',
|
||||
description='TODO: Package description',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
"py_node = my_py_pkg.my_first_node:main"
|
||||
],
|
||||
},
|
||||
)
|
@ -0,0 +1,23 @@
|
||||
# Copyright 2015 Open Source Robotics Foundation, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ament_copyright.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.copyright
|
||||
@pytest.mark.linter
|
||||
def test_copyright():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found errors'
|
@ -0,0 +1,25 @@
|
||||
# Copyright 2017 Open Source Robotics Foundation, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ament_flake8.main import main_with_errors
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.flake8
|
||||
@pytest.mark.linter
|
||||
def test_flake8():
|
||||
rc, errors = main_with_errors(argv=[])
|
||||
assert rc == 0, \
|
||||
'Found %d code style errors / warnings:\n' % len(errors) + \
|
||||
'\n'.join(errors)
|
@ -0,0 +1,23 @@
|
||||
# Copyright 2015 Open Source Robotics Foundation, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ament_pep257.main import main
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.linter
|
||||
@pytest.mark.pep257
|
||||
def test_pep257():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found code style errors / warnings'
|
@ -1,10 +1,22 @@
|
||||
# Setting up VSCode
|
||||
# Setup
|
||||
## Installing VSCode
|
||||
first install vscode using snap
|
||||
```bash
|
||||
sudo snap install code --classic
|
||||
```
|
||||
then add the `ROS` extension from Microsoft.
|
||||
|
||||
## Installing Colcon
|
||||
To install colcon first run the sudo apt install command.
|
||||
``` bash
|
||||
sudo apt install python3-colcon-common-extensions
|
||||
```
|
||||
|
||||
then add the colcon autocomplete to the `.bashrc` file.
|
||||
``` bash
|
||||
echo 'source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash' >> ~/.bashrc
|
||||
```
|
||||
|
||||
|
||||
# Setting up the ROS2 Package Workspace
|
||||
first create the folder for the package usual it is called `packagename_ws`where `_ws` stands for then you enter the directory and create another directory called `src` then run the `colcon build` command.
|
||||
@ -13,12 +25,9 @@ colcon build
|
||||
```
|
||||
next go into the `install` folder and add the `setup.bash` source command to your `~/.bashrc`
|
||||
```bash
|
||||
...
|
||||
source /home/username/package_ws/install/setup.bash
|
||||
echo "source /home/username/package_ws/install/setup.bash" >> ~/.bashrc
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Creating a Python Packages
|
||||
#### Setting Up
|
||||
Go to the workspace folder that was created in the last step and open the `src` folder. In this folder run this command.
|
||||
@ -88,6 +97,7 @@ then just like before run the `source ~/.bashrc` command to refresh everything a
|
||||
## Creating a C++ Packages
|
||||
Go to the workspace folder that was created in the last step and open the `src` folder. In this folder run this command.
|
||||
```bash
|
||||
ros2 pkg create {package_name} --build-type ament_cmake
|
||||
ros2 pkg create {package_name} --build-type ament_cmake --dependencies rclcpp
|
||||
```
|
||||
|
||||
![Image title](img/ros2_nodes.png)
|
||||
|
10
docs/General ROS 2/Colcon.md
Executable file
10
docs/General ROS 2/Colcon.md
Executable file
@ -0,0 +1,10 @@
|
||||
# Installing
|
||||
To install colcon first run the sudo apt install command.
|
||||
``` bash
|
||||
sudo apt install python3-colcon-common-extensions
|
||||
```
|
||||
|
||||
then add the colcon autocomplete to the `.bashrc` file.
|
||||
``` bash
|
||||
echo 'source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash' >> ~/.bashrc
|
||||
```
|
@ -20,8 +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 title="slam.yaml"
|
||||
```yaml
|
||||
slam_toolbox:
|
||||
ros__parameters:
|
||||
|
||||
@ -101,13 +100,12 @@ 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"
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### Navigation
|
||||
To launch the navigation program on the Turtlebot 4 run the following commands. One per terminal window making sure to execute them on the Remote PC.
|
||||
|
||||
```bash
|
||||
# Terminal Window 1
|
||||
ros2 launch turtlebot4_navigation localization.launch.py map:/path/to/map.yaml
|
||||
@ -119,4 +117,4 @@ ros2 launch turtlebot4_navigation nav2.launch.py
|
||||
ros2 launch turtlebot4_viz view_robot.launch.py
|
||||
```
|
||||
|
||||
Use the `2D Pose Estimate` to select the spot on the map were the robot is at when the Navigation is launched. Then use the `Nav2 Goal` button to select where the robot should navigate to.
|
||||
Use the `2D Pose Estimate` to select the spot on the map were the robot is at when the Navigation is launched. Then use the `Nav2 Goal` button to select where the robot should navigate to.
|
BIN
docs/img/ros2_nodes.png
Executable file
BIN
docs/img/ros2_nodes.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 343 KiB |
@ -39,7 +39,7 @@ extra:
|
||||
link: https://gitea.locker98.com
|
||||
|
||||
copyright: |
|
||||
© 2023 <a href="https://github.com/thelocker98" target="_blank" rel="noopener">locker98</a>
|
||||
© 2024 <a href="https://github.com/thelocker98" target="_blank" rel="noopener">locker98</a>
|
||||
|
||||
markdown_extensions:
|
||||
- pymdownx.highlight:
|
||||
@ -56,4 +56,4 @@ markdown_extensions:
|
||||
- attr_list
|
||||
- pymdownx.emoji:
|
||||
emoji_index: !!python/name:materialx.emoji.twemoji
|
||||
emoji_generator: !!python/name:materialx.emoji.to_svg
|
||||
emoji_generator: !!python/name:materialx.emoji.to_svg
|
||||
|
Loading…
Reference in New Issue
Block a user