prepare_shutdown_node.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <trajectory_msgs/JointTrajectory.h>
6 #include <std_srvs/Trigger.h>
7 
8 
11 
12 
13 bool prepareShutdownCB(std_srvs::Trigger::Request &req,
14  std_srvs::Trigger::Response &res)
15 {
16  /* lower head */
17  std::vector<double> head_goal(2);
18  head_goal[0] = 0;
19  head_goal[1] = 0.7;
20  trajectory_msgs::JointTrajectory traj;
21  traj.header.stamp = ros::Time::now();
22  traj.joint_names.push_back("head_pan_joint");
23  traj.joint_names.push_back("head_tilt_joint");
24  traj.points.resize(1);
25  traj.points[0].time_from_start = ros::Duration(1.0);
26  std::vector<double> q_goal(2);
27  q_goal[0]=head_goal[0];
28  q_goal[1]=head_goal[1];
29  traj.points[0].positions=q_goal;
30  traj.points[0].velocities.push_back(0.1);
31  traj.points[0].velocities.push_back(0.1);
32  traj_pub.publish(traj);
33 
34  /* move arm to driving mode */
36  group.setPlanningTime(10.0);
37  group.setNumPlanningAttempts(50);
38  group.setPlannerId("RRTConnectkConfigDefault");
39  group.setPoseReferenceFrame("base_footprint");
41  group.setNamedTarget("driving");
43  if(group.plan(startPosPlan))
44  {
45  group.execute(startPosPlan);
46  res.message = "shutdown preparation finished";
47  res.success = true;
48  }
49  else
50  {
51  res.message = "move arm to driving mode failed (planning failed)";
52  res.success = false;
53  }
54  return true;
55 }
56 
57 
58 int main(int argc, char** argv) {
59 
60  ros::init(argc, argv, "prepare_shutdown_node");
61  ros::NodeHandle nh;
62  traj_pub = nh.advertise<trajectory_msgs::JointTrajectory>("/pan_tilt_trajectory_controller/command", 5);
63  shutdown_srv = nh.advertiseService("prepare_shutdown", prepareShutdownCB);
64 
65 
66  /* wait for subscribers and publishers to come up */
67  ros::Rate loop_rate(1);
68  while (traj_pub.getNumSubscribers() <= 0)
69  {
70  ros::spinOnce();
71  loop_rate.sleep();
72  }
73 
74  ROS_INFO("[prepare_shutdown_node]: ready");
75 
76  ros::spin();
77  return 0;
78 }
79 
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setPoseReferenceFrame(const std::string &pose_reference_frame)
void setPlannerId(const std::string &planner_id)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ROSCPP_DECL void spin(Spinner &spinner)
group
ros::ServiceServer shutdown_srv
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
MoveItErrorCode execute(const Plan &plan)
bool sleep()
void setNumPlanningAttempts(unsigned int num_planning_attempts)
int main(int argc, char **argv)
bool prepareShutdownCB(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
uint32_t getNumSubscribers() const
static Time now()
ROSCPP_DECL void spinOnce()
bool setNamedTarget(const std::string &name)
ros::Publisher traj_pub


prepare_shutdown
Author(s):
autogenerated on Wed Jan 3 2018 03:48:19