trajectory_gen.cpp
Go to the documentation of this file.
00001 #include <moveit/move_group_interface/move_group.h>
00002 #include <math.h>
00003 #include "aubo_msgs/GoalPoint.h"
00004 #include "aubo_msgs/TraPoint.h"
00005 
00006 using namespace std;
00007 double last_road_point[6];
00008 
00009 std::vector<double> group_variable_values;
00010 moveit::planning_interface::MoveGroup *ptr_group;
00011 
00012 ros::Publisher tra_pub;
00013 aubo_msgs::TraPoint tra_point;
00014 
00015 int goal_trajectory(double *road)
00016 {
00017   int point_num;
00018   /*Planning to a joint-space goal*/ 
00019   group_variable_values[0] = road[0];
00020   group_variable_values[1] = road[1];
00021   group_variable_values[2] = road[2];
00022   group_variable_values[3] = road[3];
00023   group_variable_values[4] = road[4];
00024   group_variable_values[5] = road[5];
00025   ptr_group->setJointValueTarget(group_variable_values);
00026 
00027   moveit::planning_interface::MoveGroup::Plan my_plan;
00028 
00029   bool success = ptr_group->plan(my_plan);
00030 
00031   ROS_INFO("Visualizing plan 1 (joint space goal) %s",success?"":"FAILED");
00032 
00033   ptr_group->execute(my_plan);
00034 
00035   point_num = my_plan.trajectory_.joint_trajectory.points.size();
00036 
00037 
00038   tra_point.num_of_trapoint = point_num;
00039 
00040   tra_point.trapoints.resize(point_num*6);
00041 
00042   for(int j=0; j< point_num; j++)
00043   {
00044      for(int i=0; i<6; i++)
00045      {
00046           tra_point.trapoints[j*6+i] = my_plan.trajectory_.joint_trajectory.points[j].positions[i];
00047      }
00048   }
00049 
00050 
00051   //ptr_group->stop();
00052   ROS_INFO("way_point num:%d",point_num);
00053 
00054   return point_num;
00055 }
00056 
00057 int road_point_compare(double *goal)
00058 { 
00059   int ret = 0;
00060   for(int i=0;i<6;i++)
00061   {
00062     if(fabs(goal[i]-last_road_point[i])>=0.000001)
00063         {
00064        ret = 1;
00065            break;
00066         }    
00067   }
00068 
00069   if(ret == 1)
00070   {
00071     last_road_point[0]= goal[0];
00072     last_road_point[1]= goal[1];
00073     last_road_point[2]= goal[2];
00074     last_road_point[3]= goal[3];
00075     last_road_point[4]= goal[4];
00076     last_road_point[5]= goal[5];
00077   }
00078   
00079 
00080   return ret;
00081 }
00082  
00083 
00084 void chatterCallback(const aubo_msgs::GoalPoint::ConstPtr &msg)
00085 {
00086   double road[6];
00087   int bus;
00088 
00089   bus = msg->bus;
00090 
00091   road[0] = msg->joint1;
00092   road[1] = msg->joint2;
00093   road[2] = msg->joint3;
00094   road[3] = msg->joint4;
00095   road[4] = msg->joint5;
00096   road[5] = msg->joint6;
00097 
00098   if(road_point_compare(road))
00099   {
00100       goal_trajectory(road);
00101       tra_point.bus = bus;
00102       tra_pub.publish(tra_point);
00103   }
00104 }
00105 
00106 
00107 int main(int argc, char **argv)
00108 {
00109   ros::init(argc, argv, "trajectory_gen");
00110   ros::NodeHandle nh; 
00111 
00112   ros::AsyncSpinner spinner(3);
00113   spinner.start();
00114         
00115 
00116   ros::Subscriber sub1 = nh.subscribe("goal_pos", 1000, chatterCallback);
00117   tra_pub = nh.advertise<aubo_msgs::TraPoint> ("tra_point", 1000);
00118   
00119 
00120   last_road_point[0]= 0;
00121   last_road_point[1]= 0;
00122   last_road_point[2]= 0;
00123   last_road_point[3]= 0;
00124   last_road_point[4]= 0;
00125   last_road_point[5]= 0;
00126 
00127   moveit::planning_interface::MoveGroup group("arm_group");
00128   ptr_group = &group;
00129   ptr_group->getCurrentState()->copyJointGroupPositions(ptr_group->getCurrentState()->getRobotModel()->getJointModelGroup(ptr_group->getName()), group_variable_values);
00130   
00131 
00132   ROS_INFO("Reference frame: %s", group.getPlanningFrame().c_str());
00133   ROS_INFO("Reference frame: %s", group.getEndEffectorLink().c_str());
00134 
00135   ros::waitForShutdown(); 
00136   return 0;
00137 
00138 }


aubo_trajectory
Author(s): liuxin
autogenerated on Wed Sep 6 2017 03:06:56