xarm_simple_planner_test.cpp
Go to the documentation of this file.
1 /* Copyright 2018 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jason Peng <jason@ufactory.cc>
6  ============================================================================*/
7 #include "ros/ros.h"
8 #include <std_msgs/Bool.h>
9 #include <xarm_planner/pose_plan.h>
10 #include <xarm_planner/joint_plan.h>
11 #include <xarm_planner/exec_plan.h>
12 #include <xarm_msgs/SetInt16.h>
13 #include <stdlib.h>
14 #include <vector>
15 
16 bool request_plan(ros::ServiceClient& client, xarm_planner::joint_plan& srv)
17 {
18  if(client.call(srv))
19  {
20  return srv.response.success;
21  }
22  else
23  {
24  ROS_ERROR("Failed to call service joint_plan");
25  return false;
26  }
27 }
28 
29 bool request_exec(ros::ServiceClient& client, xarm_planner::exec_plan& srv)
30 {
31  if(client.call(srv))
32  {
33  return srv.response.success;
34  }
35  else
36  {
37  ROS_ERROR("Failed to call service exec_plan");
38  return false;
39  }
40 }
41 
42 
43 int main(int argc, char** argv)
44 {
45  std::vector<double> tar_joint1 = {-1.0, -0.75, 0.0, 0.2, 0.0, 0.3, 0.0};
46  std::vector<double> tar_joint2 = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
47  std::vector<double> tar_joint3 = {1.0, -0.75, 0.0, 0.2, 0.0, -0.3, 0.0};
48 
49  ros::init(argc, argv, "xarm_simple_planner_client");
50  ros::NodeHandle nh;
51  ros::ServiceClient client = nh.serviceClient<xarm_planner::joint_plan>("xarm_joint_plan");
52  ros::ServiceClient client_exec = nh.serviceClient<xarm_planner::exec_plan>("xarm_exec_plan");
53  ros::ServiceClient client_stop = nh.serviceClient<xarm_msgs::SetInt16>("xarm/set_state");
54 
55  ros::Publisher exec_pub = nh.advertise<std_msgs::Bool>("xarm_planner_exec", 10);
56  std_msgs::Bool msg;
57  xarm_planner::joint_plan srv;
58  xarm_planner::exec_plan srv_exec;
59  xarm_msgs::SetInt16 srv_stop;
60 
61  ros::service::waitForService("xarm_exec_plan");
62  ros::service::waitForService("xarm/set_state");
63 
64  while(ros::ok())
65  {
66  srv.request.target = tar_joint1;
67  if(request_plan(client, srv))
68  {
69  ROS_INFO("Plan SUCCESS! Executing... ");
70  srv_exec.request.exec = true;
71  if(request_exec(client_exec, srv_exec)==false)
72  {
73  srv_stop.request.data = 4;
74  client_stop.call(srv_stop);
75  ROS_WARN("OOPS! SETTING STOP... ");
76  break;
77  }
78  }
79 
80  // ros::Duration(4.0).sleep(); // Wait for last execution to finish
81 
82  srv.request.target = tar_joint2;
83  if(request_plan(client, srv))
84  {
85  ROS_INFO("Plan SUCCESS! Executing... ");
86  srv_exec.request.exec = true;
87  if(request_exec(client_exec, srv_exec)==false)
88  {
89  srv_stop.request.data = 4;
90  client_stop.call(srv_stop);
91  ROS_WARN("OOPS! SETTING STOP... ");
92  break;
93  }
94  }
95 
96  // ros::Duration(4.0).sleep(); // Wait for last execution to finish
97 
98  srv.request.target = tar_joint3;
99  if(request_plan(client, srv))
100  {
101  ROS_INFO("Plan SUCCESS! Executing... ");
102  srv_exec.request.exec = true;
103  if(request_exec(client_exec, srv_exec)==false)
104  {
105  srv_stop.request.data = 4;
106  client_stop.call(srv_stop);
107  ROS_WARN("OOPS! SETTING STOP... ");
108  break;
109  }
110  }
111 
112  // ros::Duration(4.0).sleep(); // Wait for last execution to finish
113 
114  srv.request.target = tar_joint2;
115  if(request_plan(client, srv))
116  {
117  ROS_INFO("Plan SUCCESS! Executing... ");
118  srv_exec.request.exec = true;
119  if(request_exec(client_exec, srv_exec)==false)
120  {
121  srv_stop.request.data = 4;
122  client_stop.call(srv_stop);
123  ROS_WARN("OOPS! SETTING STOP... ");
124  break;
125  }
126  }
127  }
128 
129  ros::shutdown();
130  return 0;
131 
132 }
133 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
#define ROS_WARN(...)
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
bool request_plan(ros::ServiceClient &client, xarm_planner::joint_plan &srv)
bool request_exec(ros::ServiceClient &client, xarm_planner::exec_plan &srv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


xarm_planner
Author(s):
autogenerated on Sat May 8 2021 02:51:52