dmp_simple_trajectory.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <iri_wam_common_msgs/DMPTrackerAction.h>
00003 #include <actionlib/client/simple_action_client.h>
00004 
00005 typedef actionlib::SimpleActionClient< iri_wam_common_msgs::DMPTrackerAction > TrajClient;
00006 
00007 class RobotArm
00008 {
00009 private:
00010   // Action client for the joint trajectory action 
00011   // used to trigger the arm movement action
00012   TrajClient* traj_client_;
00013     ros::NodeHandle nh;
00014     ros::Publisher pub;
00015 public:
00017   RobotArm() 
00018   {
00019     // tell the action client that we want to spin a thread by default
00020     traj_client_ = new TrajClient("/wam_wrapper/DMPTracker", true);
00021 
00022     //initialize the topic to send new goals
00023     
00024     pub = nh.advertise<trajectory_msgs::JointTrajectoryPoint>("/wam_wrapper/DMPTrackerNewGoal", 1);
00025 
00026     // wait for action server to come up
00027     while(!traj_client_->waitForServer(ros::Duration(5.0))){
00028       ROS_INFO("Waiting for the joint_trajectory_action server");
00029     }
00030   }
00031 
00033   ~RobotArm()
00034   {
00035     delete traj_client_;
00036   }
00037 
00039   void startTrajectory()
00040   {
00041     iri_wam_common_msgs::DMPTrackerGoal DMPgoal;
00042     
00043     DMPgoal.initial.positions.resize(7);   
00044     DMPgoal.initial.positions[0] = -0.11976;
00045     DMPgoal.initial.positions[1] = -1.84794;
00046     DMPgoal.initial.positions[2] = 0.285349;
00047     DMPgoal.initial.positions[3] = 2.84315;
00048     DMPgoal.initial.positions[4] = -0.310117;
00049     DMPgoal.initial.positions[5] = -1.21896;
00050     DMPgoal.initial.positions[6] = 0.0192133;
00051      
00052     DMPgoal.goal.positions.resize(7); 
00053     DMPgoal.goal.positions[0] = 0.160557;
00054     DMPgoal.goal.positions[1] = -1.91039;
00055     DMPgoal.goal.positions[2] = -0.664568;
00056     DMPgoal.goal.positions[3] = 2.9184;
00057     DMPgoal.goal.positions[4] = -0.5448;
00058     DMPgoal.goal.positions[5] = -0.812694;
00059     DMPgoal.goal.positions[6] = -0.471291;
00060      
00061     // When to start the trajectory: 1s from now
00062     //goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(1.0);
00063     traj_client_->sendGoal(DMPgoal);
00064     
00065     for (int i=0;i<10;i++) {
00066       sleep(0.5);
00067       trajectory_msgs::JointTrajectoryPoint DMPnew_goal;
00068       DMPnew_goal.positions.resize(7);   
00069       DMPnew_goal.positions[0] = -0.11976;
00070       DMPnew_goal.positions[1] = -1.84794;
00071       DMPnew_goal.positions[2] = 0.285349-i*0.02;
00072       DMPnew_goal.positions[3] = 2.84315;
00073       DMPnew_goal.positions[4] = -0.310117;
00074       DMPnew_goal.positions[5] = -1.21896;
00075       DMPnew_goal.positions[6] = 0.0192133;
00076       
00077       pub.publish(DMPnew_goal);
00078     }     
00079   }
00080 
00082   actionlib::SimpleClientGoalState getState()
00083   {
00084     return traj_client_->getState();
00085   }
00086  
00087 };
00088 
00089 int main(int argc, char** argv)
00090 {
00091   // Init the ROS node
00092   ros::init(argc, argv, "robot_driver");
00093 
00094   RobotArm arm;
00095   // Start the trajectory
00096   arm.startTrajectory();
00097   // Wait for trajectory completion
00098   while(!arm.getState().isDone() && ros::ok())
00099   {
00100     usleep(50000);
00101   }
00102 }


iri_wam_wrapper
Author(s): Pol Monso
autogenerated on Fri Dec 6 2013 21:47:20