๋ก๋ดํ์ ์ง์ ๋ง๋ค์ด๋ณด๊ธฐ ์ ์ ๋จผ์ ๋ก๋ดํ์ด ์ด๋ป๊ฒ ์ด๋ฃจ์ด์ก๋์ง, ๋ค๋ฅธ ์ฌ๋๋ค์ด ๋จผ์ ๋ง๋ ๋ฐฉ์์ ์ด๋ค ๋ฐฉ์์ธ์ง ์์๋ณด๊ณ ์ ํ์๋ค.
๋ฐ๋ผ์ ๋ค์ ๋งํฌ๋ฅผ ํตํด์ ํํ ๋ฆฌ์ผ์ ๊ณต๋ถํด๋ณด๊ธฐ ์์ํ๋ค.
Your First C++ MoveIt Project — MoveIt Documentation: Humble documentation
3.2 Examine the code The first thing we do is create the MoveGroupInterface. This object will be used to interact with move_group, which allows us to plan and execute trajectories. Note that this is the only mutable object that we create in this program. A
moveit.picknik.ai
cpp ํ๋ก์ ํธ๋ฅผ ๋ง๋๋ ๊ฒ๋ถํฐ ์์ํด์ Rviz ๊ณต๋ถ๊น์ง ๋ค๋ค๋ณด๊ณ ์ ํ๋ค.
1. Your First C++ MoveIt Project
(1) ์ค๋นํ๊ธฐ
์ด ๋จ๊ณ์์๋ ์์ ๊ธ์ ์ฐธ๊ณ ํ์ฌ ๋ฏธ๋ฆฌ ์ค์น๋ฅผ ์งํํ๋ฉด ๋ ๊ฒ์ด๋ค.
2023.02.24 - [ํ๊ตฌ ๐พ/2023 ํ๊ตฌ ์ด์ผ๊ธฐ] - [23' Robot Arm Project] Day1 - Setting
[23' Robot Arm Project] Day1 - Setting
23๋ ๋์ ํ๋ก์ ํธ๋ก ๋ก๋ดํ ๋ง๋ค๊ธฐ ํ๋ก์ ํธ๋ฅผ ์งํํ๊ณ ์ ํ๋ค. ์๋ ํด๋จธ๋ ธ์ด๋๋ฅผ ๋ง๋ค์ด๋ณด๋ ค๋ ์ผ์ฌ์ฐฌ ๊ณํ์ ๊ฐ์ง๊ณ 1๋ฌ ๊ฐ๋์ ๋ ผ๋ฌธ ํ์์ ํ ๊ฒฐ๊ณผ, ํ์ฌ ๊ณ 3์ธ ์ง๊ธ ์ ์ ์ ๊น์ง ๋ฌด๋ฆฌํ
mosw.tistory.com
(2) ํจํค์ง ๋ง๋ค๊ธฐ
ํฐ๋ฏธ๋์ ์ด๊ณ ROS2๋ฅผ ๋ถ๋ฌ์จ ๋ค ws_moveit2๋ก ์ด๋ํ์ฌ src์์ ๋ค์ ๋ช ๋ น์ ํตํด ์ ํจํค์ง๋ฅผ ๋ง๋ ๋ค.
ros2 pkg create \
--build-type ament_cmake \
--dependencies moveit_ros_planning_interface rclcpp \
--node-name hello_moveit hello_moveit
moveit_ros_planning_interface์ rclcpp์ ์ข ์์ ์ผ๋ก ์ถ๊ฐํ๋ค. ์ด๊ฒ๋ค์ package.xml๊ณผ Cmakelist.txt ํ์ผ์ ์ด ๋ ํจํค์ง์ ์์กดํ ์ ์๋๋ก ๋ณ๊ฒฝ๋๋ค.
์ดํ ws_moveit2/src/hello_moveit.cpp์ ์๋ก ๋ง๋ค์ด ์ฐ๋ค.
(3) ROS ๋ ธ๋ ๋ฐ ์คํ๊ธฐ ์์ฑ
#include <memory>
#include <rclcpp/rclcpp.hpp>
#include <moveit/move_group_interface/move_group_interface.h>
int main(int argc, char * argv[])
{
// Initialize ROS and create the Node
rclcpp::init(argc, argv);
auto const node = std::make_shared<rclcpp::Node>(
"hello_moveit",
rclcpp::NodeOptions().automatically_declare_parameters_from_overrides(true)
);
// Create a ROS logger
auto const logger = rclcpp::get_logger("hello_moveit");
// Next step goes here
// Shutdown ROS
rclcpp::shutdown();
return 0;
}
๋ค์ ์ฝ๋๋ฅผ ์์ฑํ์
1) ๋น๋ ๋ฐ ์คํ
์งํํ๊ธฐ ์ ์ ํ๋ก๊ทธ๋จ์ ๋น๋ํ๊ณ ์คํํ๊ณ ์ ํ๋ค.
ws_moveit2๋ก ์ด๋ํ์ฌ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ค.
colcon build --mixin debug
์ดํ ์ ํฐ๋ฏธ๋์์ ์์ ๊ณต๊ฐ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๋ค.
cd ~/ws_moveit2
source install/setup.bash
๊ทธ ์ดํ ํ๋ก๊ทธ๋จ์ ์คํํ๋ฉด ์ถ๋ ฅ ์์ด ์ข ๋ฃ๋๋ค.
ros2 run hello_moveit hello_moveit
2) ์ฝ๋ ๋ด์ฉ
์๋จ์ ์๋ ํค๋ ๋ถ๋ถ์ ์ผ๋ถ ํ์ค cpp ํค๋์ ๋์ค์ ์ฌ์ฉํ ROS ๋ฐ moveit์ฉ ํค๋์ด๋ค.
์ดํ rclcpp๋ฅผ ์ด๊ธฐํํ๋ ์ผ๋ถ ํธ์ถ์ด ์๊ณ ๋ ธ๋๋ฅผ ์์ฑํ๋ค.
auto const node = std::make_shared<rclcpp::Node>(
"hello_moveit",
rclcpp::NodeOptions().automatically_declare_parameters_from_overrides(true)
);
์ฌ๊ธฐ์ ์ฒซ๋ฒ์งธ ์ค์ ROS๊ฐ ๊ณ ์ ํ ๋ ธ๋๋ฅผ ๋ง๋๋๋ฐ ์ฌ์ฉํ ๋ฌธ์์ด์ด๋ค.
์ดํ ๋ด์ฉ์ ROS ๋งค๊ฐ ๋ณ์๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์๋๋ฌธ์ moveit์ ํ์ํ ์ค์ด๋ค.
๋ง์ง๋ง์ผ๋ก ROS๋ฅผ ์ข ๋ฃํ๋ ์ฝ๋๊ฐ ์กด์ฌํ๋ค.
(4) MoveGroupInterface์ ์ฌ์ฉํ ๊ณํ๊ณผ ์คํ
์์ 18๋ฒ์งธ ์ค์ ์ฃผ์ ๋์ ๋ค์ ๋ด์ฉ์ ์ถ๊ฐํ๋ค.
// Create the MoveIt MoveGroup Interface
using moveit::planning_interface::MoveGroupInterface;
auto move_group_interface = MoveGroupInterface(node, "panda_arm");
// Set a target Pose
auto const target_pose = []{
geometry_msgs::msg::Pose msg;
msg.orientation.w = 1.0;
msg.position.x = 0.28;
msg.position.y = -0.2;
msg.position.z = 0.5;
return msg;
}();
move_group_interface.setPoseTarget(target_pose);
// Create a plan to that target pose
auto const [success, plan] = [&move_group_interface]{
moveit::planning_interface::MoveGroupInterface::Plan msg;
auto const ok = static_cast<bool>(move_group_interface.plan(msg));
return std::make_pair(ok, msg);
}();
// Execute the plan
if(success) {
move_group_interface.execute(plan);
} else {
RCLCPP_ERROR(logger, "Planing failed!");
}
1) ๋น๋ ๋ฐ ์คํ
์ํฌ ์คํ์ด์ค์์ ๋ค์ ๋ช ๋ น์ ์คํํ๋ค.
colcon build --mixin debug
์ดํ ๋ค๋ฅธ ํฐ๋ฏธ๋์์ ์์ ๊ณต๊ฐ์ ์์ฑํ๊ณ ๋ค์ ์ฝ๋๋ฅผ ์คํํ๋ค.
ros2 launch moveit2_tutorials demo.launch.py
์ดํ Displays ์๋์ฐ์ ์๋ MotionPlaning/Planning Request์์ Query Goal State์ ๋ฐ์ค๋ฅผ ์ฒดํฌ ํด์ ํ๋ค.
์ดํ 3๋ฒ์งธ ํฐ๋ฏธ๋์์ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ค.
ros2 run hello_moveit hello_moveit
๊ทธ๋ฌ๋ฉด ๋ก๋ด์ด ๋ค์๊ณผ ๊ฐ์ด ์์ง์ผ ๊ฒ์ด๋ค.
Error
๋ง์ผ ๋ฐ๋ชจ ํ์ผ์ ๋จผ์ ์คํํ์ง ์์ผ๋ฉด ๋ค์ ์ค๋ฅ๋ฅผ ์ถ๋ ฅํ๊ณ ์ข ๋ฃ๋๋ค.
[ERROR] [1644181704.350825487] [hello_moveit]: Could not find parameter robot_description and did not receive robot_description via std_msgs::msg::String subscription within 10.000000 seconds.
-------------------------------------------------------
๋ญ๊ฐ ์ค๋ฅ๊ฐ ๋ฌ๋ค.
์์ธ์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง, ๋ด๋ถ์ ์ผ๋ก ๋ญ๊ฐ ์ถฉ๋๋๊ฑฐ ๊ฐ์์ ๋ค์ ์ด๊ธฐํํ๊ณ ๋ค์ ์งํํ๋ค.
๊ทธ๋ฌ๋๋ rviz2์์ ros2๋ฅผ ๋๋ฆฌ๋ฉด์ ํํ ๋ฆฌ์ผ์ ๋ค์ ๋๋ฆฌ๋ ๊ณผ์ ์์ ๋ด๋ถ์ ์ผ๋ก ์ค๋ฅ๊ฐ ๋ฌ๋ค.
segmentation fault(core dumped) ๋ผ๋ ์ค๋ฅ์๋ค. ์ด๋ฅผ ์ฐพ์๋ณด๋, ํ์ฉ๋์ง ์์ ๋ฉ๋ชจ๋ฆฌ์ ์ ๊ทผ ์๋ ํน์ ํ์ฉ๋์ง ์์ ๋ฐฉ๋ฒ์ผ๋ก ์ ๊ทผ ์๋๋ผ๊ณ ํ๋๋ฐ ์ฌ๊ธฐ์ ์๋ง๋ ์ฑ๋ฅ ์ด์... ๋ก ์๋ง๋ ์๋ ๊ฒ์ด ์๋๊น? ๋ผ๋ ์๊ฐ์ ํด๋ณด์๊ณ , ์ดํ ์ผ๋จ ํํ ๋ฆฌ์ผ์ ํ์ผ์ ์ถํ ๋ก๋ด์ ROS๋ก ๊ฐ๋ฐํ๋ ๊ณผ์ ์์ ๋ฏ์ด๋ณด๋ฉด์ ์ฐธ๊ณ ํ๊ณ ์ ํ์๊ณ , ์ผ๋จ ์ค๊ณ๋ฅผ ํด๋ณด๊ณ ์ ํ์๋ค.