-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAubo_Write_FOCUS.cpp
215 lines (152 loc) · 6.58 KB
/
Aubo_Write_FOCUS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*An Aubo task
Write Focus with Aubo i5
by Guo Haoran
*/
#include <moveit/move_group_interface/move_group_interface.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>
#include <moveit_msgs/DisplayRobotState.h>
#include <moveit_msgs/DisplayTrajectory.h>
#include <moveit_msgs/AttachedCollisionObject.h>
#include <moveit_msgs/CollisionObject.h>
#include <moveit_visual_tools/moveit_visual_tools.h>
#include <tf/LinearMath/Quaternion.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char** argv)
{
ros::init(argc, argv, "Aubo_Write_FOCUS");
ros::NodeHandle node_handle;
// Start a thread
ros::AsyncSpinner spinner(1);
spinner.start();
// Define the planning group name
static const std::string PLANNING_GROUP = "manipulator_i5";
// Create a planning group interface object and set up a planning group
moveit::planning_interface::MoveGroupInterface move_group(PLANNING_GROUP);
move_group.setPoseReferenceFrame("base_link");
// Create a planning scene interface object
moveit::planning_interface::PlanningSceneInterface planning_scene_interface;
// Create a robot model information object
const robot_state::JointModelGroup* joint_model_group =
move_group.getCurrentState()->getJointModelGroup(PLANNING_GROUP);
// Create an object of the visualization class
namespace rvt = rviz_visual_tools;
moveit_visual_tools::MoveItVisualTools visual_tools("base_link");
visual_tools.deleteAllMarkers();
// Load remote control tool
visual_tools.loadRemoteControl();
// Create text
Eigen::Isometry3d text_pose = Eigen::Isometry3d::Identity();
text_pose.translation().z() = 1.2;
visual_tools.publishText(text_pose, "AUBO Demo", rvt::RED, rvt::XLARGE);
// Text visualization takes effect
visual_tools.trigger();
// Get the coordinate system of the basic information
ROS_INFO_NAMED("tutorial", "Planning frame: %s", move_group.getPlanningFrame().c_str());
// Get the end of the basic information
ROS_INFO_NAMED("tutorial", "End effector link: %s", move_group.getEndEffectorLink().c_str());
// Visual terminal prompt (blocking) 阻塞函数,等待next按钮
visual_tools.prompt("Press 'next' in the RvizVisualToolsGui window to start the demo");
//*************************************************************************************************** Home Position
//获取txt文件中的坐标值
float init_coordinate[261][1];
float coordinate[3][87];
ifstream focusfile("//home//adan//coordinate//focus.txt");
for(int i = 0; i < 261; i++)
{
focusfile >> init_coordinate[i][0];
}
for(int j = 0; j < 87; j++)
{
for(int i = 0; i < 3; i++)
{
coordinate[i][j] = init_coordinate[3 * j + i][0];
}
}
focusfile.close();
//设置初始位置,6个数值对应六轴的角度
std::vector<double> home_position;
home_position.push_back(0);
home_position.push_back(0);
home_position.push_back(0);
home_position.push_back(0);
home_position.push_back(0);
home_position.push_back(0);
std::vector<double> first_position;
first_position.push_back(2.2);
first_position.push_back(0);
first_position.push_back(1.57);
first_position.push_back(0);
first_position.push_back(0);
first_position.push_back(0);
move_group.setJointValueTarget(first_position);//设置关节坐标目标
move_group.move(); //plan+execute=move
//开始设置路径值
tf::Quaternion q;
q.setRPY(3.14,0,0); //设置rpy
for(int i = 0; i < 87; i++)
{
geometry_msgs::Pose target_pose1;
target_pose1.position.x = coordinate[0][i];
target_pose1.position.y = coordinate[1][i];
target_pose1.position.z = coordinate[2][i];
target_pose1.orientation.x = q.x();
target_pose1.orientation.y = q.y();
target_pose1.orientation.z = q.z();
target_pose1.orientation.w = q.w();
move_group.setPoseTarget(target_pose1);//设置位置坐标
// Call the planner for planning calculations Note: This is just planning
moveit::planning_interface::MoveGroupInterface::Plan my_plan;
bool success = (move_group.plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
ROS_INFO_NAMED("tutorial", "Visualizing plan 1 (pose goal) %s", success ? "Success" : "FAILED");
// visual planning path in Rviz
visual_tools.deleteAllMarkers();
visual_tools.publishAxisLabeled(target_pose1, "pose1");
visual_tools.publishText(text_pose, "AUBO Pose Goal Example1", rvt::RED, rvt::XLARGE);
// Parameter 1 (trajectory_): path information
// Parameter 2 (JointModelGroup): Joint angle information and arm model information of the initial pose
visual_tools.publishTrajectoryLine(my_plan.trajectory_, joint_model_group);
visual_tools.trigger();
// Perform planning actions
move_group.execute(my_plan);
}
/*
move_group.setJointValueTarget(first_position);//设置关节坐标目标
move_group.move(); //plan+execute=move
for(int i = 33; i < 87; i++)
{
geometry_msgs::Pose target_pose1;
target_pose1.position.x = coordinate[0][i];
target_pose1.position.y = coordinate[1][i];
target_pose1.position.z = coordinate[2][i];
target_pose1.orientation.x = q.x();
target_pose1.orientation.y = q.y();
target_pose1.orientation.z = q.z();
target_pose1.orientation.w = q.w();
move_group.setPoseTarget(target_pose1);//设置位置坐标
// Call the planner for planning calculations Note: This is just planning
moveit::planning_interface::MoveGroupInterface::Plan my_plan;
bool success = (move_group.plan(my_plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
ROS_INFO_NAMED("tutorial", "Visualizing plan 1 (pose goal) %s", success ? "Success" : "FAILED");
// visual planning path in Rviz
visual_tools.deleteAllMarkers();
visual_tools.publishAxisLabeled(target_pose1, "pose1");
visual_tools.publishText(text_pose, "AUBO Pose Goal Example1", rvt::RED, rvt::XLARGE);
// Parameter 1 (trajectory_): path information
// Parameter 2 (JointModelGroup): Joint angle information and arm model information of the initial pose
visual_tools.publishTrajectoryLine(my_plan.trajectory_, joint_model_group);
visual_tools.trigger();
// Perform planning actions
move_group.execute(my_plan);
}
*/
// Move to the home point position
move_group.setJointValueTarget(home_position);
move_group.move();
visual_tools.prompt("Press 'next' in the RvizVisualToolsGui window to end the demo");
// END_TUTORIAL
ros::shutdown();
return 0;
}