-
Notifications
You must be signed in to change notification settings - Fork 13
cartesian_pathサンプルの追加 #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KuraZuzu
wants to merge
7
commits into
ros2
Choose a base branch
from
feature/cartesian_path_example
base: ros2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c4ffa78
左アームで円運動を行うcppプログラム追加
KuraZuzu a0bcdca
READMEにサンプルの手順を追加
KuraZuzu 2fb5e4e
フォーマットを修正
KuraZuzu 8e72219
ament_uncrustifyのフォーマットを適用
KuraZuzu 2f743fd
[suggestion]MoveItのリンクをhumbleからjazzyに変更
KuraZuzu 2bf0478
cartesian_pathの説明をExampleの目次に追加
KuraZuzu 16b2dec
描く円の中心座標をキリの良い数値に変更
KuraZuzu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2025 RT Corporation | ||
// | ||
// 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. | ||
|
||
// Reference: | ||
// https://github.com/ros-planning/moveit2_tutorials/blob | ||
// /a547cf49ff7d1fe16a93dfe020c6027bcb035b51/doc/move_group_interface | ||
// /src/move_group_interface_tutorial.cpp | ||
|
||
#include <cmath> | ||
#include <vector> | ||
|
||
#include "angles/angles.h" | ||
#include "geometry_msgs/msg/pose.hpp" | ||
#include "geometry_msgs/msg/quaternion.hpp" | ||
#include "moveit/move_group_interface/move_group_interface.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" | ||
|
||
using MoveGroupInterface = moveit::planning_interface::MoveGroupInterface; | ||
|
||
static const rclcpp::Logger LOGGER = rclcpp::get_logger("cartesian_path"); | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
rclcpp::init(argc, argv); | ||
rclcpp::NodeOptions node_options; | ||
node_options.automatically_declare_parameters_from_overrides(true); | ||
auto move_group_arm_node = rclcpp::Node::make_shared("move_group_arm_node", node_options); | ||
auto move_group_gripper_node = rclcpp::Node::make_shared("move_group_gripper_node", node_options); | ||
// For current state monitor | ||
rclcpp::executors::SingleThreadedExecutor executor; | ||
executor.add_node(move_group_arm_node); | ||
executor.add_node(move_group_gripper_node); | ||
std::thread([&executor]() {executor.spin();}).detach(); | ||
|
||
MoveGroupInterface move_group_arm(move_group_arm_node, "l_arm_group"); | ||
move_group_arm.setMaxVelocityScalingFactor(0.1); // Set 0.0 ~ 1.0 | ||
move_group_arm.setMaxAccelerationScalingFactor(1.0); // Set 0.0 ~ 1.0 | ||
|
||
MoveGroupInterface move_group_gripper(move_group_gripper_node, "l_gripper_group"); | ||
move_group_gripper.setMaxVelocityScalingFactor(1.0); // Set 0.0 ~ 1.0 | ||
move_group_gripper.setMaxAccelerationScalingFactor(1.0); // Set 0.0 ~ 1.0 | ||
auto gripper_joint_values = move_group_gripper.getCurrentJointValues(); | ||
|
||
// SRDFに定義されている"l_arm_init_pose"の姿勢にする | ||
move_group_arm.setNamedTarget("l_arm_init_pose"); | ||
move_group_arm.move(); | ||
|
||
// ハンドを開く | ||
gripper_joint_values[0] = angles::from_degrees(-40); | ||
move_group_gripper.setJointValueTarget(gripper_joint_values); | ||
move_group_gripper.move(); | ||
|
||
// 座標(x=0.3, y=0.2 z=0.1)を中心に、XY平面上に半径0.1 mの円を3回描くように手先を動かす | ||
std::vector<geometry_msgs::msg::Pose> waypoints; | ||
float num_of_waypoints = 30; | ||
int repeat = 3; | ||
float radius = 0.1; | ||
|
||
geometry_msgs::msg::Point center_position; | ||
center_position.x = 0.3; | ||
center_position.y = 0.2; | ||
center_position.z = 0.1; | ||
|
||
geometry_msgs::msg::Pose target_pose; | ||
tf2::Quaternion q; | ||
q.setRPY(angles::from_degrees(-90), 0, 0); | ||
target_pose.orientation = tf2::toMsg(q); | ||
|
||
for (int r = 0; r < repeat; r++) { | ||
for (int i = 0; i < num_of_waypoints; i++) { | ||
float theta = 2.0 * M_PI * (i / static_cast<float>(num_of_waypoints)); | ||
target_pose.position.x = center_position.x + radius * std::cos(theta); | ||
target_pose.position.y = center_position.y + radius * std::sin(theta); | ||
target_pose.position.z = center_position.z; | ||
waypoints.push_back(target_pose); | ||
} | ||
} | ||
|
||
moveit_msgs::msg::RobotTrajectory trajectory; | ||
const double eef_step = 0.01; | ||
move_group_arm.computeCartesianPath(waypoints, eef_step, trajectory); | ||
move_group_arm.execute(trajectory); | ||
|
||
// SRDFに定義されている"l_arm_init_pose"の姿勢にする | ||
move_group_arm.setNamedTarget("l_arm_init_pose"); | ||
move_group_arm.move(); | ||
|
||
// ハンドを閉じる | ||
gripper_joint_values[0] = 0; | ||
move_group_gripper.setJointValueTarget(gripper_joint_values); | ||
move_group_gripper.move(); | ||
|
||
rclcpp::shutdown(); | ||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examplesの目次にも追加お願いします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
追加しました。